My goal is to do this:
weights[1][0][0] = some_object(1)
But it throws this error:
TypeError: float() argument must be a string or a number, not 'some_object'
Because of this I wawnt to change the dtype to 'object' In my code I have weights. They look like this:
>>> print(weights)
[ array([[-2.66665269, 0. ],
[-0.36358187, 0. ],
[ 1.55058871, 0. ],
[ 3.91364328, 0. ]])
array([[ 0.],
[ 0.]])]
I want to change weights[1][0][0] to an object. I am refering to the 0 in:
[ array([[-2.66665269, 0. ],
[-0.36358187, 0. ],
[ 1.55058871, 0. ],
[ 3.91364328, 0. ]])
array([[ 0.], #this zero right here
[ 0.]])]
I want to convert that 0 to some_object(1). So I change the dtype to 'object', but it remains float!
>>> weights=np.array(weights,dtype='object')
>>> weights.dtype
object
>>> weights[1].dtype
float64
>>> weights[1][0].dtype
float64
>>> weights[1][0][0].dtype
float64
So now I try:
>>> weights[1].dtype='object'
TypeError: Cannot change data-type for object array.
and this
>>> weights[1][0].dtype='object'
TypeError: Cannot change data-type for object array.
so now I cannot do this:
weights[1][0][0] = some_object(1)
TypeError: float() argument must be a string or a number, not 'object'
because the dtype is incorrect. How do I change the dtype?
Edit: I found an answer.
weights[1] = weights[1].tolist()
weights[1][0][0] = some_object(1)
....
weights=np.array(weights)