From hinsen@ibs.ibs.fr Mon Sep 1 19:14:12 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Mon, 1 Sep 1997 20:14:12 +0200 Subject: [MATRIX-SIG] Weird bug In-Reply-To: <3408515D.F0EEE522@cnri.reston.va.us> (message from Jim Hugunin on Sat, 30 Aug 1997 12:59:09 -0400) Message-ID: <199709011814.UAA29165@lmspc1.ibs.fr> > Naive users are strongly discouraged from using the 3-argument numeric > functions and it is exactly this sort of behavior that is behind these > warnings. If you realize that 'a' and transpose(a) both point to the > same region of memory this "bug" makes perfect sense. In fact, there's > no alternative way of implementing things that would make this "bug" go > away without making 3-argument numeric functions use a temporary array > for storing their result, which would completely eliminate their > usefulness. Still there should never be a wrong resulr - either use a temporary array, or raise an exception. I guess the three-argument form could easily raise an error whenever the last argument shares data space with one of the other two arrays without actually being the same arraay; that should cover all critical cases. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From alawhead@vcn.bc.ca Mon Sep 1 23:41:06 1997 From: alawhead@vcn.bc.ca (Alexander Lawhead) Date: Mon, 1 Sep 1997 15:41:06 -0700 (PDT) Subject: [MATRIX-SIG] array(a) == array(a) Message-ID: I was wondering why testing the equivalence of NumPy arrays doesn't seem to function properly: >>> a = range(10) >>> a == a 1 >>> array(a) == array(a) 0 >>> array(a).tolist() == array(a).tolist() 1 Alexander _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hochberg@wwa.com Tue Sep 2 04:45:30 1997 From: hochberg@wwa.com (Timothy A. Hochberg) Date: Mon, 1 Sep 1997 22:45:30 -0500 (CDT) Subject: [MATRIX-SIG] array(a) == array(a) In-Reply-To: Message-ID: On Mon, 1 Sep 1997, Alexander Lawhead wrote: > I was wondering why testing the equivalence of NumPy arrays > doesn't seem to function properly: > > >>> a = range(10) > >>> a == a > 1 > >>> array(a) == array(a) > 0 > >>> array(a).tolist() == array(a).tolist() > 1 Testing equality using == (and <, <=, etc.) of arrays is busted on purpose. In order to be compatable with the other Numeric functions, these should return arrays where the arrays are compared element by element. The next best thing would be to raise an exception. The third best thing would be to make comparisons so horribly broken that people would notice quickly and not use them. Since options one and two are not possible for technical reasons, Jim H. elected to go with option three. And see, it worked ;) I believe in Python 1.5, it will be possible to raise an exception, so perhaps we can upgrade the situation somewhat. In the meantime, use Numeric.equal to compare element by element, and you've allready found a way to test for total equality (alltrue(equal(a,b).flat)) might be faster though.) ____ /im +------------------------------------------------+ |Tim Hochberg Research Assistant | |hochberg wwa.com University of Illinois | | Electrical Engineering | +------------------------------------------------+ _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From jhauser@ifm.uni-kiel.de Tue Sep 9 14:15:34 1997 From: jhauser@ifm.uni-kiel.de (Janko Hauser) Date: Tue, 9 Sep 1997 15:15:34 +0200 (CEST) Subject: [MATRIX-SIG] Type questions Message-ID: I have soem problems to hold the type of my arrays because of the coercion-rules with regard to simple float numbers. Example: >>> a array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) >>> b=a*1.2 # this changes to a double array because 1.2 is a double >>> b array([[ 0. , 1.2, 2.4], [ 3.6, 4.8, 6. ], [ 7.2, 8.4, 9.6]]) >>> b.typecode() 'd' >>> b=a*array([1.2],'f') # why is this a double? >>> b.typecode() 'd' >>> b=a.astype('f')*array([1.2],'f') >>> b.typecode() 'f' >>> I see no way to say python that a float is not double like the ``12L''. The simple way would be to have something like asarray(number) (code appended). But isn't it possible to do it directly in array? Or is there another way to hold the type of arrays? This can give memory-problems with huge fields if suddently all fields are coerced into double. __Janko ###################### myasarray.py def masarray(a,typecode=None): if typecode == None: if ((type(a) == type(1)) or (type(a) == type(1.2))): return array([a]) else: return array(a, copy=0) else: if ((type(a) == type(1)) or (type(a) == type(1.2))): return array([a],typecode) else: return array(a, typecode, copy=0) _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From jhauser@ifm.uni-kiel.de Tue Sep 9 16:28:50 1997 From: jhauser@ifm.uni-kiel.de (Janko Hauser) Date: Tue, 9 Sep 1997 17:28:50 +0200 (CEST) Subject: [MATRIX-SIG] Type questions In-Reply-To: <3415560C.6963@smhi.se> References: <3415560C.6963@smhi.se> Message-ID: Daniel Michelson writes: > Hej, > > A quick and dirty answer from a Python novice: > > >>> a = array([[0, 1, 2],[3, 4, 5],[6, 7, 8]]) > >>> (a*1.2).typecode() > 'd' > >>> array((a*1.2), 'f').typecode() > 'f' > > Does this help at all? > This is not really a solution, because now everything is coerced twice, internally there is a change to a double array. (If I understand the rules right, but this can be wrong) > BTW: Do you have anything to do with Lutz Hasse and his group? I've sent > them a pile of my radar data for the BALTEX PIDCAP period and they seem > to be doing good things with it... > Not at the moment, because I'm in oceanography, and the Hasse group is in the meteorological department. But who knows what will happen. But they don't work with Numpy yet (:-)). __Janko _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From Timothy A. Hochberg" Message-ID: On Tue, 9 Sep 1997, Janko Hauser wrote: > I have soem problems to hold the type of my arrays because of the > coercion-rules with regard to simple float numbers. I'm straining to remember why this is... Here's the info, way back in a musty corner of my head: It's not safe to cast arrays of type Int to type 'f'. To see this try: >>> array((sys.maxint,)) array([2147483647]) >>> array((sys.maxint,)).astype('f')[0] # Array printer breaks on big floats... 2147483648.0 >>> # OOOOPS! So Int arrays are always cast to type Float when doing multiplication, etc., which is suprising at first. The casting hiearchy looks something like: Int8(1)--------+->Int16(s)+->Int32(i/l)+ | | | UnsignedInt8(b)+ +->Float32(f)+->Float64(d)--+ | | +->Complex64(F)+->Complex128(D) ( Big parentetical comment: Hmmm. Int32->Complex64 is unsafe but is still allowed. That's probably a bug. And i/l might cause a problem on 64 bit machines as noted in PyArray_CanCastSafely.) The suffixes on Int and Float (8, 16, etc.) may vary depending on machine. ) > > Example: > >>> a > array([[0, 1, 2], > [3, 4, 5], > [6, 7, 8]]) > >>> b=a*1.2 # this changes to a double array because 1.2 is a double > >>> b > array([[ 0. , 1.2, 2.4], > [ 3.6, 4.8, 6. ], > [ 7.2, 8.4, 9.6]]) > >>> b.typecode() > 'd' > >>> b=a*array([1.2],'f') # why is this a double? > >>> b.typecode() > 'd' This is a double because the array a cannot be safely coerced to type 'f'. > >>> b=a.astype('f')*array([1.2],'f') > >>> b.typecode() > 'f' > >>> > > > I see no way to say python that a float is not double like the > ``12L''. The simple way would be to have something like > asarray(number) (code appended). But isn't it possible to do it > directly in array? The funcionality you're looking for is allready (sortof) in array. array(x, 'f', copy=0) works essentially the same as masarray(x,'f') does. (The shape of the array returned is different, but I think that's OK for what your doing.) One thing to consider is that Int16 ('s') can safely be converted to type 'f', so if you know your integers fit into a 16 bit integer, you can do something like. >>> b array([[0, 1, 2], [3, 4, 5], [6, 7, 8]],'s') >>> b*array(1.2, 'f') array([[ 0. , 1.20000005, 2.4000001 ], [ 3.60000014, 4.80000019, 6. ], [ 7.20000029, 8.40000057, 9.60000038]],'f') [SNIP] > ###################### myasarray.py > > def masarray(a,typecode=None): > if typecode == None: > if ((type(a) == type(1)) or (type(a) == type(1.2))): > return array([a]) > else: > return array(a, copy=0) > else: > if ((type(a) == type(1)) or (type(a) == type(1.2))): > return array([a],typecode) > else: > return array(a, typecode, copy=0) ____ /im +------------------------------------------------+ |Tim Hochberg Research Assistant | |hochberg wwa.com University of Illinois | | Electrical Engineering | +------------------------------------------------+ _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From da@maigret.cog.brown.edu Tue Sep 9 18:11:21 1997 From: da@maigret.cog.brown.edu (David Ascher) Date: Tue, 9 Sep 1997 13:11:21 -0400 (EDT) Subject: [MATRIX-SIG] Re: [META-SIG] plot-sig (fwd) Message-ID: If you're interested in the PLOT-SIG creation, please post a mesage to that effect on meta-sig@python.org. Then we can officially create that SIG. I don't expect much to happen on it until after the SPAM-6, but it'd be nice if it were in place by then. It would help if folks could state in those messages that they would actively participate in such a SIG (i.e. if not code, then at least critique, suggest, harangue, debate, argue). --david _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From jhauser@ifm.uni-kiel.de Tue Sep 9 18:20:46 1997 From: jhauser@ifm.uni-kiel.de (Janko Hauser) Date: Tue, 9 Sep 1997 19:20:46 +0200 (CEST) Subject: [MATRIX-SIG] Type questions In-Reply-To: References: Message-ID: Oh, that's my mistake If I try interactive >>> array(12,'f') 12.0 I thought 12.0 was a number, but it's really an array, so than there is no need for myasarray. Thanks. __Janko _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From arne@nad.ppm.u-psud.fr Wed Sep 10 10:29:10 1997 From: arne@nad.ppm.u-psud.fr (Arne Keller) Date: Wed, 10 Sep 1997 11:29:10 +0200 Subject: [MATRIX-SIG] spline Message-ID: <34166866.2781@nad.ppm.u-psud.fr> I would like to make spline approximation to sampled signals. Do you know if someone has built a python module doing this type of thing? -- Arne Keller Laboratoire de Photophysique Moleculaire du CNRS. Universite de Paris-Sud, 91405 Orsay Cedex, France. tel.: (33) 1 69 15 82 83 -- fax. : (33) 1 69 15 67 77 _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From Dirk.Engelmann@iwr.uni-heidelberg.de Wed Sep 10 15:45:21 1997 From: Dirk.Engelmann@iwr.uni-heidelberg.de (Dirk Engelmann) Date: Wed, 10 Sep 1997 16:45:21 +0200 (MET DST) Subject: [MATRIX-SIG] float -> integer with array? Message-ID: Hi! Is there a way to convert a float array to an integer ? (In my case, I just have zeros behind decimal point). Thanks for help /Cheers, Dirk Engelmann _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From da@maigret.cog.brown.edu Wed Sep 10 16:10:37 1997 From: da@maigret.cog.brown.edu (David Ascher) Date: Wed, 10 Sep 1997 11:10:37 -0400 (EDT) Subject: [MATRIX-SIG] float -> integer with array? In-Reply-To: Message-ID: > Is there a way to convert a float array to > an integer ? > (In my case, I just have zeros behind decimal point). >>> x = arange(5, typecode='f') >>> print x [ 0. 1. 2. 3. 4.] >>> y = a.astype('i') >>> print y [0 1 2 3 4] >>> print y.typecode() i _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hochberg@wwa.com Wed Sep 10 16:37:23 1997 From: hochberg@wwa.com (Timothy A. Hochberg) Date: Wed, 10 Sep 1997 10:37:23 -0500 (CDT) Subject: [MATRIX-SIG] float -> integer with array? In-Reply-To: Message-ID: On Wed, 10 Sep 1997, Dirk Engelmann wrote: > Hi! > > Is there a way to convert a float array to > an integer ? > (In my case, I just have zeros behind decimal point). Use the method astype(Int). For example: >>> a array([ 1.]) >>> b = a.astype(Int) >>> b array([1]) ____ /im +------------------------------------------------+ |Tim Hochberg Research Assistant | |hochberg wwa.com University of Illinois | | Electrical Engineering | +------------------------------------------------+ _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From johann@physics.berkeley.edu Wed Sep 10 18:40:58 1997 From: johann@physics.berkeley.edu (Johann Hibschman) Date: Wed, 10 Sep 1997 10:40:58 -0700 (PDT) Subject: [MATRIX-SIG] spline In-Reply-To: <34166866.2781@nad.ppm.u-psud.fr> Message-ID: On Wed, 10 Sep 1997, Arne Keller wrote: > I would like to make spline approximation to sampled signals. Do you > know if someone has built a python module doing this type of thing? It depends on what exactly you need. I've written a Python spline module which will take two arrays, one of x points and one of y points, and return a basic cubic spline approximation. The creation of the approximation is not that fast, since it's in Python, but calling that approximation is reasonably efficient, since it uses the "searchsorted" routine on the arrays. Unfortunately, the code is currently derived from Numerical Recipes in C, so I'm not certain about its distributability. Does this sound like what you're looking for? If so, I could email you the code. - Johann --- Johann A. Hibschman | Grad student in Physics, working in Astronomy. johann@physics.berkeley.edu | Probing pulsar pair production processes. _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From krodgers@tdyryan.com Thu Sep 11 16:02:23 1997 From: krodgers@tdyryan.com (Kevin Rodgers) Date: Thu, 11 Sep 1997 08:02:23 -0700 Subject: [MATRIX-SIG] spline In-Reply-To: References: <34166866.2781@nad.ppm.u-psud.fr> Message-ID: <3.0.1.32.19970911080223.00523e80@gate.tdyryan.com> At 10:40 AM 9/10/97 -0700, Johann Hibschman wrote: >Unfortunately, the code is currently derived from Numerical Recipes in C, >so I'm not certain about its distributability. If you're using code derived from Numerical Recipes in whatever, you should be worried about more than its distributability. See http://math.jpl.nasa.gov/nr/ for an informed discussion of both the algorithms and implementation of Numerical Recipies. If you want splines, you might check Netlib for some C or Fortran implementations, then either re-implement in Python or wrap the Netlib library. But be VERY careful with anything having to do with Numerical Recipies! ---------------------------------------------------------------------- Kevin Rodgers Teledyne Ryan Aeronautical krodgers@tdyryan.com "This one goes up to eleven." -- Nigel Tufnel ---------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From johann@physics.berkeley.edu Thu Sep 11 22:12:43 1997 From: johann@physics.berkeley.edu (Johann Hibschman) Date: Thu, 11 Sep 1997 14:12:43 -0700 (PDT) Subject: [MATRIX-SIG] Making pseudo-ufuncs? Message-ID: Hi all, I've been trying to write a class that wraps a normal unary or binary function to allow it to be simply (if slowly) applied to arrays. Hopefully, it would increase the readibility of some code. First, is there a better way to do this? Second, is the method I use to detect the types of the arrays a good idea? It would seem to fall apart for special Matrix and Vector classes. Third, is there a good way to implement outer, accumulate, and reduce for binary functions? So far, I have (FuncOps is my function operations class): class FuncBinder(FuncOps): def __init__(self, a_f): if ((type(a_f) == UfuncType) or (type(a_f) == InstanceType and FuncOps in a_f.__class__.__bases__)): self.__call__ = a_f # overwrite the existing method self.f = a_f def __call__(self, arg): "Default call routine, used for ordinary functions." if type(arg) == ArrayType: return array_map(self.f, arg) else: return self.f(arg) where def array_map(f, ar): "Apply an ordinary function to all values in an array." flat_ar = ravel(ar) out = zeros(len(flat_ar), typecode=flat_ar.typecode()) for i in xrange(len(flat_ar)): out[i] = f(flat_ar[i]) out.shape = ar.shape return out for unary functions, and (for binary functions), I've defined methods: def reduce(self, a, axis=0): result = take(a, [0], axis) for i in range(1, a.shape[axis]): result = self(result, take(a, [i], axis)) return result def accumulate(self, a, axis=0): n = len(a.shape) sum = take(a, [0], axis) out = zeros(a.shape, a.typecode()) for i in range(1, a.shape[axis]): out[all_but_axis(i, axis, n)] = self(sum, take(a, [i], axis)) return out def all_but_axis(i, axis, num_axes): """ Return a slice covering all combinations with coordinate i along axis. (Effectively the hyperplane perpendicular to axis at i.) """ the_slice = () for j in range(num_axes): if j == axis: the_slice = the_slice + (i,) else: the_slice = the_slice + (slice(None),) return the_slice def outer(op, a, b): n_a = len(a.shape) n_b = len(b.shape) a2 = reshape(a, a.shape + (1,)*n_b) b2 = reshape(b, (1,)*n_a + b.shape) # duplicate each array in the appropriate directions a3 = a2 for i in range(n_b): a3 = repeat(a3, (b.shape[i],), n_a+i) b3 = b2 for i in range(n_a): b3 = repeat(b3, (a.shape[i],), i) answer = array_map_2(op, a3, b3) return answer These all seem over-complex to me. Is there are more straightforward way to do this? --- Johann A. Hibschman | Grad student in Physics, working in Astronomy. johann@physics.berkeley.edu | Probing pulsar pair production processes. _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Fri Sep 12 11:08:52 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Fri, 12 Sep 1997 12:08:52 +0200 Subject: [MATRIX-SIG] Making pseudo-ufuncs? In-Reply-To: (message from Johann Hibschman on Thu, 11 Sep 1997 14:12:43 -0700 (PDT)) Message-ID: <199709121008.MAA04620@lmspc1.ibs.fr> > First, is there a better way to do this? Nothing I can think of. > Second, is the method I use to detect the types of the arrays a good idea? > It would seem to fall apart for special Matrix and Vector classes. You could try to check for general sequence objects, and then your functions would even work in lists. But the tricky part is getting a return value in the same object type. I am not sure this is worth the effort. > Third, is there a good way to implement outer, accumulate, and reduce for > binary functions? I'd define another class for binary functions and assign the reduce/accumulate/outer version to an appropriate attribute. Then you could use the same syntax as with ufuncs. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From da@maigret.cog.brown.edu Wed Sep 17 02:32:16 1997 From: da@maigret.cog.brown.edu (David Ascher) Date: Tue, 16 Sep 1997 21:32:16 -0400 (EDT) Subject: [MATRIX-SIG] ANNOUNCE: PLOT-SIG has been created Message-ID: Thanks to Barry Warsaw and Ken Manheimer, the PLOT-SIG has been created (it even has a web page, with little information on it for now). I am the maintainer of the SIG. The informational message describing the SIG's purpose is appended to this post. Send subscription messages to plot-sig-request@python.org I would suggest that folks save their 'contentful' messages until a fair number of people have had a chance to subscribe. When you do subscribe, feel free to check the archive at http://www.python.org/sigs/plot-sig/archive to see if you've missed anything (I'm guessing the findmail.com archive will take a little while to start up). --david ascher -- plotting to take over the world of plots. <-----------------------------------------------------------------------> PLOT-SIG, a Special Interest Group on Data Plotting Solutions for Python The purpose of this list is to develop, coddle together, adopt or otherwise make available Python tools for plotting of scientific and business plots of data. Plotting needs vary greatly depending on each user's requirements; some users wish to see a better API between Python and existing plotting libraries or programs. Others would rather see a new framework which maximally leverages the OOP and dynamic strengths of Python, at the cost of reinventing a few wheels. Both strategies will be entertained by the SIG, with individual members contributing to projects they wish to see furthered. Principles guiding the development of all software will include: * Ease of use. * Integration with other Python packages (NumPy, PIL, etc.). * Quality of the software. * Quality of the output. One possible goal for the API project is to develop a package- independent API for plots, which would produce reasonably similar results regardless of the plotting package used as a backend (PLPlot, Gist/Yorick, Gnuplot, etc.), in the same spirit as the interface defined by the DB-SIG. Package-specific extensions could naturally be provided as well. The goals for the new framework need to be further specified by the SIG, but include: * Complete Python Control. * Extensibility/Customizability. * High quality rendering both on screen and paper. * Portability (at least UNIX/X11 and Win32, MacOS if feasible). * Stealing good ideas others have had. * Interactivity Membership is expected to include folks who wish to contribute to the development efforts, folks who have lots of expertise they wish to share, and novice users who wish to share their lists of requirements, questions about the available software, etc. About this list: Additions and deletions are all automated via Majordomo. For details, send the word `help' in the body of a mail message to the Administrivia address given below. The subscription policy is `open', meaning you can add or delete yourself at any time, but you cannot add or delete anyone else without approval. This list is unmoderated and unrestricted. This means that anybody can post messages to the list. Messages are archived and available for download, as are perhaps other useful files. For details, send the word `index' in the body of a message to the Administrivia address. Post messages to the everyone on the list by using the List address. If you absolutely must to contact a human being, use the Owner address. ========================================== List address: plot-sig@python.org Administrivia: plot-sig-request@python.org Owner: plot-sig-owner@python.org ========================================== _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From jim.fulton@digicool.com Wed Sep 17 18:33:22 1997 From: jim.fulton@digicool.com (Jim Fulton) Date: Wed, 17 Sep 1997 13:33:22 -0400 Subject: [MATRIX-SIG] Much ado about nothingness. References: <199707091401.KAA06541@ptq3.etsd> <9707091815.AA18826@ch1d162nwk> Message-ID: <34201462.38EE@digicool.com> Ted Horst wrote: > > Has anybody looked at the Missing type from DigiCool ? (Actually, Digital Creations, aka DC :) > It has the desired > behavior for arithmetic operations, but doesn't work correctly for math or > umath functions. I have no idea how hard this would be to get working, This would be easy. I'm been meaning too....so little time. :-( I'd be happy to do this if needed. > or even > if this is the proper approach, Good question. There is the sticky issue that you can't actually store one of these things in a numeric array. You would have to pick a "special" numeric value and map to and from it on input and output. I think this is a good thing to do, but others disagree with me. > but somebody else is at least looking at the > problem. You can get it from http://www.digicool.com/releases/ExtensionClass/. I also think it would be a good thing for the Numeric types to be extension classes, so that they could be subclassed in Python. Jim _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From dek@cgl.ucsf.edu Wed Sep 17 21:24:26 1997 From: dek@cgl.ucsf.edu (David Konerding) Date: Wed, 17 Sep 97 13:24:26 -0700 Subject: [MATRIX-SIG] problem with Statistics module Message-ID: <199709172024.NAA22061@socrates.ucsf.EDU> Dear Konrad, I have uncovered a small problem with using your Statistics module: when using it on arrays of type Object ('O'), standardDeviation will segfault. I am using Python-1.4 with the latest version of NumPy. The following program exhibits the error. import sys from Numeric import * from Statistics import * a = [ [ 1., 2., 3. ], [ 4., 5., 6. ], [ 7., 8., None ], ] b = array(a) print b.typecode() c = array(b[0]) print c.typecode() print average(c) print standardDeviation(c) (I use Nones in my arrays to represent a time in which no observation was made) If the Python list doesn't contain the 'None', the array b will be created as type Float, but since it has the None, it's created as type Object. When I extract a row from the matrix into a new array, called c, it is created as type O, even though it only contains floats. Calling standardDeviation on an array of type Object causes the segfault. The segfault appears to happen in sqrt() since apparently segfault isn't defined on the Object type: a = [ 1., 2., 3. ] b = array(a) print sqrt(b) c = array(a, 'O') print c print sqrt(c) ## line 34 gives: [ 1. 1.41421356 1.73205081] [1.0 2.0 3.0 ] Traceback (innermost last): File "", line 34, in ? AttributeError: attribute-less object I expect the best thing I can do here is cast the array explicitly as type 'd' when I extract a row. But I'd prefer that NumPy didn't segfault. Dave ----------------------------------------------------------------------------- Email: dek@cgl.ucsf.edu David Konerding WWW: http://picasso.ucsf.edu/~dek ----------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From jim.fulton@digicool.com Thu Sep 18 00:13:10 1997 From: jim.fulton@digicool.com (Jim Fulton) Date: Wed, 17 Sep 1997 19:13:10 -0400 Subject: [MATRIX-SIG] Much ado about nothingness. References: <199707091401.KAA06541@ptq3.etsd> <9707091815.AA18826@ch1d162nwk> <34201462.38EE@digicool.com> Message-ID: <34206406.F93@digicool.com> Jim Fulton wrote: > > Ted Horst wrote: > > > > Has anybody looked at the Missing type from DigiCool ? > > (Actually, Digital Creations, aka DC :) > > > It has the desired > > behavior for arithmetic operations, but doesn't work correctly for math or > > umath functions. I have no idea how hard this would be to get working, > > This would be easy. I'm been meaning too....so little time. :-( > > I'd be happy to do this if needed. OK, I went ahead and fixed this. I also fixed an awful reference counting bug and make missing values picklable. The new version may be found at: www.digicool.com/releases/ExtensionClass/ExtensionClass-1.0.1.tar.gz Jim _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Thu Sep 18 09:41:48 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Thu, 18 Sep 1997 10:41:48 +0200 Subject: [MATRIX-SIG] Re: problem with Statistics module In-Reply-To: <199709172024.NAA22061@socrates.ucsf.EDU> (message from David Konerding on Wed, 17 Sep 97 13:24:26 -0700) Message-ID: <199709180841.KAA00545@lmspc1.ibs.fr> > I have uncovered a small problem with using your > Statistics module: when using it on arrays of > type Object ('O'), standardDeviation will segfault. For me too, but I can't do anything about that in Statistics. > as type Object. When I extract a row from the matrix into a new > array, called c, it is created as type O, even though it only contains > floats. Calling standardDeviation on an array of type Object causes the > segfault. It is intended that a subarray always has the same type as the original array. But of course object arrays shouldn't cause a segment fault. > I expect the best thing I can do here is cast the array > explicitly as type 'd' when I extract a row. But I'd prefer that That's probably the best workaround. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Thu Sep 18 11:07:00 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Thu, 18 Sep 1997 12:07:00 +0200 Subject: [MATRIX-SIG] Much ado about nothingness. In-Reply-To: <34201462.38EE@digicool.com> (message from Jim Fulton on Wed, 17 Sep 1997 13:33:22 -0400) Message-ID: <199709181007.MAA00754@lmspc1.ibs.fr> > I also think it would be a good thing for the Numeric types to be > extension classes, so that they could be subclassed in Python. That sounds like a good proposal - but it means that people have to install yet another package, and users are already complaining about the complicated NumPy installation. Maybe that will change with Python 1.5. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From da@maigret.cog.brown.edu Thu Sep 18 20:16:54 1997 From: da@maigret.cog.brown.edu (David Ascher) Date: Thu, 18 Sep 1997 15:16:54 -0400 (EDT) Subject: [MATRIX-SIG] max and min? Message-ID: max and min seem to work strangely in my current setup (1.5a3, latest Numeric, gnuwin32): >>> b array([[0, 2], [4, 6], [8, 1], [3, 5], [7, 9]]) >>> min(b) array([7, 9]) >>> max(b) array([0, 2]) _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From da@maigret.cog.brown.edu Thu Sep 18 20:29:16 1997 From: da@maigret.cog.brown.edu (David Ascher) Date: Thu, 18 Sep 1997 15:29:16 -0400 (EDT) Subject: [MATRIX-SIG] max and min? In-Reply-To: Message-ID: > max and min seem to work strangely in my current setup (1.5a3, latest > Numeric, gnuwin32): As usual, the problem is with comparisons being broken, right?. The safe way is to use umath.maximum.reduce(). I suggest that the MLab file be modified to use those forms... It currently mentions min and max. --david _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From arw@dante.mh.lucent.com Fri Sep 19 19:51:05 1997 From: arw@dante.mh.lucent.com (Aaron Watters) Date: Fri, 19 Sep 1997 14:51:05 -0400 Subject: [MATRIX-SIG] max and min? Message-ID: <199709191846.OAA23191@dante.mh.lucent.com> I wish comparisons would get unbroken. I think Guido's convention is reasonable (but not the only possibility -- but he had to pick one). Ignore me as I'm really just a lurker here (so far). -- Aaron Watters ---------- > From: David Ascher > To: matrix-sig@python.org > Subject: Re: [MATRIX-SIG] max and min? > Date: Thursday, September 18, 1997 3:29 PM > > > > max and min seem to work strangely in my current setup (1.5a3, latest > > Numeric, gnuwin32): > > As usual, the problem is with comparisons being broken, right?. The > safe way is to use umath.maximum.reduce(). > > I suggest that the MLab file be modified to use those forms... It > currently mentions min and max. > > --david > > > _______________ > MATRIX-SIG - SIG on Matrix Math for Python > > send messages to: matrix-sig@python.org > administrivia to: matrix-sig-request@python.org > _______________ > _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From pao@Goldilocks.LCS.MIT.EDU Tue Sep 23 21:52:20 1997 From: pao@Goldilocks.LCS.MIT.EDU (Christine Pao) Date: Tue, 23 Sep 1997 16:52:20 -0400 Subject: [MATRIX-SIG] array objects and if? Message-ID: <199709232052.QAA12903@sugar-bear.lcs.mit.edu> I've just run into a problem using if: >>> if Numeric.array([]): ... print 1 ... else: ... print 0 ... 0 This is what I would expect, but >>> if Numeric.array([0]): ... print 1 ... else: ... print 0 ... 0 and >>> if Numeric.zeros((3,3)): ... print 1 ... else: ... print 0 ... 0 isn't the way other sequences behave. I don't know if this has come up before. Is this what is supposed to happen? Thanks, Christine Pao _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Mon Sep 22 17:28:40 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Mon, 22 Sep 1997 18:28:40 +0200 Subject: [MATRIX-SIG] Re: [PLOT-SIG] Welcome In-Reply-To: <3.0.1.32.19970919125248.005267e0@gate.tdyryan.com> (message from Kevin Rodgers on Fri, 19 Sep 1997 12:52:48 -0700) Message-ID: <199709221628.SAA17744@lmspc1.ibs.fr> > (1) Tightly integrated with NumPy. I would even suggest that the basic > units of data storage be NumPy arrays. That would be an unnecessary restriction. NumPy itself will almost always accept nested sequence objects instead of arrays, so a plotting library should be no less tolerant. > (2) Easy file i/o: ascii space/comma/tab delimited with user-defined > comment characters, netCDF, HDF, raw binary built in; easy hooks for > user-written arbitrary file formats (this whole subject is a big sore spot > in NumPy too!). That's really a separate subject, and I agree on its importance. But it's also a messy subject due to the immense number of file formats that are in use. For those who don't know yet, I have a netCDF interface with tight NumPy integration, which is available from http://starship.skyport.net/crew/hinsen/netcdf.html Other standard formats could (and should, in my opinion) be implemented in a similar way. A bigger problem is providing support functions to facilitate handling non-standard formats. Anyway, this is off-topic here, so I'll CC to the Matrix-SIG, which is a more appropriate place. > (4) Easy way to associate descriptive strings with array elements/axes; > especially important for netCDF/HDF data. Such strings should be by > default automatically used as axis/legend notations. That's really a topic on the borderline between NumPy and plotting. What we need is an "annotated array" object. The difficult part is to decide what happens to all the extra information during NumPy operations. > (9) As WYSIWYG as possible. This will be tough, since we can't be better than the OS support we have... > (12) Good documentation of the GUI, the command line language, and the > Python and C APIs. Command line language and Python API are the same! And I doubt that we really need a separate C API. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Wed Sep 24 09:46:07 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Wed, 24 Sep 1997 10:46:07 +0200 Subject: [MATRIX-SIG] array objects and if? In-Reply-To: <199709232052.QAA12903@sugar-bear.lcs.mit.edu> (message from Christine Pao on Tue, 23 Sep 1997 16:52:20 -0400) Message-ID: <199709240846.KAA24275@lmspc1.ibs.fr> > This is what I would expect, but > > >>> if Numeric.array([0]): > ... print 1 > ... else: > ... print 0 > ... > 0 ... > isn't the way other sequences behave. Right, but then other sequences can't be multidimensional. I don't know whether this is supposed to happen, but I do know that I prefer to test explicitly for what I want (zero size, zero length along any specific axis, specific shape, etc.). -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From pao@goldilocks.lcs.mit.edu Wed Sep 24 15:56:09 1997 From: pao@goldilocks.lcs.mit.edu (Christine Pao) Date: Wed, 24 Sep 1997 10:56:09 -0400 Subject: [MATRIX-SIG] array objects and if? In-Reply-To: Your message of "Wed, 24 Sep 1997 10:46:07 +0200." <199709240846.KAA24275@lmspc1.ibs.fr> Message-ID: <199709241456.KAA07687@sugar-bear.lcs.mit.edu> > Right, but then other sequences can't be multidimensional. I don't know > whether this is supposed to happen, but I do know that I prefer to test > explicitly for what I want (zero size, zero length along any specific > axis, specific shape, etc.). I guess my question was whether the array object is intended to be a sequence or a scalar. It looks like in the case of the "if" test it is considered a scalar (nonzero array vs. array of zero length). Clearly you can't have it both ways and it is easy enough to explicitly test for zero length. Thanks. Christine Pao Spoken Language Systems Group MIT Laboratory for Computer Science _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________