I have a 3 dimensional numpy array with values ranging from 0 to 1.06. I need to rescale them between 0 and 255. How to achieve this?
Asked
Active
Viewed 253 times
4
-
1Does this answer your question? [How to normalize a NumPy array to within a certain range?](https://stackoverflow.com/questions/1735025/how-to-normalize-a-numpy-array-to-within-a-certain-range) – Stas Buzuluk Dec 25 '19 at 12:01
1 Answers
4
You just divide these by 1.06
and then multiply these with 255
. So if a
is your array, you can construct a rescaled array b
with:
b = 255 * a / 1.06
If you want to make these integers (or bytes), you can use:
(255 * a / 1.06).astype(int)
or np.uint8
for bytes.

Willem Van Onsem
- 443,496
- 30
- 428
- 555