Skip to content
Advertisement

How to add 2D np array to front of 3D np array?

I have a 3D numpy array and I want to add a 2D np array of 0’s to the front of it.

JavaScript

I want to add another array B so that:

JavaScript

I’ve tried np.append(B,A) but it returns a 2D array.

Advertisement

Answer

You can do it using numpy.vstack and by reshaping your array. For instance:

JavaScript

By the way, you can create your array A more efficiently:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement