0

I am trying to loop through a 2D array of coordinates and apply a function to them, but I am having trouble indexing both the x and y positions properly. Here is my code:

for i,j in range(330):
    aperture = phot.aperture.CircularAperture((xy[i,j]),3)
    photometry = phot.aperture_photometry(xy, aperture)

the xy array has a size of (330,2), and I want the function to be applied to each set of coordinates, but instead I receive the error cannot unpack non-iterable int object. How can I solve this?

8
  • what do you spect to be your i,j index? Commented Nov 2, 2021 at 16:25
  • for i,j in range(330) this is incorrect. You will get only one value each time. Commented Nov 2, 2021 at 16:31
  • Are you looking to use xy[i,1] and xy[i,2] ? Commented Nov 2, 2021 at 16:31
  • can you provide the full code please? Commented Nov 2, 2021 at 16:33
  • @UlisesBussi I want the i index to refer to the x coordinate and the j index to be the y coordinate Commented Nov 2, 2021 at 16:40

1 Answer 1

3

to address each element of xy array, you need to do something like this

for i in range(330):
    for j in range(2):
        aperture = phot.aperture.CircularAperture((xy[i,j]),3)
        photometry = phot.aperture_photometry(xy, aperture)
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.