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

Stick the 3d numpy arrays and then remove the specific row

I have two numpy arrays with size (1,5,2) and (1, 1,2). I want to stick two of them in one array and build one array with (1, 6,2) and then delete the first row of the matrix and final array should be with size of (1,5,2).

import numpy as np
a = np.random.rand(1, 5, 2)
b = np.random.rand(1, 1, 2)

For example,

a = array([[[0.3324251 , 0.23363885],
    [0.58601194, 0.56248613],
    [0.38604242, 0.29020216],
    [0.11876984, 0.6805301 ],
    [0.67216552, 0.43272049]]])
b = array([[[0.25492274, 0.43373311]]])

output:

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

a = array([[[0.58601194, 0.56248613],
    [0.38604242, 0.29020216],
    [0.11876984, 0.6805301 ],
    [0.67216552, 0.43272049],
    [0.25492274, 0.43373311]]])

>Solution :

You can use the hstack and then delete the first row.

 x = np.hstack((a, b))[:, 1:,:]

 x = array([[[0.58601194, 0.56248613],
    [0.38604242, 0.29020216],
    [0.11876984, 0.6805301 ],
    [0.67216552, 0.43272049],
    [0.25492274, 0.43373311]]])
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