0

Is it possible to fulfill numpy arrays with arrays? I want to obtain a following structure without specifying values by hand

ves = np.zeros((12,12), dtype=object)
ves[0][0] = np.array([0,0,0])
ves[0][1] = np.array([0,0,0])
ves[0][2] = np.array([0,0,0])
ves[0][3] = np.array([0,0,0])
and so on...

In order to obtain the expected result, I have tried ves = np.zeros((12,12), dtype=array), but it does not work.

Monica
  • 1,030
  • 3
  • 17
  • 37

1 Answers1

2
import numpy as np 

v = np.zeros([12,12,3])

As per my understanding through your explanation, it seems you wanted a three dimension matrix where each cell needs three 0 values for 12*12 places. So the above code creates the value filled ndarray.

  • Thank you! Could you help me to understand what is the difference between np.zeros([12,12,3]) and np.zeros((12,12,3))? – Monica Mar 14 '17 at 13:24
  • There is no difference in the result. In the first case you input a list (marked by square brackets) in the second you input a tuple (round brackets). See here for more details: http://stackoverflow.com/questions/626759/whats-the-difference-between-lists-and-tuples – zinjaai Mar 14 '17 at 13:31