RE: [Numpy-discussion] still no cross product for new array type
Usually this is within the scope of higher level packages such as ScientificPython. Nadav -----Original Message----- From: numpy-discussion-admin@lists.sourceforge.net on behalf of Gary Ruben Sent: Fri 12-Aug-05 14:44 To: numpy-discussion@lists.sourceforge.net Cc: Subject: [Numpy-discussion] still no cross product for new array type Just browsing through the new array PEP to see if there's support for 3-vector operations, such as cross product, norm, length functions. Sadly I don't see any. It's something I think is lacking from Numeric and numarray and would like to see implemented. Is it a deliberate choice not to include any? I understand that vectors are sufficiently different animals that you could argue that they shouldn't be supported. I use them enough to think that they should be. Gary Ruben ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
"Usually" means that that's where they are now, because they haven't been implemented in numpy. Comparing with Matlab/IDL where their status is slightly greater so as to earn operations of their own, I wonder why equivalent status isn't afforded them in numpy. Gary R. Nadav Horesh wrote:
Usually this is within the scope of higher level packages such as ScientificPython.
Nadav
-----Original Message----- From: numpy-discussion-admin@lists.sourceforge.net on behalf of Gary Ruben Sent: Fri 12-Aug-05 14:44 To: numpy-discussion@lists.sourceforge.net Cc: Subject: [Numpy-discussion] still no cross product for new array type Just browsing through the new array PEP to see if there's support for 3-vector operations, such as cross product, norm, length functions. Sadly I don't see any. It's something I think is lacking from Numeric and numarray and would like to see implemented. Is it a deliberate choice not to include any? I understand that vectors are sufficiently different animals that you could argue that they shouldn't be supported. I use them enough to think that they should be.
Gary Ruben
Gary Ruben wrote:
"Usually" means that that's where they are now, because they haven't been implemented in numpy. Comparing with Matlab/IDL where their status is slightly greater so as to earn operations of their own, I wonder why equivalent status isn't afforded them in numpy.
Because numpy is NOT matlab or IDL, nor is it trying to be a close of either of them. I've never used IDL, but MATLAB is (or at least was) a MATrix LABoratory. It was conceived, from the beginning, to be a tool to do linear algebra computations. The new array type has nothing to do with linear algebra, nor does Numeric or numarray. they are general purpose array packages. As it happens, a handy way to store matrices is in a 2-d array, so it's natural to build a linear algebra (and vector arithmetic) package on top of NumPy arrays, but it should be higher level package. One of the things I like most about NumPY, as opposed to MATLAB, is that it doesn't assume everything is a matrix! If we could ever get Python to include additional operators, we could have a Numeric array package and linear algebra package all in one.. both with nice notation, that would be nice. In the meantime, check out cvxopt: http://www.ee.ucla.edu/~vandenbe/cvxopt/ If you want a matrix package. The author is talking about using the new array specification in future versions. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
On Mon, 15 Aug 2005, Chris Barker apparently wrote:
The new array type has nothing to do with linear algebra, nor does Numeric or numarray.
"Nothing" seems a bit strong.
If we could ever get Python to include additional operators, we could have a Numeric array package and linear algebra package all in one. both with nice notation, that would be nice.
Yep.
In the meantime, check out cvxopt: http://www.ee.ucla.edu/~vandenbe/cvxopt/ If you want a matrix package. The author is talking about using the new array specification in future versions.
There is also http://www3.sympatico.ca/cjw/PyMatrix/ (I'm not using either at the moment so I cannot compare them.) Cheers, Alan Isaac
On Aug 15, 2005, at 4:18 PM, Alan G Isaac wrote:
On Mon, 15 Aug 2005, Chris Barker apparently wrote:
If we could ever get Python to include additional operators, we could have a Numeric array package and linear algebra package all in one. both with nice notation, that would be nice.
Yep.
I wonder if we shouldn't use the operator hack recently added to the cookbook to give some sort of capability for this. It doesn't support precedence that people would like, but it maybe useful enough. What do people think? http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 Perry
Perry Greenfield wrote:
On Aug 15, 2005, at 4:18 PM, Alan G Isaac wrote:
On Mon, 15 Aug 2005, Chris Barker apparently wrote:
If we could ever get Python to include additional operators, we could have a Numeric array package and linear algebra package all in one. both with nice notation, that would be nice.
Yep.
I wonder if we shouldn't use the operator hack recently added to the cookbook to give some sort of capability for this. It doesn't support precedence that people would like, but it maybe useful enough. What do people think?
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122
If it's placed in a separate module with other such pseudo-operators (|dot|, |land|, |lor|) rather than in Numeric.py itself, I'm +1 on this. It's such a beautiful hack. -- Robert Kern rkern@ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter
Nadav Horesh wrote:
Gary Ruben <gruben@bigpond.net.au>:
Just browsing through the new array PEP to see if there's support for 3-vector operations, such as cross product, norm, length functions. Sadly I don't see any.
Usually this is within the scope of higher level packages such as ScientificPython.
I'd like to see at least cross product included somewhere, since it's difficult to synthesize efficiently from the other operations provided. -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg.ewing@canterbury.ac.nz +--------------------------------------+
Greg Ewing <greg.ewing@canterbury.ac.nz> writes:
Nadav Horesh wrote:
Gary Ruben <gruben@bigpond.net.au>:
Just browsing through the new array PEP to see if there's support for > 3-vector operations, such as cross product, norm, length functions. Sadly I don't see any.
Usually this is within the scope of higher level packages such as ScientificPython.
I'd like to see at least cross product included somewhere, since it's difficult to synthesize efficiently from the other operations provided.
I agree. I've added a cross_product() funtion to Numeric in CVS. It'll do the cross product along any axes of the arrays passed, assuming that they're of dimensions 2 or 3 (a 2d cross-product returns the z-component of the equivalent 3d one). The test cases look like this: a = Numeric.array([1,2,3]) b = Numeric.array([4,5,6]) assert_eq(Numeric.cross_product(a,b), [-3, 6, -3]) a = Numeric.array([1,2]) b = Numeric.array([4,5]) assert_eq(Numeric.cross_product(a,b), -3) a = Numeric.array([[1,2,3], [4,5,6]]) b = Numeric.array([7, 8, 9]) assert_eq(Numeric.cross_product(a,b), [[-6,12,-6],[-3,6,-3]]) a = Numeric.array([[1,2,3], [4,5,6]]) b = Numeric.array([[10,11,12], [7,8,9]]) assert_eq(Numeric.cross_product(a,b,axis1=0,axis2=0), [-33,-39,-45]) assert_eq(Numeric.cross_product(a,b), [[-9,18,-9], [-3,6,-3]]) and the calling sequence like this: def cross_product(a, b, axis1=-1, axis2=-1): """Return the cross product of two vectors. The cross product is performed over the last axes of a and b by default, and can handle axes with dimensions 2 and 3. For a dimension of 2, the z-component of the equivalent three-dimensional cross product is returned. """ Someone else can make the infix-operator module :-) -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/ |cookedm@physics.mcmaster.ca
participants (8)
-
Alan G Isaac -
Chris Barker -
cookedm@physics.mcmaster.ca -
Gary Ruben -
Greg Ewing -
Nadav Horesh -
Perry Greenfield -
Robert Kern