The first job - numpy practice

[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.]

import numpy as e.g. 
z = np.ones ((10,10)) 
with 
the [1: 1,1: -1] = 0 
with

  

 

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 for example 
with np.diag = (1 + np.arange (4), k = 0) 
print (z)

 

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 e.g. 
z = np.random.random ((5,5)) 
z_min, z_max = z.min () z.max () 
z = (z-z_min) / (z_max-z_min) 
print (z)

  

Guess you like

Origin www.cnblogs.com/chanw/p/11577552.html