In python, "np" generally refers to the "numpy" library, which is an alias for the third-party library "numpy". Method: Use the command "import numpy as np" to alias the numpy library as "np".
Demo:
import numpy as np
arr = np.array([1,2,3])print(arr)
The result is:
[123]
Knowledge point expansion:
Basic use of NumPy in Python
ndarray (hereinafter referred to as array) is a numpy array object. It should be noted that it is isomorphic, which means that all elements must be of the same type. Each of these arrays has a shape and dtype.
shape is the shape of the array, such as
import numpy as np
from numpy.random import randn
arr =randn(12).reshape(3,4)
arr
[[0.986552351.20830283-0.721351830.40292924][-0.05059849-0.02714873-0.627754860.83222997][-0.84826071-0.29484606-0.769849020.09025059]]
arr.shape(3,4)
(3, 4) means that arr is an array with 3 rows and 4 columns, where dtype is float64
The following function can be used to create an array
array | Convert the input data to ndarray, the type can be specified or defaulted |
---|---|
asarray | Convert input to ndarray |
arange | Similar to built-in range |
ones, ones_like | Create an array of all 1s according to the shape, the latter can copy the shape of other arrays |
zeros, zeros_like | similar to the above, all 0s |
empty, empty_like | Create a new array, only allocate space |
eye, identity | Create a diagonal matrix with a diagonal of 1 |
So far, this article about what np does in python is introduced here. For more information about what np in python is, please search for ZaLou.Cn's previous articles or continue to browse related articles below. Hope you will support more in the future ZaLou.Cn!
Recommended Posts