Skip to main content
added 30 characters in body; edited tags
Source Link
user2988577
  • 4.2k
  • 7
  • 23
  • 22

I.m facing a little issue to combine arrays in a certain manner. Let's say we have a=array([[1,1,1],[2,2,2],[3,3,3]]) b=array([[10,10,10],[20,20,20],[30,30,30]]) I

a=array([[1,1,1],[2,2,2],[3,3,3]])

b=array([[10,10,10],[20,20,20],[30,30,30]])

I wish to get

c=array([[[1,1,1],[10,10,10]],[[2,2,2],[20,20,20]],[[3,3,3],[30,30,30]]])

The real issue is that my arrays a and b are much longer than 3 coordinates!

The best I achieved using concatenate is:   

concatenate((a,b),axis=2) which

which results in   

array([[ 1, 1, 1, 10, 10, 10], [ 2, 2, 2, 20, 20, 20], [ 3, 3, 3, 30, 30, 30]]) it

it is pretty good but not have enough depth.

Also, I've tried something from another question to get the desired depth:   

d=concatenate((a[...,None],b[...,None]),axis=2) but result

but results in: `array([[[ 1, 10], [ 1, 10], [ 1, 10]],

 array([[[ 1, 10],
    [ 1, 10],
    [ 1, 10]],

   [[ 2, 20],
    [ 2, 20],
    [ 2, 20]],

   [[ 3, 30],
    [ 3, 30],
    [ 3, 30]]])

` WhichWhich still does not works...

I.m facing a little issue to combine arrays in a certain manner. Let's say we have a=array([[1,1,1],[2,2,2],[3,3,3]]) b=array([[10,10,10],[20,20,20],[30,30,30]]) I wish to get

c=array([[[1,1,1],[10,10,10]],[[2,2,2],[20,20,20]],[[3,3,3],[30,30,30]]])

The real issue is that my arrays a and b are much longer than 3 coordinates!

The best I achieved using concatenate is:  concatenate((a,b),axis=2) which results in  array([[ 1, 1, 1, 10, 10, 10], [ 2, 2, 2, 20, 20, 20], [ 3, 3, 3, 30, 30, 30]]) it is pretty good but not have enough depth.

Also, I've tried something from another question to get the desired depth:  d=concatenate((a[...,None],b[...,None]),axis=2) but result in: `array([[[ 1, 10], [ 1, 10], [ 1, 10]],

   [[ 2, 20],
    [ 2, 20],
    [ 2, 20]],

   [[ 3, 30],
    [ 3, 30],
    [ 3, 30]]])

` Which still does not works...

I.m facing a little issue to combine arrays in a certain manner. Let's say we have

a=array([[1,1,1],[2,2,2],[3,3,3]])

b=array([[10,10,10],[20,20,20],[30,30,30]])

I wish to get

c=array([[[1,1,1],[10,10,10]],[[2,2,2],[20,20,20]],[[3,3,3],[30,30,30]]])

The real issue is that my arrays a and b are much longer than 3 coordinates!

The best I achieved using concatenate is: 

concatenate((a,b),axis=2)

which results in 

array([[ 1, 1, 1, 10, 10, 10], [ 2, 2, 2, 20, 20, 20], [ 3, 3, 3, 30, 30, 30]])

it is pretty good but not have enough depth.

Also, I've tried something from another question to get the desired depth: 

d=concatenate((a[...,None],b[...,None]),axis=2)

but results in:

 array([[[ 1, 10],
    [ 1, 10],
    [ 1, 10]],

   [[ 2, 20],
    [ 2, 20],
    [ 2, 20]],

   [[ 3, 30],
    [ 3, 30],
    [ 3, 30]]])

Which still does not works...

edited tags
Link
Saullo G. P. Castro
  • 59.4k
  • 28
  • 191
  • 244
Source Link
user2988577
  • 4.2k
  • 7
  • 23
  • 22

Combining numpy multi-dimensional arrays

I.m facing a little issue to combine arrays in a certain manner. Let's say we have a=array([[1,1,1],[2,2,2],[3,3,3]]) b=array([[10,10,10],[20,20,20],[30,30,30]]) I wish to get

c=array([[[1,1,1],[10,10,10]],[[2,2,2],[20,20,20]],[[3,3,3],[30,30,30]]])

The real issue is that my arrays a and b are much longer than 3 coordinates!

The best I achieved using concatenate is: concatenate((a,b),axis=2) which results in array([[ 1, 1, 1, 10, 10, 10], [ 2, 2, 2, 20, 20, 20], [ 3, 3, 3, 30, 30, 30]]) it is pretty good but not have enough depth.

Also, I've tried something from another question to get the desired depth: d=concatenate((a[...,None],b[...,None]),axis=2) but result in: `array([[[ 1, 10], [ 1, 10], [ 1, 10]],

   [[ 2, 20],
    [ 2, 20],
    [ 2, 20]],

   [[ 3, 30],
    [ 3, 30],
    [ 3, 30]]])

` Which still does not works...