【问题标题】:Why does my variable show up as NoneType in Variable Explorer shows up as matrix in command window [duplicate]为什么我的变量在变量资源管理器中显示为 NoneType 在命令窗口中显示为矩阵 [重复]
【发布时间】:2021-11-24 07:08:29
【问题描述】:

所以我正在使用一个数据集,我需要获取每列中的采样频率,这是我正在使用的函数

def downsample_happysongs():
    n = 8 # number of channels  
    sample_freq = 128  # sample frequency used in dataset
    data1 = data[1]['sect3']
    for col in data1.T:
        resample = mne.filter.filter_data(col, sample_freq, 0, 45, verbose=False)
        print(resample)
    


x = downsample_happysongs()



当我调用 x 时,这是我在命令窗口中得到的:

[-111.53109882 -111.59736915 -111.60413325 ...  -84.77988125  -84.68113443
  -84.55278019]
[230.5291432  230.43227696 230.24191778 ... 218.66069654 218.5746243
 218.92582851]
[149.62316188 148.62975455 147.69649625 ... 174.86999009 176.0134802
 176.86924547]
[177.41376749 176.89590573 176.57376289 ... 190.36114417 190.79033535
 191.16269878]
[389.38819789 387.82521721 383.90228579 ... 403.54903327 405.7398386
 409.00497842]
[59.11960524 59.19479442 59.41908772 ... 75.69543276 75.28374616
 74.97868426]
[558.44580036 555.27798436 553.22270828 ... 560.03316664 561.74143485
 562.49424666]
[1646.21346585 1642.88844551 1636.81714726 ... 1528.20584784 1531.18983756
 1537.56433726]

我的原始数据是一个 1500x8 矩阵,我需要获取每列的采样频率,然后取 8 列并重新创建一个重新采样的矩阵。 当我在 Spyder 中检查变量资源管理器时,'x' 显示为 NoneType。不知道我的大脑是否因为看这个太久而融化了,但我不知道如何解决它。另外我转置了我的数据,因为它是一个 1500x8 矩阵,我不知道如何迭代列,所以这就是我处理数据的方式,如果有人对此有建议,那么我会接受,但我计划再次转置。

提前致谢!

【问题讨论】:

  • 你的函数没有返回任何东西,所以它隐式返回None。这就是你绑定的名字x

标签: python data-processing mne-python


【解决方案1】:

您需要先将数据(重新采样)存储到一个列表中,然后返回该列表

def downsample_happysongs():
    n = 8 # number of channels  
    sample_freq = 128  # sample frequency used in dataset
    data1 = data[1]['sect3']
    ALL_RESAMPLE = []
    for col in data1.T:
        resample = mne.filter.filter_data(col, sample_freq, 0, 45, verbose=False)
        ALL_RESAMPLE.append(resample)
        print(resample)
    return ALL_RESAMPLE
    


x = downsample_happysongs()

【讨论】:

  • 谢谢,我还是 python 新手,但这有效!
  • 没有问题。你介意接受我的回答吗?
猜你喜欢
  • 2013-10-06
  • 2019-11-19
  • 2021-07-15
  • 1970-01-01
  • 1970-01-01
  • 2013-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多