fork download
  1. import numpy as np
  2.  
  3. a = np.array([[1,9],[2,9],[3,9],[4,9],[5,9],[6,9],[7,9],[8,9]])
  4. b = np.array([[]])
  5. print(a)
  6.  
  7. for i in range(len(a)):
  8. if i > 0 and i % 2 == 0:
  9. b = np.append(b, a[i, 0] - a[i-2, 0])
  10. else:
  11. b = np.append(b, 0)
  12.  
  13. print(b.shape)
  14.  
  15. b = b.reshape(b.shape[0], 1)
  16.  
  17. print(b)
  18.  
  19. c = np.concatenate((a,b), axis=1)
  20.  
  21. print(c)
Success #stdin #stdout 0.19s 27256KB
stdin
Standard input is empty
stdout
[[1 9]
 [2 9]
 [3 9]
 [4 9]
 [5 9]
 [6 9]
 [7 9]
 [8 9]]
(8,)
[[ 0.]
 [ 0.]
 [ 2.]
 [ 0.]
 [ 2.]
 [ 0.]
 [ 2.]
 [ 0.]]
[[ 1.  9.  0.]
 [ 2.  9.  0.]
 [ 3.  9.  2.]
 [ 4.  9.  0.]
 [ 5.  9.  2.]
 [ 6.  9.  0.]
 [ 7.  9.  2.]
 [ 8.  9.  0.]]