I'm trying to convert an array of integers into their binary representations in python. I know that native python has a function called bin
that does this. Numpy also has a similar function: numpy.binary_repr
.
The problem is that none of these are vectorized approaches, as in, they only take one single value at a time. So, in order for me to convert a whole array of inputs, I have to use a for-loop and call these functions multiple times, which isn't very efficient.
Is there any way to perform this conversion without for-loops? Are there any vectorized forms of these functions? I've tried numpy.apply_along_axis
but no luck. I've also tried using np.fromiter
and map
and it was also a no go.
I know similar questions have been asked a few other times (like here), but none of the answers given are actually vectorized.
Pointing me into any direction would be greatly appreciated!
Thanks =)