Reputation: 37
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!
Upvotes: 1
Views: 111
Reputation: 160
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]]
Upvotes: 2
Reputation: 1498
This will work fine:
t = [[3948,1234,4928,9283,9238]]
k = [[i] for i in t[0]]
print(k)
Output
[[3948], [1234], [4928], [9283], [9238]]
Upvotes: 1
Reputation:
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.
Upvotes: 0