I am trying to reshape I1 from (7,2) to (1,7,2) by means of a variable k which has the shape of old I1. But I get an error. Is there a way to do it?
import numpy as np
I1= np.array([[0, 1],
[0, 2],
[1, 3],
[2, 3],
[2, 5],
[3, 6],
[5, 6]])
k=I1.shape
I1=I1.reshape(1,k)
The error is
<module>
I1=I1.reshape(1,k)
TypeError: 'tuple' object cannot be interpreted as an integer
I1[None,...]I1[None,:,:]will give you a new array with an aditional axis with length 1. It's the same asI1[np.newaxis,:,:](new axis it's actuallyNonebut in a pretty way to be clear that you are adding an axis). Last but less recommendable is to create a list withI1and then create array agayn (more computation, less pretty, slower but a posible way)np.array( [I1] )(1,k)as a tuple is(1, (7,2)). It should be (1,7,2).