Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » [Math] Is there a name for this?

Credits go to SiegeLord for helping out!
This thread is locked; no one can reply to it. rss feed Print
[Math] Is there a name for this?
torhu
Member #2,727
September 2002
avatar

I'm doing something with NumPy. Is there a name for this?

array = max(array) - array

I want to call it complement, but I don't know if that's right... :'(

APPEND: I'll explain what the code does. It's vector operations, every element in array is subtracted from the max value.

Mark Oates
Member #1,146
March 2001
avatar

I'm assuming this is only useful when your max is a positive number?

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

torhu
Member #2,727
September 2002
avatar

I guess so, numbers are in the range [0, 1000] in practice.

Ariesnl
Member #2,902
November 2002
avatar

Array is an array and max(array) is a number...
so you are substracting an array from a number ?

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

bamccaig
Member #7,536
July 2006
avatar

torhu
Member #2,727
September 2002
avatar

It's numpy, so it's a vector operation.

If the array was sorted, it would be the same as reversing the array. But if you have an array [2, 0, 1], the result would be [0, 2, 1].

In pure Python:

a = [2, 0, 1]
maxval = max(a)
a = [maxval - x for x in a]

If the lowest value is not zero you need to compensate:

a = [-2, -1, 1]
maxval = max(a)
minval = min(a)
a = [maxval - x + minval for x in a]

SiegeLord
Member #7,827
October 2006
avatar

I tried looking, but couldn't find anything. I like the name 'complement', perhaps 'max complement' in this case.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

torhu
Member #2,727
September 2002
avatar

I ended up just called it complement, doesn't matter much anyway. But thanks. I'll give you a cookie ;)

I was using it when messing around with color schemes for an assignment at uni. We were drawing the Mandelbrot set, and there was a competition for the coolest image 8-)

Go to: