【发布时间】:2011-03-26 12:24:51
【问题描述】:
我需要获取一个 csv 文件并将此数据导入到 python 中的多维数组中,但我不确定在将数据附加到空数组后如何从数组中删除“无”值.
我首先创建了一个这样的结构:
storecoeffs = numpy.empty((5,11), dtype='object')
这将返回一个由“无”填充的 5 行 x 11 列数组。
接下来,我打开了我的 csv 文件并将其转换为一个数组:
coeffsarray = list(csv.reader(open("file.csv")))
coeffsarray = numpy.array(coeffsarray, dtype='object')
然后,我附加了两个数组:
newmatrix = numpy.append(storecoeffs, coeffsarray, axis=1)
结果是一个由“无”值填充的数组,后跟我想要的数据(显示前两行是为了让您了解我的数据的性质):
array([[None, None, None, None, None, None, None, None, None, None, None,
workers, constant, hhsize, inc1, inc2, inc3, inc4, age1, age2,
age3, age4],[None, None, None, None, None, None, None, None, None, None, None,
w0, 7.334, -1.406, 2.823, 2.025, 0.5145, 0, -4.936, -5.054, -2.8, 0],,...]], dtype=object)
如何从每一行中删除那些“无”对象,这样我剩下的就是包含我的数据的 5 x11 多维数组?
【问题讨论】:
标签: python multidimensional-array numpy extract slice