解包 numpy 矩阵的元素

Unpacking elements of a numpy matrix

我正在尝试从包含以下条目的文本文件构建矩阵:

  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.loadtxt()