3

I am not sure why I can not concatenate multiple dimensions of an array together using the the numpy.concatenate function. For example:

    array_2d.shape = [1200,1200]
    array2_2d.shape = [1200,1200]
    final_array1 = numpy.concatenate((array_2d,array2_2d),axes=0) # shape = (2400,1200)
    final_array2 = numpy.concatenate((array_2d,array2_2d),axes=1) # shape = (1200,2400)

Is there a way I can get the 2 arrays to concatenate both axes to yield a shape of (2400,2400)? Or am I just thinking of this approach incorrectly with the concatenation of arrays? Some help would be much appreciated!!!

4
  • Take a look to python-course.eu/numpy.php Commented Nov 11, 2015 at 19:04
  • I am confused by these words "concatenate multiple dimensions of an array together". Commented Nov 11, 2015 at 19:05
  • You are trying to stick two square blocks together to make a bigger square block. This will not work; you aren't putting together enough blocks to make the big block you want. Commented Nov 11, 2015 at 19:11
  • Show us with small arrays (e.g. (2,3) size)) what you want to do. Commented Nov 11, 2015 at 19:59

2 Answers 2

1

Let's think about what you're trying to accomplish, let's call array1 A, and array2 B, and some unknown array as X. Like you said, the following is 2400 x 1200:

 | A |
 | B |

But this would be a 2400 by 2400 array:

 | A | X |
 | X | B |

and so would this:

 | A | X |
 | B | X |

and this...:

 | A | A |
 | B | B |

The real question is how many times you want to concatenate each array and in which dimension or if you want to zero pad:

 | A | 0 |
 | 0 | B |

Which would be accomplished by using numpy to create an array of zeros and concatenating in the appropriate direction on both A and B before concatenating the results together.

Sign up to request clarification or add additional context in comments.

Comments

1

You should use numpy.tile(). Read this link for more information.

example:

a = np.array(([1,2],[3,4]))
b = np.tile(a, (2,2))

will create a 4x4 array from a 2x2 array, by repeating both axis.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.