# [MATRIX-SIG] cmp?

**Tom Short
**
ta.short@pti-us.com

*Tue, 17 Jun 1997 17:41:03 +0000*

>* select product_id, dept_number, sum(sales-expenses)
*>* from sales_info
*>* group by product_id, dept_number
*>*
*>* with result columns
*>*
*>* product_id, dept_number, sum(sales-expenses) for dept&prod
*
In Yorick, the "where" function is great for this sort of thing:
>* a=[1,2,3,4,5]; b=a*10; c=a*100
*>* idx=where(a==2&b==20)
*>* write, a(idx), b(idx), c(idx)
* 2 20 200
In Python, you can use the same approach, but it is more complex
(primarily because the boolean comparisons have to be done with
functions):
>>>* a=array([1,2,3,4,5])
*>>>* b=10*a
*>>>* c=100*a
*>>>* idx = nonzero(where(boolean_and(equal(a,2),equal(b,20)),1,0))
*>>>* print take(a,idx), take(b,idx), take(c,idx)
*2 20 200
- Tom
--------------------------
See the PTI Lightning Photo Gallery: http://www.pti-us.com/pti/consult/dist/photos.htm
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________