【发布时间】:2015-09-23 15:27:41
【问题描述】:
我正在尝试从具有以下条目的文本文件构建矩阵:
45.0 0.00173 -0.0227 ...
45.07 0.00173 -0.00227 ...
.
.
.
到目前为止,我已经阅读了文件行:
with open(os.path.join(dirs,fil),"r") as deck:
deck_lines=deck.readlines()
并使用以下方法获得了我所需的行:
freq_chan = deck_lines[6+int(no_nodes):len(deck_lines)]
并将值放入矩阵中:
freq_chan = np.matrix([i.split() for i in freq_chan]).astype(np.float)
但是当我尝试从矩阵中提取列时,似乎每个元素都被读取为一个矩阵:
values = freq_chan[:,0]
print(values)
产生:
[[45.0]
[45.07]
.
.
.]]
但我想要的是 [45.0, 45.07, ...]
有没有办法解包元素,也许使用 for 循环。
【问题讨论】:
-
np.matrix上的大多数操作都会返回另一个矩阵,它也是 2d。为什么不使用np.array?