Home > Software design >  Is there a way to scale data around a value in python?
Is there a way to scale data around a value in python?

Time:07-16

I'm trying to think of a way to scale my data in python around the number 2. I would need something like a MinMaxScaler, where 2 is the maximum that's scaled to 1, but with the possibility of going over 2. I'm not sure how to approach this, I'm open to any solutions, as I couldn't come up with anything useful.

So let's say I would have these as inputs: a = [0, 1, 1.5, 2, 2.5, 3]

and I would get these values back scaled = [-1, 0, 0.5, 1, 0.5, 0]

Thank you

CodePudding user response:

From your desired result, I guess you want code like this:

scaled = [1 - abs(item - 2) for item in a]

Could that be it?

  • Related