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 x=np.ones((10,10)) x[1:9,1:9]=0 print(x)
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 x = np.arange(1, 5) print(np.diag(x))
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 intermediate
import numpy as np X = np.random.random((5, 5)) Xmax, Xmin = X.max(), X.min() X = (X - Xmin)/(Xmax - Xmin) print(X)