鉴于这个 CSV 文件:
"A","B","C","D","E","F","timestamp"
611.88243,9089.5601,5133.0,864.07514,1715.37476,765.22777,1.291111964948E12
611.88243,9089.5601,5133.0,864.07514,1715.37476,765.22777,1.291113113366E12
611.88243,9089.5601,5133.0,864.07514,1715.37476,765.22777,1.291120650486E12
我只是想把它加载为一个矩阵/ndarray,它有3行7列。但是,由于某种原因,我能得到的只是一个 ndarray,它有3行(每行一行) ,没有列。
r = np.genfromtxt(fname,delimiter=',',dtype=None, names=True)
print r
print r.shape
[ (611.88243, 9089.5601000000006, 5133.0, 864.07514000000003, 1715.3747599999999, 765.22776999999996, 1291111964948.0)
(611.88243, 9089.5601000000006, 5133.0, 864.07514000000003, 1715.3747599999999, 765.22776999999996, 1291113113366.0)
(611.88243, 9089.5601000000006, 5133.0, 864.07514000000003, 1715.3747599999999, 765.22776999999996, 1291120650486.0)]
(3,)
我可以手动迭代并把它修改成我想要的形状,但这看起来很傻。我只是想加载它作为一个合适的矩阵,这样我就可以把它切割成不同的维度,然后绘制出来,就像在 matlab 中一样。