访问numpy.ndarray的列和行 [英] Access columns and rows of numpy.ndarray
本文介绍了访问numpy.ndarray的列和行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在努力从存储为numpy.ndarray的矩阵中提取某些列和行.
I currently struggling with extracting certain columns and rows from a matrix stored as a numpy.ndarray.
我有一个列表,其中附加了这些numpy.ndarrays.
I have a list in which I've appended these numpy.ndarrays.
此列表存储在名为data
print data[0].shape
输出此
(400, 288)
根据文档,我已经理解该矩阵具有400行和288列.
Which I've according to the documentation have understood being the matrix has 400 rows, and 288 columns.
如何分别提取所有288?
How do I extract all the 288 seperately?
示例:
>> import numpy as np
>> data = np.random.rand(3,3)
>> print data
[[ 0.97522481 0.57583658 0.68582806]
[ 0.88509883 0.22261933 0.84307038]
[ 0.59397925 0.51592125 0.54346909]]
我如何单独打印此3x3矩阵的列,首先是
How do I print the columns separately of this 3x3 matrix, first being
[0.97522481 , 0.88509883, 0.59397925 ]
不输出其他内容?
推荐答案
是您要找的东西吗?
import numpy as np
arr = np.array([[1, 2],
[3, 4],
[5, 6]])
print(arr.shape)
# (3, 2)
print(list(data.T))
# [array([1, 3, 5]), array([2, 4, 6])]
这篇关于访问numpy.ndarray的列和行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文