numpy array merge

N

Nathan

Is there an easy way to merge two numpy arrays with different rank
sizes (terminology?). I want to make a single array by concatenating
two arrays along a given direction and filling the excess cells with a
dummy variable. numpy concatenate works well as long as the two
arrays have the same dimension, but I want to do this on two array
with a matching dimension size. An example:

import numpy as np
a = np.array([[1,2,3],[4,5,6]])
b = np.array([[1,2],[3,4],[5,6]])
np.concatenate((a,a),axis=1) #This works fine, but isn't what I need.
Out: array([[1, 2, 3, 1, 2, 3],
[4, 5, 6, 4, 5, 6]])
np.concatenate((a,b),axis=1) #This doesn't work, but this is what I
need.

I want to fill the third row of array "a" with a dummy variable (99999
or NaN) and concatenate with "b" to make:
[1,2,3,1,2]
[4,5,6,4,5]
[99999,99999,99999,5,6]

This just seems like it would be relatively common. So I thought I'd
check if I'm missing something before I go write the logic. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top