Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

reshape the array with specific form

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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])]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading