1. Create a value of 1 and the inner boundary of the array is 0, the following legend:
[Note:] solving this problem can put all the values are set to 1, this is a big square; secondly, the boundary except small squares are all set to 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.]
1 import numpy as np 2 a=np.ones((10,10)) 3 a[1:-1,1:-1]=0 4 print(a)
2. Create a value on the main diagonal array 1,2,3,4 5x5 matrix, the following legend:
[1000]
[0200]
[0030]
[0004 ]
1 import numpy as for example 2 a = np.arange (1.5 ) 3 z = np.diag (a) four print (z)
2. Create a value on the main diagonal array 1,2,3,4 5x5 matrix, the following legend:
[1000]
[0200]
[0030]
[0004 ]
1 import numpy as example 2 with np.random.random = ((10,10 )) 3 zmax, zmin = z.max () z.min () 4 z = (z-Zmin) / (zmax- m and n) 5 print (z)