I am trying to read through the numbers within a 1D array, but I seem to be having some trouble. It seems that this is a common issue, but I can't seem to figure out the solution in my case.
I have extracted a list of star coordinates from an image, and want to read through the x and y values:
# Find centres of mass of each labeled objects
xy = np.array(ndimage.center_of_mass(data, labeled, range(1, num_objects+1)))
# Unpack star coordinates, split array into x and y components
print(xy)
x, y = np.hsplit(xy, 2)
# array of coordinates
star_coords = [x, y]
print(star_coords)
for i in range(len(star_coords)):
# Fit a PSF to each star
print(x[i])
x = x[i]
y = y[i]
x2, y2, amplitude, intensity, sigma_y_fitted, sigma_x_fitted = fitPSF(im_array, global_mean, x, y, config)
When I use the for loop to go through the elements in my 1D array of values (len = 4031) and reference it as x[i]
, I receive an error that says index 1 is out of bounds for axis 0 with size 1. I assume this means the code is interpreting the [i]
index across columns rather than rows. How do I fix this so that way it reads down the elements of the array rather than across the non-existent columns?