微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

试图纠正异常值,但它说我正在从明显不推荐使用的参差不齐的嵌套序列创建一个 nd 数组

如何解决试图纠正异常值,但它说我正在从明显不推荐使用的参差不齐的嵌套序列创建一个 nd 数组

我正在尝试预处理我的数据,我决定做的一件事是纠正数据中的异常值。所以基本上超过±mult_std的样本值,其中mult_std是任何给定电压轨迹的标准偏差,被设置为±mult_std以纠正电压异常值。

唯一的问题是当我运行这段代码

    # Rectifying Outliers
    for epoch in epoched:
        epoch_mean = np.mean(epoch)
        epoch_std = np.std(epoch)
        a.append(epoch_std)
        epoched_corrected.append(np.array([i - epoch_std * mult_std if i > epoch_mean + epoch_std * mult_std 
                            else i + epoch_std * mult_std if i < epoch_mean - epoch_std * mult_std 
                            else i for i in epoch]))

    corrected_epoched_eeg_data.append(epoched_corrected)

我收到此错误

(BCI_env) (base) mikaelhaji@Mikaels-MacBook-Pro mi % /Users/mikaelhaji/Environments/BCI_env/bin/python /Users/mikaelhaji/Desktop/mi/Preprocessing_MotorImagery.py
/Users/mikaelhaji/Desktop/mi/Preprocessing_MotorImagery.py:76: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this,you must specify 'dtype=object' when creating the ndarray.
  epoched = np.array(array_epochs)
Traceback (most recent call last):
  File "/Users/mikaelhaji/Desktop/mi/Preprocessing_MotorImagery.py",line 85,in <module>
    epoched_corrected.append(np.array([i - epoch_std * mult_std if i > epoch_mean + epoch_std * mult_std 
  File "/Users/mikaelhaji/Desktop/mi/Preprocessing_MotorImagery.py",in <listcomp>
    epoched_corrected.append(np.array([i - epoch_std * mult_std if i > epoch_mean + epoch_std * mult_std 
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

关于我如何可能简化这个或为什么我会收到这个错误的任何想法。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。