Home > other >  Numpy base data types and generate a random number of notes
Numpy base data types and generate a random number of notes

Time:11-20

 
# In [4] :


The import numpy as np
Arr2=np. Array ([[1, 2, 3, 4], [5,6,7,8]])
Print (arr2)


# In [5] :


Print (' dimensions of array are as follows: 'arr2. Shape)


# In [6] :


Print (' array type is: ', arr2 dtype)


# In [7] :


Print (' the number of elements in the array is: 'arr2. Size)


# In [8] :


Print (' for each element of the array size: 'arr2. Itemsize)


# In [10] :


Arr2. Shape=4, 2 # reset shape
Print (arr2)


# In [12] :


Print (np) arange,1,0.1) (0) # from 0 to 1, the step length is 0.1, the results contain 0 contains no 1


# In [13] :


Print (np) linspace,1,12) (0) # 0 and 1 is divided into 11 parts of the node number 12, create arithmetic progression, the results contain 0 and 1


# In [14] :


,2,20 print (np. Logspace (0)) of 0 # generate 10 square 2 to the power of (0) to 10 (100) of 20 elements of geometric sequence, the results contain 0 and 100


# In [20] :


Print (np) zeros ((2, 3)))


# In [22] :


Print (np) eye (4, 4))


# In [23] :


Print (np) diag ([1, 2, 3, 4]))


# In [25] :


Print (np) ones ((2, 3)))


# In [26] :


Print (np. Float64 (42))
Print (np. Int8 (42))
Print (np) bool (0))
Print (np. Float (True))


# In [32] :


Df=np dtype ([(" name ", np str_, 40), (" numitems ", np. Int64), (" price ", np. Float64)])
Print (df)
Print (df/" name ")


# In [35] :


Itemz=np. Array ([(" comedy ", 42,4.14), (" cabbages, "13,1.72)], dtype=df)
Print (itemz)


# In [36] :


Print (np) random) random (100)) # generates random number of uniform distribution on


# In [37] :


Print (np) random) randn (10, 5)) # is generated to make the distribution of the random number


# In [38] :


Print (np) random) randint (0, 10, size=(2, 4))) # generated random number and a given upper and lower limits set size


Learned to post


CodePudding user response:

Learned to comments

CodePudding user response:

Learn to reply the
  • Related