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.
How do I convert my list into an array of arrays? I'm not sure if I used the correct wording, but:
Here's an example:
What I have:
[[3948,1234,4928,9283,9238]]
What I am trying to have:
[[3948], [1234], [4928], [9283], [9238]]``` Thanks Guys!
list
np.array(alist)
reshape
import numpy as np d = np.array([3948,1234,4928,9283,9238]) dd =d.reshape((5,1)) print(dd.shape) (5, 1) print(dd)
Output
[[3948] [1234] [4928] [9283] [9238]]
Add a comment
This will work fine:
t = [[3948,1234,4928,9283,9238]] k = [[i] for i in t[0]] print(k)
[[3948], [1234], [4928], [9283], [9238]]
You could use
array_of_arrays = [[num] for num in array]
Which creates a new list by going through every value of your previous list and adds [value] to it.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
listobject.np.array(alist)produce? Do you know aboutreshape? Or transpose?