简体   繁体   English

消除轴

[英]Axis elimination

I'm having a trouble understanding the concept of Axis elimination in numpy. 我在理解numpy中轴消除的概念时遇到了麻烦。 Suppose I have the following 2D matrix: 假设我有以下2D矩阵:

A = 

1 2 3

3 4 5

6 7 8

Ok I understand that sum(A, axis=0) will sum each column down and will give a 1D array with 3 elements. 好的,我知道sum(A,axis = 0)会将每一列求和,并给出一个包含3个元素的1D数组。 I also understand that sum(A, axis=1) will sum each row. 我也明白sum(A,axis = 1)将对每一行求和。

But my trouble is when I read that axis=0 eliminates the 0th axis and axis=1 eliminates the 1th axis. 但是我的麻烦是当我读到axis = 0消除了第0根轴,而axis = 1消除了第1根轴。 Also sometime people mention "reduce" instead of "eliminate". 有时也有人提到“减少”而不是“消除”。 I'm unable to understand what does that eliminate. 我不明白这消除了什么。 For example sum(A, axis=0) will sum each column from top to bottom, but I don't see elimination or reduction here. 例如sum(A,axis = 0)将从上到下对每一列求和,但是在这里我看不到消除或减少。 What's the point? 重点是什么? The same also for sum(A,axis=1). sum(A,axis = 1)也相同。

AND how is it for higher dimensions? 以及对于更高的尺寸如何?

ps I always confused between matrix dimensions and array dimensions. ps我总是在矩阵尺寸和数组尺寸之间感到困惑。 I wished that people who write the numpy documentation makes this distinction very clear. 我希望编写numpy文档的人能够清楚区分这一区别。

http://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.reduce.html http://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.reduce.html

Reduces a's dimension by one, by applying ufunc along one axis. 通过沿一个轴应用ufunc将a的尺寸减小一倍。

For example, add.reduce() is equivalent to sum(). 例如,add.reduce()等同于sum()。

In numpy , the base class is ndarray - a multidimensional array (can 0d, 1d, or more) numpy ,基类是ndarray多维数组(可以为0d,1d或更多)

http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html

Matrix is a subclass of array http://docs.scipy.org/doc/numpy/reference/arrays.classes.html Matrix是数组http://docs.scipy.org/doc/numpy/reference/arrays.classes.html的子类

Matrix objects are always two-dimensional 矩阵对象始终是二维的

The history of the numpy Matrix is old, but basically it's meant to resemble the MATLAB matrix object. numpy Matrix的历史很久,但是基本上是要类似于MATLAB矩阵对象。 In the original MATLAB nearly everything was a matrix, which was always 2d. 在原始的MATLAB中,几乎所有东西都是矩阵,总是2d。 Later they generalized it to allow more dimensions. 后来他们将其推广,以允许更大的尺寸。 But it can't have fewer dimensions. 但是它不能有更少的尺寸。 MATLAB does have 'vectors', but they are just matrices with one dimension being 1 (row vector versus column vector). MATLAB确实具有“向量”,但是它们只是一维为1 (行向量与列向量)的矩阵。

'axis elimination' is not a common term when working with numpy . 使用numpy时,“轴消除”不是一个常用术语。 It could, conceivably, refer to any of several ways that reduce the number of dimensions of an array. 可以想象,它可以引用减少数组维数的几种方法中的任何一种。 Reduction, as in sum() , is one. sum() ,约简是一个。 Indexing is another: a[:,0,:] . 索引是另一个: a[:,0,:] Reshaping can also change the number of dimensions. 重塑形状也可以更改尺寸数量。 np.squeeze is another. np.squeeze是另一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM