I need big help, please check out this code:
import.math
dose =20.0
a = [[[2,3,4],[5,8,9],[12,56,32]]
[[25,36,45][21,65,987][21,58,89]]
[[78,21,98],[54,36,78],[23,12,36]]]
PAC = math.exp(-dose*a)
this what I would like to do. However the error I am getting is
TypeError: only length-1 arrays can be converted to Python scalars
If you want to perform mathematical operations on arrays (whatever their dimensions…), you should really consider using NumPy which is designed just for that. In your case, the corresponding NumPy command would be:
If NumPy is not an option, you’ll have to loop on each element of
a, compute yourmath.exp, store the result in a list… Really cumbersome and inefficient. That’s because themathfunctions require a scalar as input (as the exception told you), when you’re passing a list (of lists). You can combine all the loops in a single list comprehension, though:but once again, I would strongly recommend NumPy.