numpy collapse last dimension

Solutions on MaxInterview for numpy collapse last dimension by the best coders in the world

showing results for - "numpy collapse last dimension"
Jermaine
15 Aug 2020
1>>> arr = numpy.zeros((50,100,25))
2>>> arr.shape
3# (50, 100, 25)
4
5>>> new_arr = arr.reshape(5000,25)
6>>> new_arr.shape   
7# (5000, 25)
8
9# One shape dimension can be -1. 
10# In this case, the value is inferred from 
11# the length of the array and remaining dimensions.
12>>> another_arr = arr.reshape(-1, arr.shape[-1])
13>>> another_arr.shape
14# (5000, 25)
15