Create a two-dimensional array numpy

(A) directly create

d=np.array([[10,11,12],[20,21,22],[30,31,32]])

(B) to create an array of tuples incrementing

d=np.arange(20).reshape(5,4)

(C) to create incremental array specified range

d=np.arange(10,20).reshape(5,2)

(D) create an array of random integer elements

d = np.random.randint (10,99, size = (4,3)) 4 rows and three columns, each element 10 from a random number between (99-1) -

(E) create a whole array 0

d=np.zeros((4,3))

(Vi) create all-0 array based on the existing array of structures

d1 existing array 
D = np.zeros_like (d1)

          

(Vii) create a whole array of 1

np.ones = D ((4,3- )) 
or 
D = np.ones_like (D1)

(Viii) create an array of the same element

d=np.ones((4,3))*20

 (Ix) Other

d = np.linspace (10,20,20) .reshape (4,5) from 10 to 20, 20 to generate an average distribution of sets of data, to generate an array of 4 rows and 5 columns

Guess you like

Origin www.cnblogs.com/jm7612/p/12502833.html