我正在使用荆棘和耳蜗来产生spiketrain。结果是表单中的pandas.DataFrame形式,列“spike'包含我需要的尖峰时间数组。
当我尝试用
提取它时a = df.as_matrix(['spikes'])
结果矩阵将始终如下所示:
a = [[array([1,2,3])][array([4,5,6])]]
要进一步使用数据,我需要表格:
a= [[1,2,3][4,5,6]]
如何删除array()部分?
这是我使用的代码:
import cochlea
import thorns.waves as wv
#generating the spiketrain
sound = wv.ramped_tone(fs=100e3,freq=500,duration=0.3,dbspl=60)
spiketrain=cochlea.run_zilany2014(sound,fs=100e3,anf_num=(2,0,0),cf=500,seed=0,species='human')
print spiketrain
#trying to extrakt spiketime information
a = spiketrain.as_matrix(['spikes'])
print 'a='
print a
答案 0 :(得分:0)
这是一种方式:
import pandas as pd, numpy as np
df = pd.DataFrame({'A': [np.array([1,2,3]), np.array([4,5,6]), np.array([7,8,9])]})
res = np.array(df['A'].values.tolist())
# array([[1, 2, 3],
# [4, 5, 6],
# [7, 8, 9]])
res2 = list(map(list, df['A']))
# [[1, 2, 3],
# [4, 5, 6],
# [7, 8, 9]]