Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is my (2, 3, 4) shape np array
- array([[[ 0, 1, 2, 3],
- [ 4, 5, 6, 7],
- [ 8, 9, 10, 11]],
- [[12, 13, 14, 15],
- [16, 17, 18, 19],
- [20, 21, 22, 23]]])
- # I want to reshape the elements 8-to-15 in new 2D array
- # I will convert it to 1D array
- d321d = d.flatten()
- #This is how it looks now
- array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
- 17, 18, 19, 20, 21, 22, 23])
- #Now I will grab the elements that I want
- d1 = d321d[8:16]
- #This is how it looks now
- array([ 8, 9, 10, 11, 12, 13, 14, 15])
- # Finally I'm able to reshape above values in 2D array
- fd2 = np.reshape(d1, (-1, 4))
- #This is how it looks now
- #RESULT :
- array([[ 8, 9, 10, 11],
- [12, 13, 14, 15]])
Add Comment
Please, Sign In to add comment