Can anyone explain what this line is doing in python code ?
X.reshape((X.shape[0], 1) + X.shape[1:])
I am using numpy here.
Can anyone explain what this line is doing in python code ?
X.reshape((X.shape[0], 1) + X.shape[1:])
I am using numpy here.
Basically, this code is changing the shape of X to have an additional (size 1, or singleton if you are used to MATLAB) dimension. So if the shape was previously (3,3,3) it changes it to (3,1,3,3). This doesn't add any data since 3x3x3=3x1x3x3=27 It would probably be used so that the number of dimensions match (for functions that include another array). An equivalent form would be:
X = X[:, None, ...]
For more about why you might want to do this, see here