March 2003
Intermediate to advanced
656 pages
39h 30m
English
compress
compress(condition,a,axis=0)
Returns an array c with the same type code
and rank as a.
c includes only the elements of
a for which the item of
condition, corresponding along the given
axis, is true. For example,
compress((1,0,1),a
)
= =
take(
a
,(0,2),0)
since (1,0,1) has true values only at indices
0 and 2.
Here’s how to get only the even numbers from an
array:
a = Numeric.arange(10) print Numeric.compress(a%2= =0, a) # prints: [0 2 4 6 8]