which numpy module for string arrays code example

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

a = np.zeros((3,3),int)
a[[0,1,2],[2,0,1]] = [1,2,3]
a
array([[0, 0, 1],
       [2, 0, 0],
       [0, 3, 0]])

A = a.astype(str)
A
array([['0', '0', '1'],
       ['2', '0', '0'],
       ['0', '3', '0']],
      dtype='<U11')

A[[0,1,2],[0,1,2]] = 'X'
A 
array([['X', '0', '1'],
       ['2', 'X', '0'],
       ['0', '3', 'X']],
      dtype='<U11')

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

a = np.zeros((3,3))
a 
array([[ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.]])

a = np.zeros((3,3),int)
a
array([[0, 0, 0],
       [0, 0, 0],
       [0, 0, 0]])

a = np.zeros((3,3),bool)
a
array([[False, False, False],
       [False, False, False],
       [False, False, False]], dtype=bool)

a = np.zeros((3,3),str)
a 
array([['', '', ''],
       ['', '', ''],
       ['', '', '']],
      dtype='<U1')