I'm trying to convert a 2d NumPy array of complex numbers into another 2d array RGB values for an image, by mapping a function over the array.
This is the function:
import numpy as np
import colorsys
def ComplexToRGB(complex):
angle = ((np.angle(complex,deg=True)+360)%360)/360
magnitude = np.absolute(complex)
rawColor = colorsys.hls_to_rgb(angle,0.5,1-np.log2(magnitude)%1)
return rawColor
I map this function over an array by passing the array as input:
print(ComplexToRGB(foo))
where foo is foo=np.linspace(-1-1j,1+1j,11).
When I pass a single complex number as an input, I don't get an error, but when I try to use an array as an input, I get the rather mysterious error
Exception has occurred: ValueError
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
File "C:\Users\trevo\Documents\GitHub\NumPy-Complex-Function-Grapher\colorTest.py", line 7, in ComplexToRGB
rawColor = colorsys.hls_to_rgb(angle,0.5,1-np.log2(magnitude)%1)
File "C:\Users\trevo\Documents\GitHub\NumPy-Complex-Function-Grapher\colorTest.py", line 12, in <module>
print(ComplexToRGB(foo))
I understand that you can't use Boolean conditionals when you map over an array, but I don't have any logic in my function, just math, so I'm not user where the error is coming from. Thanks for your help!