The first job -Numpy practice

1. Create a value of 1 and the inner boundary of the array is 0, the following legend:
[Note:] solving this problem can first of all values are set to 1, this is a big square; Next, the setting of all boundaries except small square 0.
The title uses a slice of numpy principle. X multidimensional arrays follow the same principle [start: step: stop] is.
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]
[1. 0.0 0. 0. 0. 0. 0. 0. 1.]
[1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]
[1. 0. 0. 0. 0. 0 0. 0. 0. 1.]
[1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]
[1. 0. 0. 0. 0. 0. 0. 0. 0 1.]
[1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]
[1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]
[1 1. 1. 1. 1. 1. 1. 1. 1. 1.]

import numpy as np
a=np.ones((10,10))
a[1:-1,1:-1] = 0
print(a)

  

2. Create a value on the main diagonal array 1,2,3,4 5x5 matrix, the following legend:

[1000]
[0200]
[0030]
[0004 ]

import numpy as np
b=np.diag(1+np.arange(4), k=0) 
print(b)

  

3. The operation of the normalization array
generating a random 5 * 5 matrix, to find the maximum and minimum values, and the maximum and minimum values 1 and 0, respectively, said other values between 0 and 1 in the middle.

import numpy as np
C = np.random.random((5,5))
Cmax, Cmin = C.max(), C.min()
C = (C - Cmin)/(Cmax - Cmin)
print(C)

  

Guess you like

Origin www.cnblogs.com/Chenjim/p/11569546.html