python - Extract indices of array outside of a slice -


i want perform statistics on annulus around central portion of 2d array (performing statistics on background around star in image,for instance). know how obtain 2d slice of region inside of array , return indices of slice, there way of obtaining indices of values outside of slice?

i have 2d array called 'z' , box size (psf_box) around want perform statistics. i've got far:

center = np.ceil(np.shape(z)[0]/2.0) # center of array # make 2d slice of star, , convert pixels nan annulus[center-ceil(psf_size/2.0):center+ceil(psf_size/2.0)-1,\ center-ceil(psf_size/2.0):center+ceil(psf_size/2.0)-1] = np.nan np.savetxt('annulus.dat',annulus,fmt='%s') 

i convert pixels inside of box slice nan, don't know how output indices of pixels outside of box not 'nan'. or better yet, there way perform operations on area around slice directly? (as opposed outputting pixel values aren't nan)

i hope represents want do, ie. elements of annulus in 2d data. if data outside annulus change condition.

import numpy np  #construct grid x= np.linspace(0,1,5) y= np.linspace(0,1,5) xv,yv = np.meshgrid(x, y, sparse=false, indexing='ij')   # gaussian function x0,y0=0.5,0.5 zz= np.exp(- (xv-x0)**2 - (yv-y0)**2)  # function on grid  print 'function\n', zz # distance metric on grid distance =  np.sqrt(   (xv-x0)**2+ (yv-y0)**2)   print 'distance center\n', distance  # make condition , apply array cond= (distance>0.3) & (distance<0.7) print  'selection\n',zz[cond]   # if care locations of annulus    print xv[cond] print yv[cond] 

output:

function [[ 0.60653066  0.73161563  0.77880078  0.73161563  0.60653066]  [ 0.73161563  0.8824969   0.93941306  0.8824969   0.73161563]  [ 0.77880078  0.93941306  1.          0.93941306  0.77880078]  [ 0.73161563  0.8824969   0.93941306  0.8824969   0.73161563]  [ 0.60653066  0.73161563  0.77880078  0.73161563  0.60653066]] distance center [[ 0.70710678  0.55901699  0.5         0.55901699  0.70710678]  [ 0.55901699  0.35355339  0.25        0.35355339  0.55901699]  [ 0.5         0.25        0.          0.25        0.5       ]  [ 0.55901699  0.35355339  0.25        0.35355339  0.55901699]  [ 0.70710678  0.55901699  0.5         0.55901699  0.70710678]] selection [ 0.73161563  0.77880078  0.73161563  0.73161563  0.8824969   0.8824969   0.73161563  0.77880078  0.77880078  0.73161563  0.8824969   0.8824969   0.73161563  0.73161563  0.77880078  0.73161563] [ 0.    0.    0.    0.25  0.25  0.25  0.25  0.5   0.5   0.75  0.75  0.75   0.75  1.    1.    1.  ] [ 0.25  0.5   0.75  0.    0.25  0.75  1.    0.    1.    0.    0.25  0.75   1.    0.25  0.5   0.75] 

see great answer : numpy function multiple conditions


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -