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

np.concatenate(np.stack the different arrays with a general solution

I have 6 array with same size. I have a general function and based on a value I should consider 2, 3, 5, 6 array of these and concate them with the following way. Could you please help me with a general solution for this? Here I only provide a simple example and in my real data, I should build different array and I have more than 20 which I should use.

import numpy as np
a = np.random.randint(3, size = (2,4))
b = np.random.randint(3, size = (2,4))
c = np.random.randint(3, size = (2,4))
d = np.random.randint(3, size = (2,4))
e = np.random.randint(3, size = (2,4))
f = np.random.randint(3, size = (2,4))

value=6
out = np.concatenate(np.stack((a,  b,  c,  d,  e,    f),    axis=1))

value=3
out = np.concatenate(np.stack((a,  b,  c),    axis=1))

value=2
out = np.concatenate(np.stack((a,  b),    axis=1))

>Solution :

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

The general solution to most problems with many variables is to use a container:

lst = [a, b, c, d, e, f]

value=6
out = np.concatenate(np.stack(lst[:value],    axis=1))
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