Numpy: A detailed explanation of some usage methods in Numpy - Jason niu

Introduction to Common Concepts

numpy:


Introduction to common methods

np.expand_dims usage: It is to add the data to the axis of the axis, and the data is at the 0 position of the axis of the axis. 
For example, the original one-dimensional 2 data, axis=0, then the shape becomes (1,2), axis=1, the shape becomes (2,1), and for example, the original is (2,3), axis=0 , then shape becomes (1,2,3), axis=1 then shape becomes (2,1,3). Refer to the usage of the blog python numpy.expand_dims

>>> x.shape

(2, 2)

>>> np.expand_dims(x,axis=0).shape

(1, 2, 2)

>>> np.expand_dims(x,axis=-1).shape

(2, 2, 1)

np.argmax(a) #Find the subscript of the maximum value in the array a, and get the subscript of the first maximum value when there are multiple maximum values 

np.squeeze() #Remove single-dimensional entries from the shape of the array, that is, remove the dimension of 1 in the shape

shape() # The function is a function in numpy.core.fromnumeric. Its function is to read the length of the matrix. For example, shape[0] is to read the length of the first dimension of the matrix. Its input parameter can be an integer representing the dimension, or it can be a matrix.

 d = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], dtype=np.float) #Force a float type array of

np.ceil(a) np.floor(a) #Calculate the ceiling value and floor value of each element (ceiling is rounded up, floor is rounded down)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326688158&siteId=291194637