Python Forum
Expand the range of a NumPy array?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Expand the range of a NumPy array?
#1
Hello everyone,

I have to agree that I am not great at coding and math but this forum has helped me a lot before and come seeking your help once again.


Let's say I have a multi dimensional array "a" with numbers ranging from -256 to 256. Not necessary the min and max value in that array will be at positive or negative 256.

I normalize this array between the range of 0 to 255 (unsigned 8 bit integer) using:
c = (255*(a - np.min(a))/np.ptp(a)).astype(int)
Or I can normalize between -128 to 127 (signed 8 bit integer using:
l, u = np.amin(a), np.amax(a)
ints = np.rint((a- l) * (255 / (u - l))) - 127
My question is, if I know the original min and max values of the array "a", how can I expand it back to those min and max values?
I know there will be some resolution loss, but I am okay with it.

Respectfully,
PythonNPC.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert numpy array to image without loading it into RAM. DreamingInsanity 7 5,917 Feb-08-2024, 09:38 AM
Last Post: paul18fr
  IPython errors for numpy array min/max methods muelaner 1 575 Nov-04-2023, 09:22 PM
Last Post: snippsat
  Change a numpy array to a dataframe Led_Zeppelin 3 1,131 Jan-26-2023, 09:01 PM
Last Post: deanhystad
  from numpy array to csv - rounding SchroedingersLion 6 2,211 Nov-14-2022, 09:09 PM
Last Post: deanhystad
  How to expand and collapse individual parts of the code in Atom Lora 2 1,168 Oct-06-2022, 07:32 AM
Last Post: Lora
  numpy.array has no attribute head Led_Zeppelin 1 1,254 Jul-13-2022, 12:56 AM
Last Post: Led_Zeppelin
  Seeing al the data in a dataframe or numpy.array Led_Zeppelin 1 1,155 Jul-11-2022, 08:54 PM
Last Post: Larz60+
  go over and search in numpy array faster caro 7 1,776 Jun-20-2022, 04:54 PM
Last Post: deanhystad
  Creating a numpy array from specific values of a spreadsheet column JulianZ 0 1,137 Apr-19-2022, 07:36 AM
Last Post: JulianZ
  Trying to understand Numpy/array nabuchadresar 2 1,835 Dec-17-2021, 07:52 AM
Last Post: nabuchadresar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020