有人可以解释numpy如何显示多维数组吗

有人可以解释numpy如何显示多维数组吗

本文介绍了有人可以解释numpy如何显示多维数组吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下命令:

np.ones((2,2,3))

我得到以下内容

array([[[1., 1., 1.],
        [1., 1., 1.]],

       [[1., 1., 1.],
        [1., 1., 1.]]])

据我所了解的阅读docos/blogs等,这是一个多维数组,实际上是3个2x2矩阵的组合,因此我们有2列2行,深度"维为3,表示numpy使用(行, 3维数组的列,深度)系统.

From what I understand reading docos/blogs etc this is a multi-dimensional array that is effectively a combination of 3, 2x2 matrices so we have 2 columns 2 rows and "depth" dimension of 3 meaning numpy uses a (row,column,depth) system for 3 dimensional arrays.

那我应该如何解释终端中显示的内容,这似乎是2个3x2矩阵,表示一个(深度,行,列)系统.

How then should I interpret what is displayed in the terminal which appears to be 2 3x2 matrices implying a (depth,row,column) system.

推荐答案

与Matlab(主要是专栏)不同,NumPy使用行主要索引:分组从最左侧的索引开始.因此,ones((2, 3, 4))由两个为ones((3, 4))的数组组成,而每个数组均由三个为ones((4,))的数组组成.

Unlike Matlab (which is column-major) NumPy uses row-major indexing: grouping starts from the leftmost index. So, ones((2, 3, 4)) consists of two arrays that are ones((3, 4)), and each of those consists of three arrays that are ones((4,)).

左-到-右是外-到-内.同样,它是索引-到索引的快速更改(如果顺序读取所有元素).

Left - to - right is outer - to - inner. Also, it is slowly-changing index - to - quickly-changing index (if one reads all the elements sequentially).

>>> np.ones((2, 3, 4))
array([[[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]],

       [[ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.]]])

对于2D数组,它是行列.对于3D,它是纵行列,等等:对于4D,它是某种行列.

For a 2D array it's row-column. For 3D it is depth-row-column, etc: for 4D it's something-something-row-column.

这篇关于有人可以解释numpy如何显示多维数组吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 13:48