Home > Enterprise >  Combine specific value of Multiple Arrays into one Single Array
Combine specific value of Multiple Arrays into one Single Array

Time:01-06

Say for example I have these 3 arrays:

# Array 1:
array_1 = [[100, 0, 0, 0, 0, 100],
           [0, 100, 0, 0, 0, 100],
           [0, 0, 100, 100, 0, 0]]

# Array 2:
array_2 = [[0, 0, 0, 0, 100, 0],
           [0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 100]]

# Array 3:
array_3 = [[0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 100, 0],
           [0, 0, 0, 0, 0, 0]]

How will I be able to combine the 3 arrays into a one single array?

This will be the expected output:

[[100 0 0 0 100 100]
[0 100 0 0 100 100]
[0 0 100 100 0 100]]

As you can see, the 100s from array_1, array_2 and array_3 can be seen in the newly created array.

Combination of 100s must be with the same row as the other.

CodePudding user response:

In this case, you can just add the arrays together

>>> a = np.arange(18).reshape((3,6))
>>> b = np.arange(18).reshape((3,6))
>>> c = np.arange(18).reshape((3,6))
>>> a
array([[ 0,  1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10, 11],
       [12, 13, 14, 15, 16, 17]])
>>> a   b   c
array([[ 0,  3,  6,  9, 12, 15],
       [18, 21, 24, 27, 30, 33],
       [36, 39, 42, 45, 48, 51]])
  •  Tags:  
  • Related