import numpy as np
>>> np.ones((2,3))
array([[1., 1., 1.],
[1., 1., 1.]])
>>> np.ones(6)
array([1., 1., 1., 1., 1., 1.])
>>> np.zeros((2,3))
array([[0., 0., 0.],
[0., 0., 0.]])
>>> np.zeros(6)
array([0., 0., 0., 0., 0., 0.])
>>> list_c = [[1, 2], [3, 4]]
>>> c = np.array(list_c)
>>> c.sum(axis = 0)
array([4, 6])
>>> np.arange(10,30,5)
array([10, 15, 20, 25])
>>> np.linspace(1,10,10)
array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])
>>> np.ones(12).reshape(3,4)
array([[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]])
>>> A = np.array([[1, 1],[0, 1]])
>>> B = np.array([[2, 0],[3, 4]])
>>> print(A*B)
[[2 0]
[0 4]]
>>> print(A@B)
[[5 4]
[3 4]]
>>> print(A.dot(B))
[[5 4]
[3 4]]
>>> b = np.arange(12).reshape(3, 4)
>>> b
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
>>> b.sum(axis=0)
array([12, 15, 18, 21])
>>> b.min(axis=1)
array([0, 4, 8])
>>> b.cumsum(axis=1)
array([[ 0, 1, 3, 6],
[ 4, 9, 15, 22],
[ 8, 17, 27, 38]], dtype=int32)
>>> a = np.arange(10)**3
>>> a
array([ 0, 1, 8, 27, 64, 125, 216, 343, 512, 729], dtype=int32)
>>> a[2:5]
array([ 8, 27, 64], dtype=int32)
>>> a[:6:2] = 1000
>>> a
array([1000, 1, 1000, 27, 1000, 125, 216, 343, 512, 729],
dtype=int32)
>>> a[::-1]
array([ 729, 512, 343, 216, 125, 1000, 27, 1000, 1, 1000],
dtype=int32)
转发:Python之NumPy(axis=0 与axis=1)区分