0

I have many numpy arrays of shape (Ni,227,227,3), where Ni of each array is different.

I want to join them and make array of shape (N1+N2+..+Nk,227,227,3) where k is the number of arrays.

I tried numpy.concatenate and numpy.append but they ask for same dimension in axis 0. I am also confused on what is axis 1 and axis 2 in my arrays.

  • 1
    `np.concatenate(alist, axis=0)` should work. Don't do this in a loop - collect a list of all the array, and do one concatenate. Forget about `np.append`. – hpaulj Jun 25 '18 at 06:10
  • What's alist here? – Shreyas Pimpalgaonkar Jun 25 '18 at 06:11
  • `alist` of all the arrays you want to join! – hpaulj Jun 25 '18 at 06:12
  • np.concatenate([a,b,c,d],axis=0) gives me ValueError: all the input arrays must have same number of dimension, ----- and the shapes are (1500, 227, 227, 3) (1500, 227, 227, 3) (0,) (1380, 227, 227, 3) – Shreyas Pimpalgaonkar Jun 25 '18 at 06:25
  • 1
    The `(0,)` does not have the same number of dimensions as the others. – hpaulj Jun 25 '18 at 06:30
  • Oh, I see, that was the problem (Also 4th array has different dimension). It was an empty array so concatenate doesn't work with empty arrays? – Shreyas Pimpalgaonkar Jun 25 '18 at 06:41
  • 0-dimensional arrays can't be concatenated. But a (0, 227, 227, 3) shape array could be concatenated with your other arrays, even though it is empty. The `1380` in the 4th array isn't a problem since you are concatenating on the first (0-th) axis. Practice concatenating small arrays where you can see what's happening! – hpaulj Jun 25 '18 at 06:55
  • yes, I understood. thank you. – Shreyas Pimpalgaonkar Jun 25 '18 at 06:57

1 Answers1

0

So, the main problem here was with the one of the arrays of shape (0,) instead of (0,227,227,3).

np.concatenate(alist,axis=0) works.