Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing autograd arraybox values

I am trying to use the python package autograd and I want to use values of an autograd arraybox in an interpolation

np.interp(x, x_values, y_values)

where y_values are store in an autograd arraybox. This leads to an error

TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'

which is connected to the fact the y_values is an autograd arraybox. I don't understand why I get this error, since I thought that autograd should work with numpy? But ok if I can convert the autograd arraybox into a numpy array I can work with that, but that does not seem to work either?

floats = [float(x) for x in y_values]

leads to

TypeError: float() argument must be a string or a number, not 'ArrayBox'
like image 870
carl Avatar asked Feb 24 '26 16:02

carl


1 Answers

I did:

myvariable._value

and I got an array with the values inside the ArrayBox, which then I could manipulate.

I figured it out after checking the attributes of the ArrayBox using call(myvariable). Looks it is not documented anywhere. Hope it helps

like image 52
Saray Soldado Magraner Avatar answered Feb 27 '26 05:02

Saray Soldado Magraner