how to input a string character into a numpy zeros imatrix n python

Solutions on MaxInterview for how to input a string character into a numpy zeros imatrix n python by the best coders in the world

showing results for - "how to input a string character into a numpy zeros imatrix n python"
Paula
27 Mar 2020
1a = np.zeros((3,3),int)
2a[[0,1,2],[2,0,1]] = [1,2,3]
3a
4array([[0, 0, 1],
5       [2, 0, 0],
6       [0, 3, 0]])
7
8A = a.astype(str)
9A
10array([['0', '0', '1'],
11       ['2', '0', '0'],
12       ['0', '3', '0']],
13      dtype='<U11')
14
15A[[0,1,2],[0,1,2]] = 'X'
16A 
17array([['X', '0', '1'],
18       ['2', 'X', '0'],
19       ['0', '3', 'X']],
20      dtype='<U11')
21
Lilli
31 Nov 2017
1a = np.zeros((3,3))
2a 
3array([[ 0.,  0.,  0.],
4       [ 0.,  0.,  0.],
5       [ 0.,  0.,  0.]])
6
7a = np.zeros((3,3),int)
8a
9array([[0, 0, 0],
10       [0, 0, 0],
11       [0, 0, 0]])
12
13a = np.zeros((3,3),bool)
14a
15array([[False, False, False],
16       [False, False, False],
17       [False, False, False]], dtype=bool)
18
19a = np.zeros((3,3),str)
20a 
21array([['', '', ''],
22       ['', '', ''],
23       ['', '', '']],
24      dtype='<U1')
25