addressing matrix elements
- To: mathgroup at smc.vnet.net
- Subject: [mg3566] addressing matrix elements
- From: drc at emi.net (David Cabana)
- Date: Mon, 25 Mar 1996 21:33:49 -0500
- Organization: CyberGate, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
The Mma language sometimes drives me crazy. If I don't practice it regularly, I seem to forget everything. Here's what I want to do, but can't. Say M is a matrix of integers. I want to func[M, k] to return a matrix same dimensions as M, each entry consisting of the corresponding entry of M taken modulo k. For instance, func[{{22,33}, {44,55}}, 10] should return {{2,3}, {4,5}}. I would like this to work for arbitrary rectangular integer matrices, but am not having much luck. It seems like this should be easy, but I'm stumped. More generally, I would like to be able to apply a function f to each element in a matrix of arbitrary size and dimensions, without worrying about the particulars of the matrix representation via lists. I want func[M, g] to return a matrix of the same size and shape as M, with elements formed by applying g to corresponding elements of M. Is there nice way to do this? Seems like some combination of Map, Apply, Thread, SetAttributes Listable, Outer, etc. could do the job, but I am lost in the morass of possibilites. Any help would be appreciated. Thanks, -- David Cabana drc at gate.net "Ask the American public if they want an FBI Wiretap and they'll say 'no.' If you ask them do they want a feature on their phone that helps the FBI find their missing child they'll say, 'Yes.'" - FBI Directory Louis Freeh, on Digital Telephony, US House (Subcmte. on Telecommunications & Finance) hearing on the Digital Telephony bill, 09/13/94). "The people never give up their liberties but under some delusion" - Edmund Burke ==== [MESSAGE SEPARATOR] ====