Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
So, if I want a numpy array [0,1,2,3,4,5,6] (or any other vector with, say 7 elements) which has the dimension (7,1) and not (7,), is there anyway to do that when I create it, instead of writing t=np.expand_dims(np.array(range(7)),axis=1) ?
t=np.expand_dims(np.array(range(7)),axis=1)
np.arange(7)[:,None]
range(7)
np.array(range(7)).reshape((7,1))
np.array([list(range(7))]).T
np.arange(7)
Best way I can think of is
i = range(7) j = np.array(i)[:, None]
A slightly shorter way is:
j = np.atleast_2d(i).T
Add a comment
Just transpose it
x = np.array([range(7)]).T
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
np.arange(7)[:,None]? Starting withrange(7), you need to expand dims somehow.np.array(range(7)).reshape((7,1))ornp.array([list(range(7))]).Tis the best I can think of.np.arange(7)isn't dimensionless. It is 1d, We don't need 2d to represent a list of 7 numbers.