import pandas as pd import numpy as np x1 = np.random.randint(0,2000,(12,220,80)) x2 = np.random.randint(0,2000,(12,220,1000))
I currently have two 3-D arrays that I want to combine together to make a 4-D array and looking for the most efficient way
I want to combine them so they have the shape (12,220,81,1000) so that the x1 is repeated 1000 times appending each element of the second array onto the end of the first array. I’ve tried different combinations of np.insert
, np.concatenate
and np.append
along the various axes but can’t seem to get it to produce the desired shape
Thanks for any help in advance
Advertisement
Answer
Make x1
a (12,220,80,1) and repeat
on the last axis to get (12,220,80,1000). Likewise expand x2
to (12,200,1,1000). Then you can concatenate on axis=2
.