You can subscribe to this list here.
2000 |
Jan
(8) |
Feb
(49) |
Mar
(48) |
Apr
(28) |
May
(37) |
Jun
(28) |
Jul
(16) |
Aug
(16) |
Sep
(44) |
Oct
(61) |
Nov
(31) |
Dec
(24) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(56) |
Feb
(54) |
Mar
(41) |
Apr
(71) |
May
(48) |
Jun
(32) |
Jul
(53) |
Aug
(91) |
Sep
(56) |
Oct
(33) |
Nov
(81) |
Dec
(54) |
2002 |
Jan
(72) |
Feb
(37) |
Mar
(126) |
Apr
(62) |
May
(34) |
Jun
(124) |
Jul
(36) |
Aug
(34) |
Sep
(60) |
Oct
(37) |
Nov
(23) |
Dec
(104) |
2003 |
Jan
(110) |
Feb
(73) |
Mar
(42) |
Apr
(8) |
May
(76) |
Jun
(14) |
Jul
(52) |
Aug
(26) |
Sep
(108) |
Oct
(82) |
Nov
(89) |
Dec
(94) |
2004 |
Jan
(117) |
Feb
(86) |
Mar
(75) |
Apr
(55) |
May
(75) |
Jun
(160) |
Jul
(152) |
Aug
(86) |
Sep
(75) |
Oct
(134) |
Nov
(62) |
Dec
(60) |
2005 |
Jan
(187) |
Feb
(318) |
Mar
(296) |
Apr
(205) |
May
(84) |
Jun
(63) |
Jul
(122) |
Aug
(59) |
Sep
(66) |
Oct
(148) |
Nov
(120) |
Dec
(70) |
2006 |
Jan
(460) |
Feb
(683) |
Mar
(589) |
Apr
(559) |
May
(445) |
Jun
(712) |
Jul
(815) |
Aug
(663) |
Sep
(559) |
Oct
(930) |
Nov
(373) |
Dec
|
From: Pau G. <pau...@gm...> - 2006-06-21 17:09:54
|
On 6/21/06, Travis Oliphant <oli...@ie...> wrote: > Johannes Loehnert wrote: > > Hi, > > > > > >> I'm not sure why bool arrays cannot be used as indices. > >> The "natural" solution to the original problem seemed to be: > >> M[:,V>0] > >> but this is not allowed. > >> > > > > I started a thread on this earlier this year. Try searching the archive for > > "boolean indexing" (if it comes back online somewhen). > > > > Travis had some reason for not implementing this, but unfortunately I do not > > remember what it was. The corresponding message might still linger on my home > > > > PC, which I can access this evening.... > > > > I suspect my reason was just not being sure if it could be explained > consistently. But, after seeing this come up again. I decided it was > easy enough to implement. > > So, in SVN NumPy, you will be able to do > > a[:,V>0] > a[V>0,:] > > The V>0 will be replaced with integer arrays as if nonzero(V>0) had been > called. > does it work for a[<boolean>,<boolean>] ? what about a[ix_( nonzero(<boolean>), nonzero(<boolean>) )] ? maybe the <boolean> to nonzero(<boolean>) conversion would be more coherently done by the ix_ function than by the [] pau |
From: Travis O. <oli...@ie...> - 2006-06-21 16:50:34
|
Johannes Loehnert wrote: > Hi, > > >> I'm not sure why bool arrays cannot be used as indices. >> The "natural" solution to the original problem seemed to be: >> M[:,V>0] >> but this is not allowed. >> > > I started a thread on this earlier this year. Try searching the archive for > "boolean indexing" (if it comes back online somewhen). > > Travis had some reason for not implementing this, but unfortunately I do not > remember what it was. The corresponding message might still linger on my home > > PC, which I can access this evening.... > I suspect my reason was just not being sure if it could be explained consistently. But, after seeing this come up again. I decided it was easy enough to implement. So, in SVN NumPy, you will be able to do a[:,V>0] a[V>0,:] The V>0 will be replaced with integer arrays as if nonzero(V>0) had been called. -Travis |
From: Craig L. <cl...@as...> - 2006-06-21 16:41:30
|
Not sure if this one has been addressed. There appears to be a problem with cumsum(dtype=), with reasonably small numbers. Both PPC and x86 Macs. ======== import numpy print "numpy version:", numpy.__version__ v = numpy.arange(10002) # 10001 is OK, larger is "worse" print "ok: ", v.cumsum() print "not ok: ", v.cumsum(dtype=numpy.float64) print "ok: ", numpy.arange(10002,dtype=numpy.float64).cumsum() ========= ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on Python 2.4.3 (#1, Apr 3 2006, 18:07:14) [GCC 4.0.1 (Apple Computer, Inc. build 5247)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> print "numpy version:", numpy.__version__ numpy version: 0.9.9.2549 >>> v = numpy.arange(10002) # 10001 is OK, larger is "worse" >>> print "ok: ", v.cumsum() ok: [ 0 1 3 ..., 49995000 50005000 50015001] >>> print "not ok: ", v.cumsum(dtype=numpy.float64) not ok: [ 0.00000000e+00 1.00010000e+04 3.00000000e+00 ..., 4.99950000e+07 5.00050000e+07 0.00000000e+00] >>> print "ok: ", numpy.arange(10002,dtype=numpy.float64).cumsum() ok: [ 0.00000000e+00 1.00000000e+00 3.00000000e+00 ..., 4.99950000e+07 5.00050000e+07 5.00150010e+07] >>> - craig |
From: Matthieu P. <pe...@sh...> - 2006-06-21 16:15:46
|
Le Mardi 20 Juin 2006 11:24, Travis Oliphant a =E9crit=A0: > Matthieu Perrot wrote: > > hi, > > > > I need to handle strings shaped by a numpy array whose data own to a C > > structure. There is several possible answers to this problem : > > 1) use a numpy array of strings (PyArray_STRING) and so a (char *) > > object in C. It works as is, but you need to define a maximum size to > > your strings because your set of strings is contiguous in memory. > > 2) use a numpy array of objects (PyArray_OBJECT), and wrap each =ABC > > string=BB with a python object, using PyStringObject for example. Then = our > > problem is that there is as wrapper as data element and I believe data > > can't be shared when your created PyStringObject using (char *) thanks = to > > PyString_AsStringAndSize by example. > > > > > > Now, I will expose a third way, which allow you to use no size-limited > > strings (as in solution 1.) and don't create wrappers before you really > > need it (on demand/access). > > > > First, for convenience, we will use in C, (char **) type to build an > > array of string pointers (as it was suggested in solution 2). Now, the > > game is to make it works with numpy API, and use it in python through a > > python array. Basically, I want a very similar behabiour than arrays of > > PyObject, where data are not contiguous, only their address are. So, the > > idea is to create a new array descr based on PyArray_OBJECT and change > > its getitem/setitem functions to deals with my own data. > > > > I exepected numpy to work with this convenient array descr, but it fails > > because PyArray_Scalar (arrayobject.c) don't call descriptor getitem > > function (in PyArray_OBJECT case) but call 2 lines which have been > > copy/paste from the OBJECT_getitem function). Here my small patch is : > > replace (arrayobject.c:983-984): > > Py_INCREF(*((PyObject **)data)); > > return *((PyObject **)data); > > by : > > return descr->f->getitem(data, base); > > > > I play a lot with my new numpy array after this change and noticed that= a > > lot of uses works : > > This is an interesting solution. I was not considering it, though, and > so I'm not surprised you have problems. You can register new types but > basing them off of PyArray_OBJECT can be problematic because of the > special-casing that is done in several places to manage reference countin= g. > > You are supposed to register your own data-types and get your own > typenumber. Then you can define all the functions for the entries as > you wish. > > Riding on the back of PyArray_OBJECT may work if you are clever, but it > may fail mysteriously as well because of a reference count snafu. > > Thanks for the tests and bug-reports. I have no problem changing the > code as you suggest. > > -Travis Thanks for applying my suggestions. I think, you suggest this kind of declaration : PyArray_Descr *descr =3D PyArray_DescrNewFromType(PyArray_VOID); descr->f->getitem =3D (PyArray_GetItemFunc *) my_getitem; descr->f->setitem =3D (PyArray_SetItemFunc *) my_setitem; descr->elsize =3D sizeof(char *); PyArray_RegisterDataType(descr); Without the last line, you are right it works and it follows the C-API way. But if I register this array descr, the typenumber is bigger than what PyTypeNum_ISFLEXIBLE function considers to be a flexible type. So the returned scalar object is badly-formed. Then, I get a segmentation fault=20 later, because the created voidscalar has a null descr pointer. =2D-=20 Matthieu Perrot |
From: Travis O. <oli...@ie...> - 2006-06-21 16:09:57
|
Bill Baxter wrote: > On 6/21/06, *Simon Burton* <si...@ar... > <mailto:si...@ar...>> wrote: > > On Wed, 21 Jun 2006 13:48:48 +0900 > "Bill Baxter" <wb...@gm... <mailto:wb...@gm...>> wrote: > > > > > >>> a[:,num.where(v>0.5)[0]] > > array([[1, 2, 4], > > [6, 7, 9]]) > > > > I'll put that up on the Matlab->Numpy page. > > oh, yuck. What about this: > > >>> a[:,num.nonzero(v>0.5)] > array([[0, 1, 3], > [5, 6, 8]]) > >>> > > > The nonzero() function seems like kind of an anomaly in and of > itself. It doesn't behave like other index-returning numpy > functions, or even like the method version, v.nonzero(), which returns > the typical tuple of array. So my feeling is ... ew to numpy.nonzero. How about we add the ability so that a[:, <boolean>] gets translated to a[:, nonzero(<boolean>)] ? -Travis |
From: Travis N. V. <tr...@en...> - 2006-06-21 15:27:22
|
All, As part of this year's SciPy 2006 Conference, we've planned Coding Sprints on Monday and Tuesday (August 14-15) and a Tutorial Day Wednesday (August 16)--the normal conference presentations follow on Thursday and Friday (August 17-18). For this year at least, the Tutorials (and Sprints) are no additional charge (you're on your own for food on those days, though). With regard to Tutorial topics, we've settled on the following: "3D visualization in Python using tvtk and MayaVi" "Scientific Data Analysis and Visualization using IPython and Matplotlib." "Building Scientific Applications using the Enthought Tool Suite (Envisage, Traits, Chaco, etc.)" "NumPy (migration from Numarray & Numeric, overview of NumPy)" These will be in two tracks with two three hour sessions in each track. If you plan to attend, please send an email to tut...@sc... with the two sessions you'd most like to hear and we'll build the schedule with a minimum of conflict. We'll post the schedule of the tracks on the Wiki here: http://www.scipy.org/SciPy2006/TutorialSessions Also, if you haven't registered already, the deadline for early registration is July 14. The abstract submission deadline is July 7. More information is here: http://www.scipy.org/SciPy2006 Thanks, Travis |
From: Keith G. <kwg...@gm...> - 2006-06-21 14:56:54
|
Alan G Isaac wrote: > M.transpose()[V>0] > If you want the columns as columns, > you can transpose again. I can't get that to work when M is a n by m matrix: >> M = asmatrix(rand(3,4)) >> M matrix([[ 0.78970407, 0.78681448, 0.79167808, 0.57857822], [ 0.44567836, 0.23985597, 0.49392248, 0.0282004 ], [ 0.7044725 , 0.4090776 , 0.12035218, 0.71365101]]) >> V = asmatrix(rand(4,1)) >> V matrix([[ 0.61638738], [ 0.76928157], [ 0.3882811 ], [ 0.68979661]]) >> M.transpose()[V > 0.5] matrix([[ 0.78970407, 0.78681448, 0.57857822]]) The answer should be a 3 by 3 matrix. |
From: Keith G. <kwg...@gm...> - 2006-06-21 14:14:24
|
On 6/20/06, Bill Baxter <wb...@gm...> wrote: > >>> a[:,num.where(v>0.5)[0]] > array([[1, 2, 4], > [6, 7, 9]]) > > I'll put that up on the Matlab->Numpy page. That's a great addition to the Matlab to Numpy page. But it only works if v is a column vector. If v is a row vector, then where(v.A > 0.5)[0] will return all zeros. So for row vectors it should be where(v.A > 0.5)[1]. Or, in general, where(v.flatten(1).A > 0.5)[1] |
From: Albert S. <fu...@gm...> - 2006-06-21 13:58:24
|
Hey Sheldon With NumPy you can use dtype's newbyteorder method to convert any dtype's byte order to an order you specify: In [1]: import numpy as N In [2]: x = N.array([1],dtype='<i4') In [3]: y = N.array([1],dtype='>i4') In [4]: xle = N.asarray(x, dtype=x.dtype.newbyteorder('<')) In [5]: yle = N.asarray(y, dtype=y.dtype.newbyteorder('<')) In [6]: x.dtype Out[6]: dtype('<i4') In [7]: y.dtype Out[7]: dtype('>i4') In [8]: xle.dtype Out[8]: dtype('<i4') In [9]: yle.dtype Out[9]: dtype('<i4') Regards, Albert > -----Original Message----- > From: num...@li... [mailto:numpy- > dis...@li...] On Behalf Of Johnston Sheldon > Sent: 21 June 2006 15:31 > To: Num...@li... > Subject: [Numpy-discussion] LittleEndian > > Hi, > > Can someone give a brief example of the Numeric function LittleEndian? > > I have written two separate functions to read binary data that can be > either LittleEndian or BigEndian (using byteswapped() ) but it would be > great with just one function. |
From: Johannes L. <a.u...@gm...> - 2006-06-21 13:36:25
|
Hi, > I'm not sure why bool arrays cannot be used as indices. > The "natural" solution to the original problem seemed to be: > M[:,V>0] > but this is not allowed. I started a thread on this earlier this year. Try searching the archive for "boolean indexing" (if it comes back online somewhen). Travis had some reason for not implementing this, but unfortunately I do not remember what it was. The corresponding message might still linger on my home PC, which I can access this evening.... Johannes |
From: Johnston S. <She...@sm...> - 2006-06-21 13:31:58
|
Hi, =20 Can someone give a brief example of the Numeric function LittleEndian? I have written two separate functions to read binary data that can be either LittleEndian or BigEndian (using byteswapped() ) but it would be great with just one function.=20 =20 Much obliged, Sheldon |
From: Pierre GM <pgm...@ma...> - 2006-06-21 10:12:10
|
On Wednesday 21 June 2006 04:46, Michael Sorich wrote: > When transposing a masked array of dtype '<f8' I noticed that an > ndarray of dtype '|O4' was returned. OK, I see where the problem is: When your fill_value has a type that cannot be converted to the type of your data, the `filled` method (used internally in many functions, such as `transpose`) raises a TypeError, which is caught and your array is converted to 'O'. That's what happen here: your fill_value is a string, your data are integer, the types don't match, hence the conversion. So, no, I don't think that's a bug. Why filling when you don't have any masked values, then ? Well, there's a subtle difference between a boolean mask and a mask of booleans. When the mask is boolean (mask=nomask=False), there's no masked value, and `filled` returns the data. Now, when your mask is an array of boolean (your first case), MA doesn't check whether mask.any()==False to determine whether there are some missing data or not, it just processes the whole array of boolean. I agree that's a bit confusing here, and there might be some room for improvement (for example, changing the current `if m is nomask` to `if m is nomask or m.any()==False`, or better, forcing mask to nomask if mask.any()==False). But I don;t think that qualifies as bug. In short: when you have an array of numbers, don't try to fill it with characters. |
From: Francesc A. <fa...@ca...> - 2006-06-21 09:16:03
|
=========================== Announcing PyTables 1.3.2 =========================== This is a new minor release of PyTables. There you will find, among other things, improved support for NumPy strings and the ability to create indexes of NumPy-flavored tables (this capability was broken in earlier versions). *Important note*: one of the fixes addresses an important bug that shows when browsing files with lots of nodes, making PyTables to crash. Because of this, an upgrade is encouraged. Go to the PyTables web site for downloading the beast: http://www.pytables.org/ or keep reading for more info about the new features and bugs fixed. Changes more in depth ===================== Bug fixes: - Changed the nodes in the lru cache heap from Pyrex to pure Python ones. This fixes a problem that can appear in certain situations (mainly, when navigating back and forth along lots of Node objects). While this fix is sub-optimal, at least it leads to well behaviour until the faster approach will eventually get back. - Due to different conventions in padding chars, it has been added a special case when converting from numarray strings into numpy ones so that these different conventions are handled correctly. Fixes ticket #13 and other strange numpy string quirks (thanks to Pepe Barbe). - Solved an issue that appeared when indexing Table columns with flavor 'numpy'. Now, tables that are 'numpy' flavored can be indexed as well. - Solved an issue when saving string atoms with ``VLArray`` with a flavor different from "python". The problem was that the item sizes of the original strings were not checked, so rubish was put on-disk. Now, if an item size of the input is different from the item size of the atom, a conversion is forced. Added tests to check for these situations. - Fixed a problem with removing a table with indexed columns under certain situations. Thanks to Andrew Straw for reporting it. - Fixed a small glitch in the ``ptdump`` utility that prevented dumping ``EArray`` data with an enlargeable dimension different from the first one. - Make parent node unreference child node when creation fails. Fixes ticket #12 (thanks to Eilif). - Saving zero-length strings in Array objects used to raise a ZeroDivisionError. Now, it returns a more sensible NotImplementedError until this is supported. Backward-incompatible changes: - Please, see ``RELEASE-NOTES.txt`` file. Deprecated features: - None Important note for Windows users ================================ If you are willing to use PyTables with Python 2.4 in Windows platforms, you will need to get the HDF5 library compiled for MSVC 7.1, aka .NET 2003. It can be found at: ftp://ftp.ncsa.uiuc.edu/HDF/HDF5/current/bin/windows/5-165-win-net.ZIP Users of Python 2.3 on Windows will have to download the version of HDF5 compiled with MSVC 6.0 available in: ftp://ftp.ncsa.uiuc.edu/HDF/HDF5/current/bin/windows/5-165-win.ZIP What it is ========== **PyTables** is a package for managing hierarchical datasets and designed to efficiently cope with extremely large amounts of data (with support for full 64-bit file addressing). It features an object-oriented interface that, combined with C extensions for the performance-critical parts of the code, makes it a very easy-to-use tool for high performance data storage and retrieval. PyTables runs on top of the HDF5 library and numarray (but NumPy and Numeric are also supported) package for achieving maximum throughput and convenient use. Besides, PyTables I/O for table objects is buffered, implemented in C and carefully tuned so that you can reach much better performance with PyTables than with your own home-grown wrappings to the HDF5 library. PyTables sports indexing capabilities as well, allowing doing selections in tables exceeding one billion of rows in just seconds. Platforms ========= This version has been extensively checked on quite a few platforms, like Linux on Intel32 (Pentium), Win on Intel32 (Pentium), Linux on Intel64 (Itanium2), FreeBSD on AMD64 (Opteron), Linux on PowerPC (and PowerPC64) and MacOSX on PowerPC. For other platforms, chances are that the code can be easily compiled and run without further issues. Please, contact us in case you are experiencing problems. Resources ========= Go to the PyTables web site for more details: http://www.pytables.org About the HDF5 library: http://hdf.ncsa.uiuc.edu/HDF5/ About numarray: http://www.stsci.edu/resources/software_hardware/numarray To know more about the company behind the PyTables development, see: http://www.carabos.com/ Acknowledgments =============== Thanks to various the users who provided feature improvements, patches, bug reports, support and suggestions. See the ``THANKS`` file in the distribution package for a (incomplete) list of contributors. Many thanks also to SourceForge who have helped to make and distribute this package! And last but not least, a big thank you to THG (http://www.hdfgroup.org/) for sponsoring many of the new features recently introduced in PyTables. Share your experience ===================== Let us know of any bugs, suggestions, gripes, kudos, etc. you may have. ---- **Enjoy data!** -- The PyTables Team |
From: Alan G I. <ai...@am...> - 2006-06-21 09:13:59
|
On Wed, 21 Jun 2006, Bill Baxter apparently wrote: > ew to numpy.nonzero I agree that having the method and function behave so differently is awkward; this was discussed before on this list. It does allow Simon's nicer solution, however. I'm not sure why bool arrays cannot be used as indices. The "natural" solution to the original problem seemed to be: M[:,V>0] but this is not allowed. Cheers, Alan Isaac |
From: Michael S. <mic...@gm...> - 2006-06-21 08:46:20
|
When transposing a masked array of dtype '<f8' I noticed that an ndarray of dtype '|O4' was returned. I found this a little strange as the masked array did not contain any masked values. Upon closer examination (see script below) it seems that if the mask is a boolean array with all false values and the fill_value is a string this will occur. However if the fill_value is a number or the mask is simply False, the dtype stays as '<f8'. I was going to submit this as a bug but wanted to check that this was not a deliberate feature. I am using the numpy version that comes with a recent version of python enthought edition. import numpy print numpy.version.version ma1 = numpy.ma.array(((1.,2,3),(4,5,6)), mask=((0,0,0),(0,0,0))) print ma1.filled('NA').dtype print ma1.filled(-999).dtype ma2 = numpy.ma.array(((1.,2,3),(4,5,6)), mask=False) print ma2.filled('NA').dtype print ma2.filled(-999).dtype --------------- output: 0.9.9.2538 '|O4' '<f8' '<f8' '<f8' |
From: Alan G I. <ai...@am...> - 2006-06-21 08:40:55
|
On Tue, 20 Jun 2006, Keith Goodman apparently wrote:=20 > I have a matrix M and a vector (n by 1 matrix) V. I want to form a new=20 > matrix that contains the columns of M for which V > 0.=20 > One way to do that in Octave is M(:, find(V > 0)). How is it done in nump= y?=20 M.transpose()[V>0] If you want the columns as columns, you can transpose again. hth, Alan Isaac |
From: Bill B. <wb...@gm...> - 2006-06-21 07:17:24
|
On 6/21/06, Simon Burton <si...@ar...> wrote: > > On Wed, 21 Jun 2006 13:48:48 +0900 > "Bill Baxter" <wb...@gm...> wrote: > > > > > >>> a[:,num.where(v>0.5)[0]] > > array([[1, 2, 4], > > [6, 7, 9]]) > > > > I'll put that up on the Matlab->Numpy page. > > oh, yuck. What about this: > > >>> a[:,num.nonzero(v>0.5)] > array([[0, 1, 3], > [5, 6, 8]]) > >>> The nonzero() function seems like kind of an anomaly in and of itself. It doesn't behave like other index-returning numpy functions, or even like the method version, v.nonzero(), which returns the typical tuple of array. So my feeling is ... ew to numpy.nonzero. --Bill |
From: Simon B. <si...@ar...> - 2006-06-21 05:23:55
|
On Wed, 21 Jun 2006 13:48:48 +0900 "Bill Baxter" <wb...@gm...> wrote: > > >>> a[:,num.where(v>0.5)[0]] > array([[1, 2, 4], > [6, 7, 9]]) > > I'll put that up on the Matlab->Numpy page. oh, yuck. What about this: >>> a[:,num.nonzero(v>0.5)] array([[0, 1, 3], [5, 6, 8]]) >>> Simon. -- Simon Burton, B.Sc. Licensed PO Box 8066 ANU Canberra 2601 Australia Ph. 61 02 6249 6940 http://arrowtheory.com |
From: Bill B. <wb...@gm...> - 2006-06-21 04:48:51
|
On 6/21/06, Erin Sheldon <eri...@gm...> wrote: > > On 6/20/06, Bill Baxter <wb...@gm...> wrote: > > I think that one's on the NumPy for Matlab users, no? > > > > http://www.scipy.org/NumPy_for_Matlab_Users > > > > >>> import numpy as num > > >>> a = num.arange (10).reshape(2,5) > > >>> a > > array([[0, 1, 2, 3, 4], > > [5, 6, 7, 8, 9]]) > > >>> v = num.rand(5) > > >>> v > > array([ 0.10934855, 0.55719644, 0.7044047 , 0.19250088, 0.94636972]) > > >>> num.where(v>0.5) > > (array([1, 2, 4]),) > > >>> a[:,num.where(v>0.5)] > > array([[[1, 2, 4]], > > > > [[6, 7, 9]]]) > > > > Seems it grows an extra set of brackets for some reason. Squeeze will > get > > rid of them. > > > > >>> a[:,num.where(v>0.5)].squeeze() > > array([[1, 2, 4], > > [6, 7, 9]]) > > > > Not sure why the squeeze is needed. Maybe there's a better way. > > where returns a tuple of arrays. This can have unexpected results > so you need to grab what you want explicitly: > > >>> (w,) = num.where(v>0.5) > >>> a[:,w] > array([[1, 2, 4], > [6, 7, 9]]) > Ah, yeh, that makes sense. Thanks for the explanation. So to turn it back into a one-liner you just need: >>> a[:,num.where(v>0.5)[0]] array([[1, 2, 4], [6, 7, 9]]) I'll put that up on the Matlab->Numpy page. --bb |
From: Erin S. <eri...@gm...> - 2006-06-21 04:10:11
|
On 6/20/06, Bill Baxter <wb...@gm...> wrote: > I think that one's on the NumPy for Matlab users, no? > > http://www.scipy.org/NumPy_for_Matlab_Users > > >>> import numpy as num > >>> a = num.arange (10).reshape(2,5) > >>> a > array([[0, 1, 2, 3, 4], > [5, 6, 7, 8, 9]]) > >>> v = num.rand(5) > >>> v > array([ 0.10934855, 0.55719644, 0.7044047 , 0.19250088, 0.94636972]) > >>> num.where(v>0.5) > (array([1, 2, 4]),) > >>> a[:,num.where(v>0.5)] > array([[[1, 2, 4]], > > [[6, 7, 9]]]) > > Seems it grows an extra set of brackets for some reason. Squeeze will get > rid of them. > > >>> a[:,num.where(v>0.5)].squeeze() > array([[1, 2, 4], > [6, 7, 9]]) > > Not sure why the squeeze is needed. Maybe there's a better way. where returns a tuple of arrays. This can have unexpected results so you need to grab what you want explicitly: >>> (w,) = num.where(v>0.5) >>> a[:,w] array([[1, 2, 4], [6, 7, 9]]) |
From: Keith G. <kwg...@gm...> - 2006-06-21 03:49:30
|
On 6/20/06, Bill Baxter <wb...@gm...> wrote: > I think that one's on the NumPy for Matlab users, no? > > http://www.scipy.org/NumPy_for_Matlab_Users > > >>> import numpy as num > >>> a = num.arange (10).reshape(2,5) > >>> a > array([[0, 1, 2, 3, 4], > [5, 6, 7, 8, 9]]) > >>> v = num.rand(5) > >>> v > array([ 0.10934855, 0.55719644, 0.7044047 , 0.19250088, 0.94636972]) > >>> num.where(v>0.5) > (array([1, 2, 4]),) > >>> a[:,num.where(v>0.5)] > array([[[1, 2, 4]], > > [[6, 7, 9]]]) > > Seems it grows an extra set of brackets for some reason. Squeeze will get > rid of them. > > >>> a[:,num.where(v>0.5)].squeeze() > array([[1, 2, 4], > [6, 7, 9]]) > > Not sure why the squeeze is needed. Maybe there's a better way. Thank you. That works for arrays, but not matrices. So do I need to do asarray(a)[:, where(asarray(v)>0.5)].squeeze() ? |
From: Erin S. <eri...@gm...> - 2006-06-21 03:34:42
|
OK, I have changed all the examples that used dtype=Float or dtype=Int to float and int. Erin On 6/20/06, David M. Cooke <co...@ph...> wrote: > On Tue, Jun 20, 2006 at 09:00:52PM -0400, Erin Sheldon wrote: > > The numpy example page still has dtype=Float and dtype=Int > > all over it. Is there a generic replacement for Float, Int or should > > these be changed to something more specific such as int32? > > Erin > > float and int (the Python types) are the generic 'float' and 'int' > types. > > -- > |>|\/|< > /--------------------------------------------------------------------------\ > |David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/ > |co...@ph... > |
From: Bill B. <wb...@gm...> - 2006-06-21 03:33:46
|
I think that one's on the NumPy for Matlab users, no? http://www.scipy.org/NumPy_for_Matlab_Users >>> import numpy as num >>> a = num.arange (10).reshape(2,5) >>> a array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]) >>> v = num.rand(5) >>> v array([ 0.10934855, 0.55719644, 0.7044047 , 0.19250088, 0.94636972]) >>> num.where(v>0.5) (array([1, 2, 4]),) >>> a[:,num.where(v>0.5)] array([[[1, 2, 4]], [[6, 7, 9]]]) Seems it grows an extra set of brackets for some reason. Squeeze will get rid of them. >>> a[:,num.where(v>0.5)].squeeze() array([[1, 2, 4], [6, 7, 9]]) Not sure why the squeeze is needed. Maybe there's a better way. --bb On 6/21/06, Keith Goodman <kwg...@gm...> wrote: > > I have a matrix M and a vector (n by 1 matrix) V. I want to form a new > matrix that contains the columns of M for which V > 0. > > One way to do that in Octave is M(:, find(V > 0)). How is it done in > numpy? > > > |
From: Keith G. <kwg...@gm...> - 2006-06-21 03:04:27
|
I have a matrix M and a vector (n by 1 matrix) V. I want to form a new matrix that contains the columns of M for which V > 0. One way to do that in Octave is M(:, find(V > 0)). How is it done in numpy? |
From: David M. C. <co...@ph...> - 2006-06-21 02:01:14
|
On Tue, Jun 20, 2006 at 09:00:52PM -0400, Erin Sheldon wrote: > The numpy example page still has dtype=Float and dtype=Int > all over it. Is there a generic replacement for Float, Int or should > these be changed to something more specific such as int32? > Erin float and int (the Python types) are the generic 'float' and 'int' types. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/ |co...@ph... |