Advertisement
yclee126

numpy extend array

Sep 23rd, 2021
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. import numpy as np
  2.  
  3. b = np.array([
  4. [1, 2, 3],
  5. [4, 5, 6],
  6. [7, 8, 9]
  7. ], dtype='float')
  8.  
  9. b = np.concatenate((np.transpose([b[:, 0]]), b), axis=1) # left
  10. b = np.concatenate((b, np.transpose([b[:, -1]])), axis=1) # right
  11. b = np.concatenate(([b[0, :]], b), axis=0) # up
  12. b = np.concatenate((b, [b[-1, :]]), axis=0) # down
  13.  
  14. print(b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement