Issue
I have an specific array which each rows has to array. I want to reshape it. But, I don't know how to reshape it to a 2d array. Here is my array:
x = np.array([[[array([0.23006942, 0.29322573, 0.37292298]),
array([0.23006942])],
[array([0.29322573, 0.37292298, 0.23006942]),
array([0.32480389])],
[array([0.37292298, 0.23006942, 0.32480389]),
array([0.31427784])]],
[[array([0.09971349, 0.08827682, 0.0900638 ]),
array([0.02251595])],
[array([0.08827682, 0.0900638 , 0.02251595]),
array([0.0986413])],
[array([0.0900638 , 0.02251595, 0.0986413 ]),
array([0.02144376])]]], dtype=object)
Here is the desired output:
out = np.array(
[
[array([0.23006942, 0.29322573, 0.37292298]),array([0.23006942])],
[array([0.29322573, 0.37292298, 0.23006942]),array([0.32480389])],
[array([0.37292298, 0.23006942, 0.32480389]),array([0.31427784])],
[array([0.09971349, 0.08827682, 0.0900638 ]),array([0.02251595])],
[array([0.08827682, 0.0900638 , 0.02251595]),array([0.0986413])],
[array([0.0900638 , 0.02251595, 0.0986413 ]),array([0.02144376])]
])
Any help appreciated.
Thanks
I've tried to use the reshape. But, it does not solve.
Solution
It's ragged, it's not concatenated. Is it a question of flattening the array to a list of arrays?
out = [x.tolist() for arr in x for x in arr]
Output:
[[array([0.23006942, 0.29322573, 0.37292298]), array([0.23006942])],
[array([0.29322573, 0.37292298, 0.23006942]), array([0.32480389])],
[array([0.37292298, 0.23006942, 0.32480389]), array([0.31427784])],
[array([0.09971349, 0.08827682, 0.0900638 ]), array([0.02251595])],
[array([0.08827682, 0.0900638 , 0.02251595]), array([0.0986413])],
[array([0.0900638 , 0.02251595, 0.0986413 ]), array([0.02144376])]]
Answered By - enke
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.