import numpy as np
print("Create an array of 10 zeros")
print(np.zeros(10))
print("Create an array of 10 ones")
print(np.ones(10))
print("Create an array of 10 fives")
print(np.ones(10)*5)
print(np.zeros(10) + 5)
print("Create an array of the integers from 10 to 50")
print(np.arange(10,51))
print("Create an array of all the even integers from 10 to 50")
arr = np.arange(10,51)
print(arr[arr % 2 == 0])
print(np.arange(10,51,2))
print("Create a 3x3 matrix with values ranging from 0 to 8")
print(np.arange(9).reshape(3,3))
print("Create a 3x3 identity matrix")
print(np.eye(3))
print("Use NumPy to generate a random number between 0 and 1")
print(np.random.rand(1))
print("Use NumPy to generate an array of 25 random numbers sampled from a standard normal distribution")
print(np.random.randn(25))
print("Create an array of 20 linearly spaced points between 0 and 1")
print(np.linspace(0,1,20))
print("Create a 2-d array 5 x 5")
print(np.arange(1,26).reshape(5,5))
print("Get the sum of all the values")
print(np.sum(np.arange(1,26)))
print("Get the standard deviation of the values")
print(np.std(np.arange(1,26)))
print("Get the sum of all the columns")
arr = np.arange(1,26).reshape(5,5)
print(arr.sum(axis=0))
结果如下:
如果觉得不错,就点赞或者关注或者留言~~
谢谢~ ~