Numpy的“增”操作
import numpy as np
arr1 = np.array([1,2,3,4])
arr1
array([1, 2, 3, 4])
arr2 = np.array([[1,2,3,4],[4,5,6,7],[7,8,9,10]])
arr2
array([[ 1, 2, 3, 4],
[ 4, 5, 6, 7],
[ 7, 8, 9, 10]])
np. linspace(0,1,12)
array([0. , 0.09090909, 0.18181818, 0.27272727, 0.36363636,
0.45454545, 0.54545455, 0.63636364, 0.72727273, 0.81818182,
0.90909091, 1. ])
np. logspace(0,2,20)
array([ 1. , 1.27427499, 1.62377674, 2.06913808,
2.6366509 , 3.35981829, 4.2813324 , 5.45559478,
6.95192796, 8.8586679 , 11.28837892, 14.38449888,
18.32980711, 23.35721469, 29.76351442, 37.92690191,
48.32930239, 61.58482111, 78.47599704, 100. ])
np. zeros((2,3))
array([[0., 0., 0.],
[0., 0., 0.]])
np. eye(3)
array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
np. diag([1,2,3,4])
array([[1, 0, 0, 0],
[0, 2, 0, 0],
[0, 0, 3, 0],
[0, 0, 0, 4]])
np. eye(4)
array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]])
numpy的“查”操作
arr2.shape
(3, 4)
arr2.ndim
2
print(arr2.size)
print(arr2.dtype)
print(arr2.itemsize)
12
int32
4
np.float64(56