The dimension of tensor (axis) - the explanation of axis

Tensors, or tensors, can be seen as a natural generalization of vectors and matrices, and we use tensors to represent a wide range of data types.

The order of a tensor is sometimes called a dimension, or axis, and the word axis is translated from the English axis.

For example, a matrix [[1,2],[3,4]] is a 2-order tensor with two dimensions or axes.

What you see along the 0th axis is [1,2], [3,4] two vectors, which are equivalent to a 2x2 matrix in mathematics, taken out by row, each row as a vector;

What you see along the first axis is [1,3], [2,4] two vectors, equivalent to a 2x2 matrix in mathematics, taken out by columns, each column as a vector;

import numpy as np  
  
a = np.array([[1,2],[3,4]])  
s0 = np.sum(a, axis=0) #ie [1,2], [3,4] addition  
s1 = np.sum(a, axis=1) #ie [1,3], [2,4] addition  
  
print(s0)  
print(s1)

The result is displayed as:

>>> [4, 6]
>>> [3, 7]



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325648713&siteId=291194637