python - Fastest way to convert ubyte [0, 255] array to float array [-0.5, +0.5] with NumPy -
The question is in the title and it is very straightforward.
I have a file from F
I am reading the ubyte
array:
arr = numpy.fromfile (F, '& gt; u1', size * rows * cols Currently, I am rearranging the data in 3 passes, as follows: < arr = images.astype (float) arr - = max_value / 2.0 arr / = max_value
Since The array is somewhat larger, it takes an important part of each other.
It would be nice if I could do this through data 1 or 2 near Because I think it will be faster.
Do I have to reduce the number of passes for a "composite" vector?
or, do I have to speed up this speed Another way?
I did: looks fast No, I have finished it, this is my system It is almost twice as fast as it seems that As stated in the observations, it is actually a fast yet easy way, to achieve it. This is another factor on my system, which is faster than two, but mostly due to the use of
ar = ar - 255/2 r * * = 1./255
:)
ar = ar - 255/2
In addition to decreasing and type conversion on the fly, it does not optimize the segmentation with a scalar: it is faster to split a bunch of times many times on the array and then on the array. Although additional floating-point operation round-of-error may increase. numexpr
multiple cores and not so much that it only passes a single pass on the array code: < / P>
import numexpr ar = numexpr.evaluate ('(- 255.0 / 2.0) / 255.0')
Comments
Post a Comment