pythonarrays

performing a math function for array


I am new to programming so, I might sound naive. I have a set of arrays

matrix([[0.23316744, 0.62686578, 0.23497639, 0.41566779, 0.18428155]]), matrix([[0.26199825, 0.7148431 , 0.2296318 , 0.36555626, 0.18962302]]),............. etc.

I would like to perform the math.arctan function on each element and bring it back to the same format to perform further operations.

I cannot perform the math.arctan on it directly since it gives the error

TypeError: must be real number, not list

so I tried using the np.asscalar to separate each term but it does not work and gives the error

TypeError: only size-1 arrays can be converted to Python scalars

Any help in this would be really helpful.


Solution

  • it gives you the error

    TypeError: must be real number, not list
    

    because the function Math.arctan Expect a number not a List , a simple solution is to loop into your list and for each element L[i][j] do L[i][j] = Math.arctan(L[i][j])

    in this code, I suppose you have a list of list and each child liste contain numbers

    for i in range(0,len(l)):
        for j in range(0,len(l[i])):
            L[i][j] = Math.arctan(L[i][j])