I'm trying to set an element of a Numpy array to be another Numpy array. I'm not sure on how to do this since every time I try I get ValueError: setting an array element with a sequence.
I know this is possible with Python's list
since I can append the new array to list and it will work.
This is an example of what I'm trying to do:
import numpy as np
finalArray = np.zeros(3)
finalList = []
a = np.arange(128).reshape(32,4)
b = np.arange(124).reshape(31,4)
c = np.arange(120).reshape(30,4)
# This works
finalList.append(a)
finalList.append(b)
finalList.append(c)
# This doesn't work
finalArray[0] = a
finalArray[1] = b
finalArray[2] = c
Any ideas on how to do this?
Numpy arrays cannot be filled with arbitrary types. They are more like the arrays of C or Java. To create a two dimensional array, feed a two dimensional list into the np.array function. For example,
x = np.array([[0,0,0],[0,0,0],[0,0,0]])
creates a 3x3 two dimensional array filled with zeros.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With