fork download
  1. # setting up np.ndarray using np.zeros (3 rows, 20 columns)
  2. import numpy as np
  3. a = np.zeros((3,20))
  4.  
  5. # updating values where needed by index
  6. a[0,17] = 1
  7. a[1,14] = 1
  8. a[2,15] = 1
  9.  
  10. # summation is as follows:
  11. s = np.sum(a, axis=0)
  12. print(a)
  13. print(s)
Success #stdin #stdout 0.11s 23408KB
stdin
Standard input is empty
stdout
[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0.]
 [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0.]]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 1. 0. 1. 0. 0.]