1

Next code is matlab code. I want to convert this code into python code in order to use it in Arcgis.

vals = zeros(size(a(:,:,1)));
 [~,indexOfMax] = max(a,[],3);
 for i=1:size(a,1)
    for j=1:size(a,2)
        vals(i,j) = b(i,j, indexOfMax(i,j));
    end 
 end

I'll explain briefly explain this code. I have two images (named A and B). Both have 7 layers at the same dimension (4169,6289,7). First I'd like to find the location of max value in A image and then get the value of B image at the location of max value which extracted from A image in previous step.

Thanks a lot

2
  • 2
    it seems that using pythons-matplotlib might be a good starting place Commented Dec 24, 2012 at 7:02
  • 3
    you should look into scipy at scipy.org/NumPy_for_Matlab_Users Commented Dec 24, 2012 at 7:19

1 Answer 1

2
vals = numpy.zeros((a.shape[0], a.shape[1]))
indexOfMax = numpy.argmax(a,2)
for i in range(a.shape[0]):
  for j in range(a.shape[1]):
    vals[i,j] = b[i,j, indexOfMax[i,j]]

It should also be possible to vectorize instead of using the for loops.

Be careful, in Python indentation is important! Keep the indentations before the second for loop and before vals.

Sign up to request clarification or add additional context in comments.

Comments

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.