Reputation: 4766
I want to create a n-dimentional numpy array. Following is my code
import numpy as np
random_weights = np.empty(3)
random_weights[0] = np.array([0,1,2])
random_weights[1] = np.array([3,4,5])
Above code gives me ValueError: setting an array element with a sequence.
error. I am trying to create multi-dimentional array. What is the reason for this issue?
Upvotes: 0
Views: 30
Reputation: 800
If you want a 2d array, you need to define it.
import numpy as np
random_weights = np.empty((2, 3)) # 2 rows, 3 columns
random_weights[0] = np.array([0,1,2])
random_weights[1] = np.array([3,4,5])
Upvotes: 2