1

I have read 3 raster images of equal shape (500 by 500) as numpy array, and have put them in this way:

rasters = np.array(A,B,C)

Where A, B, C are 2d numpy arrays belonging to each image.

Now I have to calculate the followings:

result1 = B-A
result2 = C-B

Then,

final_result = np.max([result1,result2],axis = 0)

The final_result should have the same shape of A or B or C (i.e., 500 by 500)

How can I do it?

4
  • Is the issue getting A.B and C out of rasters, or doing the subtractions, or something else? Commented Dec 21, 2014 at 9:45
  • The issue is to doing substractions Commented Dec 21, 2014 at 9:45
  • np.array(A,B,C) or np.array([A,B,C])? Commented Dec 22, 2014 at 1:24
  • np.array([A,B,C]). sorry for that. Commented Dec 22, 2014 at 3:00

2 Answers 2

3

You can use np.diff and np.max:

np.max(np.diff(rasters, axis=0), axis=0)

Alternatively:

np.max(rasters[1:] - rasters[:-1], axis=0)
Sign up to request clarification or add additional context in comments.

Comments

1

B-A is accomplished using np.subtract(B,A).

3 Comments

In my real problem, A, B, C...are many. So looking for pythonic way of doing it.
And, I want to do it from the 'rasters'.
@simen: So "I have read 3 raster images" was not exactly true, nor was "The issue is doing subtractions". Good to know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.