0
I’m building a code that has a very similar structure to the code below.
from math import sin, pi
from numpy import zeros
djn = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
djn = array(djn)
def test(djn):
M = len(djn)
delta = zeros(M, float)
delta[0:M] = 0.409279709 * sin(((2*pi)/365)*(284+djn[0:M]))
return delta
res = test(djn)
The idea is that the function argument is an array as well as the output of it. However I have gotten the following error:
only size-1 arrays can be converted to Python scalars
But I’ve seen structures like this and I can’t see my mistake.
Thank you for your cooperation :)
The only problem with the above code is that you are not loading
array
,sin
andpi
. Behold here. However if the code is different and the error you put is what happens in the other code, use thenp.vectorize
– Paulo Marques
I ended up not putting, but was using the
sin
and thepi
ofmath
and not ofnumpy
– Syner
use the
sin
ofnumpy
. That alone is enough to solve the problem– Flavio Moraes
@Syner I know it’s not related to the problem, but I also realized that you wrote a term
2*pi/365
inside the sine and was wondering if it would not be360
because it looks like you wanted to convert degrees to radian, right?– Flavio Moraes