Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to perform basic math on numpy ndarray

So, I have a numpy ndarray with dimensions (984, 1977, 2). What I want to accomplish is to have a numpy ndarray where I do basic math on the final values. So let’s say data is my ndarray. And data[0][0] equals to [72 46]. So I want to perform (72 – 46) / (72 + 46) and store that value in my new ndarray for each of the pair. Basically, it represents two stacked bands and the final output needs to be a resultant of the two based on the above formula (not NDVI). I have been looking at numpy’s tutorial to find an answer but no luck so far.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

For that array

x = data[:,:,0]
y = data[:,:,1]

are the two ‘last’ column values

res = (x-y)/(x+y)

should be the result you want for all pairs, a (984, 1977) shape array.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading