[Numpy-discussion] puzzle with boolean dtype

2010-10-06 Thread Alan G Isaac
Integer exponentiation fails (i.e., changes type) with boolean dtype. See below. Expected? Alan Isaac a = np.array([[0,1,0],[0,0,1],[1,0,0]], dtype=np.bool_) a2 = a*a a3 = a2*a print(a3) [[False True False] [False False True] [ True False False]]

Re: [Numpy-discussion] puzzle with boolean dtype

2010-10-06 Thread Alan G Isaac
On 10/6/2010 5:52 PM, Charles R Harris wrote: What would you want in it's place? For consistancy, a**0 == all_true, a**i == a, i 0? Yes. Alan Isaac PS Boolean matrix powers are well defined and useful. I found this oddity by accidentally creating an array instead of a matrix.

Re: [Numpy-discussion] new warning in 1.5.0: divide by zero encountered in log

2010-09-08 Thread Alan G Isaac
On 9/8/2010 6:38 AM, John Reid wrote: def safe_x_log_x(x): @return: x log(x) but replaces -inf with 0. l = np.log(x) result = x * l result[np.isneginf(l)] = 0. return result Assuming x is known to contain nonnegative floats: def safe_x_log_x(x): x =

Re: [Numpy-discussion] array manipulation

2010-08-17 Thread Alan G Isaac
On 8/17/2010 12:13 AM, Alex Ter-Sarkissov wrote: I have an array (say, mat=rand(3,5)) from which I 'pull out' a row (say, s1=mat[1,]). The problem is, the shape of this row s1 is not [1,5], as I would expect, but rather [5,], which means that I can't, for example, concateante mat and s1

Re: [Numpy-discussion] ANN: NumPy 1.5.0 beta 2

2010-08-17 Thread Alan G Isaac
Two warnings remain; no failures. Details below. Alan Isaac (Python 2.7 on Vista) Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import numpy as np np.test() Running unit tests for numpy NumPy

Re: [Numpy-discussion] ANN: NumPy 1.5.0 beta 2

2010-08-17 Thread Alan G Isaac
On 8/17/2010 12:07 PM, Pierre GM wrote: What does a np.ma.test() give you ? No problems. (Aren't those always run?) Alan np.ma.test() Running unit tests for numpy.ma NumPy version 1.5.0b2 NumPy is installed in C:\Python27\lib\site-packages\numpy Python version 2.7 (r27:82525, Jul 4 2010,

Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Alan G Isaac
On 8/17/2010 11:53 AM, Nikolaus Rath wrote: I want to find the first i such that x[i] y and x[i+1]= y. Is there a way to do this without using a Python loop? argmax? (to get i+1): d = np.linspace(0,10,101) x = np.sin(d) np.argmax(x=0.5) 6 fwiw, Alan

Re: [Numpy-discussion] Changing a matrix element into a scalar

2010-08-03 Thread Alan G Isaac
On 8/3/2010 12:23 PM, Wayne Watson wrote: How do I access 1.2 in such a way as to end up with a float? I keep getting a matrix. from numpy import matrix m = matrix([[1.2],[2.3]]) Matrices have the odd (and imo undesirable) property that m[0,0] != m[0][0] You want the former. For a

Re: [Numpy-discussion] Changing a matrix element into a scalar

2010-08-03 Thread Alan G Isaac
On 8/3/2010 1:29 PM, Joshua Holbrook wrote: What's the advantage of the matrix datatype? As it turns out, that's a controversial question. ;-) One answer: pedagogy (for those used to matrices). A related answer: succinctness and readability of *some* code. a,b,c =

Re: [Numpy-discussion] Tabular: Importing data from file

2010-08-03 Thread Alan G Isaac
On 8/3/2010 5:40 PM, Robert Faryabi wrote: I'm using Tabular Package for manipulating tab-delimited data. There is a small problem that I cannot get my head around it. When I construct my tabarray from file, the blank fields are replaced by nan. Does any one knows how to just keep them as

Re: [Numpy-discussion] ANN: NumPy 1.5.0 beta 1

2010-08-01 Thread Alan G Isaac
On 8/1/2010 12:38 PM, Ralf Gommers wrote: Binaries, sources and release notes can be found at https://sourceforge.net/projects/numpy/files/ https://sourceforge.net/projects/numpy/files/ I'm not seeing them. Alan ___ NumPy-Discussion mailing list

Re: [Numpy-discussion] ANN: NumPy 1.5.0 beta 1

2010-08-01 Thread Alan G Isaac
Tests produce a few failures and a couple warnings. Details below. Alan Isaac Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import numpy as np np.test() Running unit tests for numpy NumPy

Re: [Numpy-discussion] floating point arithmetic issue

2010-07-30 Thread Alan G Isaac
On 7/30/2010 8:21 AM, Guillaume Chérel wrote: is there no implementation of an exact type You could use the fraction module: f = [Fraction(i,10) for i in range(10)] a = np.array(f, dtype=object) a array([0, 1/10, 1/5, 3/10, 2/5, 1/2, 3/5, 7/10, 4/5, 9/10], dtype=object) But I don't see why

Re: [Numpy-discussion] floating point arithmetic issue

2010-07-30 Thread Alan G Isaac
On 7/30/2010 12:59 PM, Guillaume Chérel wrote: my problem may involve many more than 2 disks at a time You cd approximate each disc by a polygon, as accurately as you need, and test each point for membership in each disc: from matplotlib.nxutils import pnpoly hth, Alan Isaac

Re: [Numpy-discussion] A bug in boolean indexing?

2010-07-29 Thread Alan G Isaac
On 7/29/2010 4:04 AM, Nadav Horesh wrote: a = np.arange(5) a[a0] = a This has nothing to do with reusing ``a``:: b = np.arange(50) a[a0] = b a array([0, 0, 1, 2, 3]) Note however that reusing ``a`` is unsafe. (You will get all zeros.) fwiw, Alan Isaac

[Numpy-discussion] additions to random: innovative names vs. algorithm specification

2010-07-29 Thread Alan G Isaac
Rather than just looking for a new name (e.g., znormal), would it not be better to decide on a syntax for specifying PRNG algorithms? (E.g., MATLAB takes such an approach: http://www.mathworks.com/access/helpdesk/help/techdoc/math/brt5wsv.html) Wouldn't this meet the need for replicability with

Re: [Numpy-discussion] additions to random: innovative names vs. algorithm specification

2010-07-29 Thread Alan G Isaac
On 7/29/2010 4:37 PM, Robert Kern wrote: this MATLAB API is deprecated The old API has been replaced by a constructor that still takes a string literal argument to determine the PRNG algorithm. See the bottom of http://www.mathworks.com/access/helpdesk/help/techdoc/math/brt5wsv.html This

Re: [Numpy-discussion] ceil returns real ?

2010-07-28 Thread Alan G Isaac
On 7/28/2010 8:26 AM, Mark Bakker wrote: I don't understand why ceil and floor return real values The same for ``round``. (Note that Python 3 rounds to int.) Furthermore, it would be nice if each took a ``dtype`` argument. Alan Isaac ___

Re: [Numpy-discussion] ceil returns real ?

2010-07-28 Thread Alan G Isaac
Wed, 28 Jul 2010 14:26:36 +0200, Mark Bakker wrote: I don't understand why ceil and floor return real values [snip] Wouldn't an integer make more sense? On 7/28/2010 9:39 AM, Pauli Virtanen wrote: Which integer? Only arbitrary-size integers (Python longs) are able to span the whole

Re: [Numpy-discussion] determinant of a scalar not handled

2010-07-27 Thread Alan G Isaac
On Mon, Jul 26, 2010 at 10:05 PM, Alan G Isaacais...@american.edu wrote: But I am still confused about the use case. What is the scalar- (or 1d-array-) returning procedure invoked before taking the determinant? On 7/27/2010 8:51 AM, Skipper Seabold wrote: Recently I ran into this trying to

Re: [Numpy-discussion] subtract.reduce behavior

2010-07-27 Thread Alan G Isaac
On 7/26/2010 9:41 AM, Johann Hibschman wrote: if reduce were defined as a *right* fold, then it would make sense for subtract (and divide) to use the right identity Instead of deviating from the Python definition of reduce, it would imo make more sense to introduce new functions, sayfoldl and

Re: [Numpy-discussion] determinant of a scalar not handled

2010-07-26 Thread Alan G Isaac
On 7/26/2010 12:45 PM, Skipper Seabold wrote: Right now np.linalg.det does not handle scalars or 1d (scalar) arrays. I don't have a real opinion on changing this, but I am curious to know the use case, as the current behavior seems a) correct and b) to provide an error check. Cheers, Alan

Re: [Numpy-discussion] determinant of a scalar not handled

2010-07-26 Thread Alan G Isaac
On 7/26/2010 8:22 PM, Joshua Holbrook wrote: imo, the determinant of a scalar should be defined as itself, based on the definition of the determinant. What definition do you have in mind? Alan Isaac ___ NumPy-Discussion mailing list

Re: [Numpy-discussion] determinant of a scalar not handled

2010-07-26 Thread Alan G Isaac
On 7/26/2010 8:18 PM, Skipper Seabold wrote: np.linalg.det(np.array([[2]])) #2.0 which should either fail or if not, then I think np.linalg.det should handle scalars and scalars as 1d arrays It should not fail, because it follows from standard definitions. (E.g., it is the base case of a

Re: [Numpy-discussion] subtract.reduce behavior

2010-07-23 Thread Alan G Isaac
On 7/22/2010 4:00 PM, Johann Hibschman wrote: I'm trying to understand numpy.subtract.reduce. The documentation doesn't seem to match the behavior. The documentation claims For a one-dimensional array, reduce produces results equivalent to: r = op.identity for i in

Re: [Numpy-discussion] subtract.reduce behavior

2010-07-23 Thread Alan G Isaac
Fri, 23 Jul 2010 10:29:47 -0400, Alan G Isaac wrote: np.subtract.reduce([]) 0.0 Getting a right identity for an empty array is surprising. Matching Python's behavior (raising a TypeError) seems desirable. (?) On 7/23/2010 10:37 AM, Pauli Virtanen wrote: I don't

Re: [Numpy-discussion] ANN: scipy 0.8.0 release candidate 1

2010-07-05 Thread Alan G Isaac
On 7/5/2010 11:13 AM, Ralf Gommers wrote: The failure is yet another case of test precision set slightly too high. Thought we had got them all... Not sure about the matlab thing. Which version of Windows are you running? Vista 64bit (with 32 bit Python 2.6). Alan

Re: [Numpy-discussion] MemoryError with dot(A, A.T) where A is 800MB on 32-bit Vista

2010-06-09 Thread Alan G Isaac
On 6/9/2010 12:49 PM, greg whittier wrote: Is there a way to do A*A.T without two copies of A? Does this do what you want? Alan Isaac a array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]) np.tensordot(a,a,axes=(-1,-1)) array([[ 1, 3, 5, 7, 9], [

Re: [Numpy-discussion] Summation of large float32/float64 arrays

2010-05-23 Thread Alan G Isaac
On 5/21/2010 8:34 PM, Christoph Gohlke wrote: the 32-bit Python interpreter can only use 2 GB of your memory Why? 2**32/1e9 4.294967296003 Thanks, Alan ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org

Re: [Numpy-discussion] Summation of large float32/float64 arrays

2010-05-23 Thread Alan G Isaac
On 5/23/2010 9:33 PM, Christoph Gohlke wrote: 2 GB is the memory limit for 32-bit processes running in user-mode under 64-bit Windows, unless the executable was specifically built with 'IMAGE_FILE_LARGE_ADDRESS_AWARE' set. Seehttp://msdn.microsoft.com/en-us/library/aa366778%28VS.85%29.aspx

Re: [Numpy-discussion] Summation of large float32/float64 arrays

2010-05-21 Thread Alan G Isaac
On 5/21/2010 4:13 PM, Matthew Turk wrote: a1 = numpy.random.random((512,512,512)).astype(float32) This consistently gives me a MemoryError. I believe I have plenty of physical memory. (That should require about 1.3G during creation, right? I have 8G.) It seems I'm hitting some kind of 1G memory

Re: [Numpy-discussion] Wrong Eigenvalue (Approximation?)

2010-05-16 Thread Alan G Isaac
On 5/16/2010 12:03 AM, Gabriel Mihalache wrote: The eigenvalue should be 1 exactly. http://floating-point-gui.de/ hth, Alan Isaac ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] check for inequalities on a list

2010-05-10 Thread Alan G Isaac
On 5/10/2010 5:42 PM, gerardob wrote: I would like to check whether lower_bound[i]= x[i]= upper_bound[i] for all i in range(len(x)) import numpy as np l, m, u = np.arange(12).reshape((3,4)) (l = m) (m = u) array([ True, True, True, True], dtype=bool) l[3]=9 (l = m) (m = u) array([

[Numpy-discussion] trouble with bool_

2010-05-06 Thread Alan G Isaac
What information exactly is `isnan` supposed to communicate? Put another way, given that it raises NotImplemented for unknown types, and that bool(NotImplemented) is True, is there a reason by it cannot return a Python bool (which seems more useful)? Thanks, Alan Isaac np.isnan(np.nan) True

Re: [Numpy-discussion] proposing a beware of [as]matrix() warning

2010-04-29 Thread Alan G Isaac
Alan wrote: There is one change I would not mind: let A * M be undefined if A is an ndarray and M is a NumPy matrix. On 4/28/2010 5:46 PM, David Warde-Farley wrote: What about the other binary ops? I would say, matrix goes with matrix, array with array, never the two shall meet unless you

Re: [Numpy-discussion] proposing a beware of [as]matrix() warning

2010-04-29 Thread Alan G Isaac
On 4/28/2010 5:46 PM, David Warde-Farley wrote: Would it be acceptable to retain the matrix class but not have it imported in the default namespace, and have to import e.g. numpy.matlib to get at them? If we can have A * M undefined, then I do not think this is a needed addition. But I do not

Re: [Numpy-discussion] proposing a beware of [as]matrix() warning

2010-04-28 Thread Alan G Isaac
On 4/28/2010 12:05 PM, Travis Oliphant wrote: A proposal was made to allow calling a NumPy array to infer dot product: a(b) is equivalent to dot(a,b) a(b)(c) would be equivalent to dot(dot(a,b),c) Here is a related ticket that proposes a more explicit alternative: adding a ``dot`` method

Re: [Numpy-discussion] proposing a beware of [as]matrix() warning

2010-04-28 Thread Alan G Isaac
On 4/28/2010 12:08 PM, Dag Sverre Seljebotn wrote: it would be good to deprecate the matrix class from NumPy Please let us not have this discussion all over again. The matrix class is very useful for teaching. In economics for example, the use of matrix algebra is widespread, while algebra

Re: [Numpy-discussion] binomial coefficient, factorial

2010-04-14 Thread Alan G Isaac
On 4/13/2010 11:16 PM, jah wrote: binomial coefficent and factorial function http://code.google.com/p/econpy/source/browse/trunk/pytrix/pytrix.py fwiw, Alan Isaac ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org

Re: [Numpy-discussion] Numpy Segmentation Fault

2010-04-06 Thread Alan G Isaac
On 4/6/2010 6:46 AM, Yogesh Tomar wrote: import numpy import numpy.linalg x=numpy.eye(1000) for i in range(10): eigenvalues,eigenvectors=numpy.linalg.eig(x) eigenvalues,eigenvectors=numpy.linalg.eig(x) print str(i),'---'* I'm not seeing any

Re: [Numpy-discussion] Is this odd?

2010-04-02 Thread Alan G Isaac
On 4/2/2010 8:29 AM, Nadav Horesh wrote: In python empty sequences are always equivalent to False, and non-empty to True. I think that was why the OP objected to this behavior: bool(np.array([0])) False Alan Isaac ___

Re: [Numpy-discussion] indexing question

2010-03-30 Thread Alan G Isaac
On 3/30/2010 10:13 AM, Tom K. wrote: What I want to do is get rid of singleton dimensions, and index into the last dimension with an array. x=np.zeros((10,1,1,1,14,1024)) np.squeeze(x).shape (10, 14, 1024) hth, Alan Isaac ___ NumPy-Discussion

Re: [Numpy-discussion] Set values of a matrix within a specified range to zero

2010-03-30 Thread Alan G Isaac
On 3/30/2010 12:56 PM, Sean Mulcahy wrote: 512x512 arrays. I would like to set elements of the array whose value fall within a specified range to zero (eg 23 x 45). x[(23x)*(x45)]=0 hth, Alann Isaac ___ NumPy-Discussion mailing list

Re: [Numpy-discussion] integer division rule changed

2010-03-22 Thread Alan G Isaac
On 3/13/2010 8:57 PM, Charles R Harris wrote: I suspect the change was made, whenever that was, in order to conform to python. So is there an actual polcy? When C99 behavior and Python behavior differ, will NumPy follow Python as a *rule*? Thanks, Alan Isaac

Re: [Numpy-discussion] Help!!! Docstrings overrun by markup crap.

2010-03-21 Thread Alan G Isaac
On 3/21/2010 12:24 AM, Charles R Harris wrote: I really, really want to get rid of the asterisks, they are ugly and distracting (IMHO). I agree, which is why my deflist example did not use asterisks. I consider it readable and only very slightly verbose. (The blank lines are needed by reST,

Re: [Numpy-discussion] Help!!! Docstrings overrun by markup crap.

2010-03-21 Thread Alan G Isaac
On 3/21/2010 12:47 AM, josef.p...@gmail.com wrote: dashes would be also ok, but I don't think rst would recognize them. It does. But again, a definition list (using indentation) is also a list structure. It needs no markup besides the indentation. My main problem with rst is that it doesn't

Re: [Numpy-discussion] Help!!! Docstrings overrun by markup crap.

2010-03-21 Thread Alan G Isaac
On 3/21/2010 12:54 AM, Ralf Gommers wrote: too many blank lines are needed Please define need after seeing the compact example I posted. Personally, I think reST makes the right trade-offs, minimizing markup within the constraint of being unambiguous. Alan Isaac

Re: [Numpy-discussion] Help!!! Docstrings overrun by markup crap.

2010-03-21 Thread Alan G Isaac
On 3/21/2010 12:54 AM, Ralf Gommers wrote: too many blank lines are needed On Sun, Mar 21, 2010 at 9:51 PM, Alan G Isaac ais...@american.edu mailto:ais...@american.edu wrote: Please define need after seeing the compact example I posted. On 3/21/2010 9:58 AM, Ralf Gommers wrote

Re: [Numpy-discussion] Help!!! Docstrings overrun by markup crap.

2010-03-20 Thread Alan G Isaac
On 3/20/2010 2:15 PM, josef.p...@gmail.com wrote: As far as I know, stars are the only way to render a list in restructured txt, otherwise it looses the list formatting. Try a definition list? Example below. Alan Returns --- q, r if mode = 'full': - q : ndarray of float or complex,

Re: [Numpy-discussion] lists of zeros and ones

2010-03-19 Thread Alan G Isaac
On 3/19/2010 10:53 AM, gerardob wrote: I would like to know a simple way to generate a list containing all the lists having two 1's at each element. Example, n = 4 L2 = [[1,1,0,0],[1,0,1,0],[1,0,0,1],[0,1,1,0],[0,1,0,1],[0,0,1,1]] I like list(set(itertools.permutations([1,1]+[0]*(n-2

Re: [Numpy-discussion] np.resize differs from ndarray.resize

2010-03-19 Thread Alan G Isaac
On 3/18/2010 4:56 AM, Sebastian Haase wrote: How would people feel about unifying the function vs. the method behavior ? One could add an addition option like `repeat` or `fillZero`. One could (at first !?) keep opposite defaults to not change the current behavior. But this way it would be

[Numpy-discussion] bug in ndarray.resize?

2010-03-17 Thread Alan G Isaac
Is the zero-fill intentional? If so, it is documented? (NumPy 1.3) Alan Isaac a = np.arange(5) b = a.copy() c = np.resize(a, (5,2)) b.resize((5,2)) c # as expected array([[0, 1], [2, 3], [4, 0], [1, 2], [3, 4]]) b # surprise! array([[0, 1], [2, 3],

Re: [Numpy-discussion] bug in ndarray.resize?

2010-03-17 Thread Alan G Isaac
On 3/17/2010 10:16 AM, josef.p...@gmail.com wrote: numpy.resize(a, new_shape) Return a new array with the specified shape. If the new array is larger than the original array, then the new array is filled with repeated copied of a. Note that this behavior is different from a.resize(new_shape)

[Numpy-discussion] integer division rule?

2010-03-13 Thread Alan G Isaac
Francesc Altet once provided an example that for integer division, numpy uses the C99 rule: round towards 0. This is different than Python's rule for integer division: round towards negative infinity. But I cannot reproduce his example. (NumPy 1.3.) Did this behavior change at some point?

[Numpy-discussion] random.uniform documentation bug?

2010-02-23 Thread Alan G Isaac
This behavior does not match the current documentation. np.random.uniform(low=0.5,high=0.5) 0.5 np.random.uniform(low=0.5,high=0.4) 0.48796883601707464 I assume this behavior is intentional and it is the documentation that is in error (for the case when high=low)? fwiw, Alan Isaac

Re: [Numpy-discussion] Request for testing

2010-02-21 Thread Alan G Isaac
On 2/21/2010 5:30 AM, Charles R Harris wrote: I would be much obliged if some folks would run the attached script and report the output, numpy version, and python version. No problem with NumPy 1.3.0 (from superpack) on Python 2.6.4 under Vista. Alan Isaac Python 2.6.4 (r264:75708, Oct 26

Re: [Numpy-discussion] Updating Packages in 2.5 (win/numpy) and Related Matters

2010-02-18 Thread Alan G Isaac
Wayne wrote: I just checked the version via import and it's 0.6.0. Try updating. Also, the SciPy Reference Guide explains how to turn off deprecation warnings. http://docs.scipy.org/doc/scipy/scipy-ref.pdf Alan Isaac ___ NumPy-Discussion mailing list

[Numpy-discussion] cov

2010-02-15 Thread Alan G Isaac
1. Should `numpy.cov` use `ddof` instead of `bias`, like `std` and `mean`? 2. Should the docs for scipy.cov state that it is deprecated? http://docs.scipy.org/scipy/docs/scipy.stats.stats.cov/#scipy-stats-cov (Use raises a deprecation warning.) Thanks, Alan Isaac

Re: [Numpy-discussion] cov

2010-02-15 Thread Alan G Isaac
On Mon, Feb 15, 2010 at 8:42 AM, Alan G Isaacais...@american.edu wrote: 1. Should `numpy.cov` use `ddof` instead of `bias`, like `std` and `mean`? On 2/15/2010 9:31 AM, josef.p...@gmail.com wrote: +1 (I just checked scipy stats and the usage of bias versus ddof is also inconsistent.

Re: [Numpy-discussion] Scalar-ndarray arguments passed to not_equal

2010-02-10 Thread Alan G Isaac
On 2/10/2010 1:57 PM, Friedrich Romstedt wrote: I wonder why there is no response on my e-mail dating back to Feb 4. Is there nobody interested in it, is somebody working on it, or did it simply did not come through? I'm going to guess it is because your actual question is at the very end of a

Re: [Numpy-discussion] Python 2.6 and numpy 1.3.0/1.4.0 from an extension

2010-02-08 Thread Alan G Isaac
I see that NumPy 1.4.0 is still the download offered on SourceForge. Did I misunderstand that a decision had been made to withdraw it, at least until the ongoing discussion about ABI breakage is resolved? (Btw, as a user, I'm hoping Jarrod's sensible proposal prevails in that discussion. That

[Numpy-discussion] swap elements in two arrays

2010-02-07 Thread Alan G Isaac
I have two 1d arrays, say `a` and `b`. I need to swap elements if a 1d boolean criterion `to_swap` is met. Here's one way: a, b = np.choose([to_swap,np.logical_not(to_swap)], [a, b]) Here is a much faster way: a[to_swap], b[to_swap] = b[to_swap], a[to_swap] Other better ways?

Re: [Numpy-discussion] swap elements in two arrays

2010-02-07 Thread Alan G Isaac
On 2/7/2010 10:21 AM, Alan Isaac wrote: I have two 1d arrays, say `a` and `b`. I need to swap elements if a 1d boolean criterion `to_swap` is met. [clip] Here is a much faster way: a[to_swap], b[to_swap] = b[to_swap], a[to_swap] On 2/7/2010 10:21 AM, Pauli Virtanen wrote: That

Re: [Numpy-discussion] swap elements in two arrays

2010-02-07 Thread Alan G Isaac
On 2/7/2010 11:16 AM, Keith Goodman wrote: Bad: a = np.array([1, 2, 3]) b = a[1:] a[to_swap], b[to_swap] = b[to_swap], a[to_swap] a array([2, 1, 2]) b array([1, 2]) So that is an important point: if `a` and `b` share data, the swap is not well defined. But that

Re: [Numpy-discussion] Installed NumPy and MatPlotLib in the Wrong Order. How uninstall MPL?

2010-02-06 Thread Alan G Isaac
You should be able to have Matplotlib in Python 2.5 and in Python 2.6, no problem. But you need to get the correct installer. There are separate installers for different Pythons. Alan Isaac ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org

Re: [Numpy-discussion] Installed NumPy and MatPlotLib in the Wrong Order. How uninstall MPL?

2010-02-06 Thread Alan G Isaac
On 2/6/2010 9:02 AM, Charles R Harris wrote: I don't know if things have changed, but long ago when I was using windows more often I found it best to delete old installations of python when moving up to later versions. I have had multiple versions running side by side for years, with never a

Re: [Numpy-discussion] multiply a lign matrix with a column matrix should return a scalar( matlab yes, numpy no)!!!

2010-02-03 Thread Alan G Isaac
On 2/3/2010 3:08 AM, laurent.fe...@free.fr wrote: if i multiply two matrix, one with a unique line and the second one with a unique column, i should have a scalar What definition of matrix multiplication is that?? If you really want a scalar product, ask for it:: import numpy as np

Re: [Numpy-discussion] Fixing numpy 1.4.0 ABI breakage, and a plea for self-contained, small commits

2010-01-27 Thread Alan G Isaac
On 1/27/2010 7:57 PM, David Cournapeau wrote: Guido explicitly asked not to break compatibility while staying under py3k, so we should try to do it once numpy has been ported to py3k (e.g. if numpy 1.5 still is not py3k compatible, do a 1.6 before a 2.0 - iterate if necessary:) ). This

Re: [Numpy-discussion] Fixing numpy 1.4.0 ABI breakage, and a plea for self-contained, small commits

2010-01-27 Thread Alan G Isaac
On 1/27/2010 7:57 PM, David Cournapeau wrote: Guido explicitly asked not to break compatibility while staying under py3k, so we should try to do it once numpy has been ported to py3k (e.g. if numpy 1.5 still is not py3k compatible, do a 1.6 before a 2.0 - iterate if necessary:) ). Alan G

Re: [Numpy-discussion] Fixing numpy 1.4.0 ABI breakage, and a plea for self-contained, small commits

2010-01-27 Thread Alan G Isaac
On 1/27/2010 8:56 PM, David Cournapeau wrote: one could make the argument that releasing the API would avoid having to port numpy twice (first to py3k with say numpy 1.5.0, then to the new API for numpy 2.0). But I am not sure it is a big change in practice ? OK, I misunderstood: I thought

[Numpy-discussion] is shuffle needlessly slow?

2010-01-26 Thread Alan G Isaac
Is this a fair test? I expected shuffle to be much faster (no array creation). Alan Isaac import timeit setup = ... import numpy as np ... prng = np.random.RandomState() ... N = 10**5 ... indexes = np.arange(N) ... print timeit.timeit('prng.shuffle(indexes)',setup, number=100)

Re: [Numpy-discussion] is shuffle needlessly slow?

2010-01-26 Thread Alan G Isaac
On 1/26/2010 2:00 PM, Alan G Isaac wrote: Is this a fair test? I expected shuffle to be much faster (no array creation). Alan Isaac import timeit setup = ... import numpy as np ... prng = np.random.RandomState() ... N = 10**5 ... indexes = np.arange(N) ... print timeit.timeit

[Numpy-discussion] fast duplicate of array

2010-01-23 Thread Alan G Isaac
Suppose x and y are conformable 2d arrays. I now want x to become a duplicate of y. I could create a new array: x = y.copy() or I could assign the values of y to x: x[:,:] = y As expected the latter is faster (no array creation). Are there better ways? Thanks, Alan Isaac

[Numpy-discussion] random v. random_state in RandomState

2010-01-23 Thread Alan G Isaac
As I understand it, numpy.random provides the function ``random`` as an alias for ``random_state``. Might this be moved into numpy.random.mtrand.RandomState, for interface consistency? Right now if I start with ``prng = np.random.RandomState(seed=myseed)`` I cannot use ``prng.random`` as it does

Re: [Numpy-discussion] fast duplicate of array

2010-01-23 Thread Alan G Isaac
On 1/23/2010 5:01 PM, Anne Archibald wrote: If both arrays are C contiguous, or more generally contiguous blocks of memory with the same strided structure, you might get faster copying by flattening them first, so that it can go in a single memcpy(). I may misuderstand this. Did you just

Re: [Numpy-discussion] fast duplicate of array

2010-01-23 Thread Alan G Isaac
On 1/23/2010 6:00 PM, Keith Goodman wrote: x = y.view() Thanks, but I'm not looking for a view. And I need x to own its data. Alan ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] fast duplicate of array

2010-01-23 Thread Alan G Isaac
On 1/23/2010 7:29 PM, Anne Archibald wrote: I had in mind accessing the underlying data through views that were flat: In [3]: x = np.random.random((1000,1000)) In [4]: y = np.random.random((1000,1000)) In [5]: xf = x.view() In [6]: xf.shape = (-1,) In [7]: yf = y.view() In [8]:

Re: [Numpy-discussion] TypeError: 'module' object is not callable

2010-01-12 Thread Alan G Isaac
filter(lambda x: x.startswith('eig'),dir(np.linalg)) ['eig', 'eigh', 'eigvals', 'eigvalsh'] import scipy.linalg as spla filter(lambda x: x.startswith('eig'),dir(spla)) ['eig', 'eig_banded', 'eigh', 'eigvals', 'eigvals_banded', 'eigvalsh'] hth, Alan Isaac

Re: [Numpy-discussion] TypeError: 'module' object is not callable

2010-01-12 Thread Alan G Isaac
On 1/12/2010 1:35 AM, Jankins wrote: from scipy.sparse.linalg.eigen import eigen Traceback (most recent call last): File stdin, line 1, inmodule ImportError: cannot import name eigen Look at David's example: from scipy.sparse.linalg import eigen hth, Alan Isaac

[Numpy-discussion] indexing question

2009-12-20 Thread Alan G Isaac
Why is s3 F_CONTIGUOUS, and perhaps equivalently, why is its C_CONTIGUOUS data in s3.base (below)? Thanks, Alan Isaac a3 array([[ 0, 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10, 11]]) a3.flags C_CONTIGUOUS : True F_CONTIGUOUS : False OWNDATA : True WRITEABLE : True ALIGNED :

Re: [Numpy-discussion] dot function or dot notation, matrices, arrays?

2009-12-19 Thread Alan G Isaac
On 12/19/2009 11:45 AM, Wayne Watson wrote: A 4x1, 1x7, and 1x5 would be examples of a 1D array or matrix, right? Are you saying that instead of using a rotational matrix ... that I should use a 2-D array for rotCW? So why does numpy have a matrix class? Is the class only used when working

Re: [Numpy-discussion] dot function or dot notation, matrices, arrays?

2009-12-18 Thread Alan G Isaac
On 12/18/2009 5:54 PM, Keith Goodman wrote: On Fri, Dec 18, 2009 at 2:51 PM, Wayne Watson sierra_mtnv...@sbcglobal.net wrote: That should do it. Thanks. How do I get the scalar result by itself? np.dot(x.T,x)[0,0] 14 or x = np.array([1,2,3]) np.dot(x,x) 14 or

Re: [Numpy-discussion] dot function or dot notation, matrices, arrays?

2009-12-18 Thread Alan G Isaac
On 12/18/2009 7:12 PM, Wayne Watson wrote: The point of the scalar product is to produce theta. As David said, that is just NumPy's `dot`. a = np.array([0,2]) b = np.array([5,0]) theta = np.arccos(np.dot(a,b)/np.sqrt(np.dot(a,a)*np.dot(b,b))) theta 1.5707963267948966 theta/np.pi 0.5 hth,

[Numpy-discussion] fsum

2009-12-16 Thread Alan G Isaac
Does NumPy have an equivalent to Python's math.fsum? Thanks, Alan Isaac ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] Proposal for matrix_rank function in numpy

2009-12-15 Thread Alan G Isaac
On 12/15/2009 1:39 PM, Bruce Southey wrote: +1 for the function but we can not shorten the name because of existing numpy.rank() function. 1. Is it a rule that there cannot be a name duplication in this different namespace? 2. Is there a commitment to keeping both np.rank and np.ndim? (I.e.,

Re: [Numpy-discussion] How to solve homogeneous linear equations with NumPy?

2009-12-05 Thread Alan G Isaac
On 12/3/2009 12:40 AM, Peter Cai wrote: If I have homogeneous linear equations like this array([[-0.75, 0.25, 0.25, 0.25], [ 1. , -1. , 0. , 0. ], [ 1. , 0. , -1. , 0. ], [ 1. , 0. , 0. , -1. ]]) And I want to get a non-zero solution for it. How

Re: [Numpy-discussion] boolean arrays

2009-11-26 Thread Alan G Isaac
On 11/26/2009 8:20 AM, Nils Wagner wrote: a = array(([True,True],[True,True])) b = array(([False,False],[False,False])) a+b NumPy's boolean operations are very well behaved. a = np.array(([True,True],[True,True])) a+a array([[ True, True], [ True, True]], dtype=bool) Compare

Re: [Numpy-discussion] How to get rid of the loop?

2009-11-07 Thread Alan G Isaac
On 11/7/2009 1:51 PM, Stas K wrote: Can I get rid of the loop in this example? And what is the fastest way to get v in the example? ar = array([1,2,3]) for a in ar: for b in ar: v = a**2+b**2 a2 = a*a np.add.outer(a2,a2) array([[ 2, 5, 10], [ 5, 8, 13],

Re: [Numpy-discussion] initializing an array of lists

2009-11-07 Thread Alan G Isaac
On 11/7/2009 10:56 PM, a...@ajackson.org wrote: I want to build a 2D array of lists, and so I need to initialize the array with empty lists : myarray = array([[[],[],[]] ,[[],[],[]]]) [[[] for i in range(3)] for j in range(2) ] fwiw, Alan Isaac

Re: [Numpy-discussion] converting discrete data to unique integers

2009-11-04 Thread Alan G Isaac
On 11/4/2009 3:09 PM, David Warde-Farley wrote: I'd like to map every unique element (these could be strings, objects, or already ints) to a unique integer between 0 and len(unique(d)) - 1. mymap = dict((k,v) for v,k in enumerate(set(a))) fwiw, Alan Isaac

Re: [Numpy-discussion] Multiplicity of an entry

2009-10-26 Thread Alan G Isaac
On 10/26/2009 4:04 AM, Nils Wagner wrote: how can I obtain the multiplicity of an entry in a list a = ['abc','def','abc','ghij'] That's a Python question, not a NumPy question. So comp.lang.python would be a better forum. But here's a simplest solution:: a = ['abc','def','abc','ghij'] for

Re: [Numpy-discussion] GSOC 2010

2009-10-21 Thread Alan G Isaac
On 10/21/2009 3:23 PM, Charles R Harris wrote: What exactly *was* the history of that project and what can we learn from it? Imo, what really drove this project forward, is that Skipper was able to interact regularly with someone else who was actively using and developing on the code base

Re: [Numpy-discussion] NumPy SVN broken

2009-10-07 Thread Alan G Isaac
On 10/7/2009 10:57 PM, Robert Kern wrote: it's pimpl OK: http://en.wikipedia.org/wiki/Opaque_pointer Thanks, Alan Isaac ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] Tuple outer product?

2009-09-25 Thread Alan G Isaac
On 9/25/2009 1:45 PM, Mads Ipsen wrote: Is there a numpy operation on two arrays, say [1,2,3] and [4,5,6], that will yield: [[(1,4),(1,5),(1,6)],[(2,4),(2,5),(2,6)],[(3,4),(3,5),(3,6)]] from itertools import product list(product([1,2,3],[4,5,6])) [(1, 4), (1, 5), (1, 6), (2, 4), (2, 5),

Re: [Numpy-discussion] Tuple outer product?

2009-09-25 Thread Alan G Isaac
I do not see what is wrong with itertools.product, but if you hate it, you can use numpy.meshgrid: np.array(np.meshgrid([1,2,3],[4,5,6])).transpose() array([[[1, 4], [1, 5], [1, 6]], [[2, 4], [2, 5], [2, 6]], [[3, 4], [3, 5],

Re: [Numpy-discussion] Tuple outer product?

2009-09-25 Thread Alan G Isaac
On 9/25/2009 4:01 PM, Mads Ipsen wrote: a = numpy.array([1,2,3]) b = numpy.array([4,5,6]) (n,m) = (a.shape[0],b.shape[0]) a = numpy.repeat(a,m).reshape(n,m) b = numpy.repeat(b,n).reshape(m,n).transpose() ab = numpy.dstack((a,b)) print ab.tolist() That's just a slow implementation of

Re: [Numpy-discussion] Tuple outer product?

2009-09-25 Thread Alan G Isaac
OK, sure, for large arrays meshgrid will look bad. (It creates a large array twice.) If the example really involves sequential integers, then mgrid could be used instead to save on this. Even so, it is just implausible that duplicating meshgrid functionality will be faster than using meshgrid.

Re: [Numpy-discussion] Tuple outer product?

2009-09-25 Thread Alan G Isaac
Alan G Isaac wrote: That's just a slow implementation of meshgrid: np.meshgrid(a,b).transpose().tolist() Gives you the same thing. On 9/25/2009 6:38 PM, Mads Ipsen wrote: Yes, but it should also work for [2.1,3.2,4.5] combined with [4.6,-2.3,5.6] - forgot to tell that. No problem

Re: [Numpy-discussion] Simple pattern recognition

2009-09-16 Thread Alan G Isaac
On 9/16/2009 8:22 PM, Gökhan Sever wrote: I want to be able to count predefined simple rectangle shapes on an image as shown like in this one: http://img7.imageshack.us/img7/2327/particles.png ch.9 of

Re: [Numpy-discussion] exec: bad practice?

2009-09-15 Thread Alan G Isaac
On 9/15/2009 7:07 AM, Sebastien Binet wrote: usage of the exec statement is usually frown upon and can be side stepped. e.g: for m in meat: for c in cut: locals()['consumed_%s_%s' % (m,c)] = some_array Additionally, name construction can be pointless. Maybe:: info = dict() for

<    1   2   3   4   5   6   7   >