|
[Math] Is there a name for this? |
torhu
Member #2,727
September 2002
|
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
|
I'm assuming this is only useful when your max is a positive number? -- |
torhu
Member #2,727
September 2002
|
I guess so, numbers are in the range [0, 1000] in practice. |
Ariesnl
Member #2,902
November 2002
|
Array is an array and max(array) is a number... Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
bamccaig
Member #7,536
July 2006
|
Sounds like a shortcut for Array(max(array), len(array)) - array. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
torhu
Member #2,727
September 2002
|
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
|
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 |
torhu
Member #2,727
September 2002
|
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 |
|