About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: December 2006

URL: http://cxc.harvard.edu/ciao3.4/where.tm.html
Hardcopy (PDF): A4 | Letter
AHELP for CIAO 3.4 where Context: slangrtl

Synopsis

Get indices where an integer array is non-zero

Syntax

Array_Type where (Array_Type a)

Description

The where function examines an numeric array a and returns an integer array giving the indices of a where the corresponding element of a is non-zero.

Although this function may appear to be simple or even trivial, it is arguably one of the most important and powerful functions for manipulating arrays.

Example

Consider the following:

    variable X = [0.0:10.0:0.01];
    variable A = sin (X);
    variable I = where (A < 0.0);
    A[I] = cos (X) [I];

Here the variable X has been assigned an array of doubles whose elements range from 0.0 through 10.0 in increments of 0.01. The second statement assigns A to an array whose elements are the sin of the elements of X. The third statement uses the where function to get the indices of the elements of A that are less than 0.0. Finally, the last statement substitutes into A the cos of the elements of X at the positions of A where the corresponding sin is less than 0. The end result is that the elements of A are a mixture of sines and cosines.

Hardcopy (PDF): A4 | Letter
Last modified: December 2006



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.