1

Assist me in creating 4d array. Below is my code for 3 dimension array. How do i get output in shape of (4,3,2,3)

Three_d_array - numpy.array([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]])

The above code provides output in shape of (3,2,3) but how to i get the 4d in this shape

1
  • please provide an example of the output you expect. Commented Jun 14, 2020 at 8:14

1 Answer 1

3
import numpy as np    
a = np.arange(72)
a = np.reshape(a, (4,3,2,3))

or:

a = np.array([[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]], [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]], [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]], [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]]])

or:

a = np.array([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]])
a = np.expand_dims(a, axis=0)
a = np.repeat(a, 4, axis=0)
Sign up to request clarification or add additional context in comments.

1 Comment

Hello, Can i code the same way as my 3d instead of using arrange or reshape? Trying to visualize how to code would...be

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.