[Numpy-discussion] numpy.r_[True, False] is not a boolean array
Hello, I observe the following behavior: numpy.r_[True, False] - array([1, 0], dtype=int8) numpy.r_[True] - array([ True], dtype=bool) I would expect the first line to give a boolean array: array([ True, False], dtype=bool) Is it normal? Is it a bug? -- O.C. numpy.__version__ = '1.4.1' ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] itertools.combinations to numpy
On Fri, Dec 3, 2010 at 6:31 AM, Mario Moura moura.ma...@gmail.com wrote: Hi Folks I have this situation from timeit import Timer reps = 5 t = Timer('itertools.combinations(range(1,10),3)', 'import itertools') print sum(t.repeat(repeat=reps, number=1)) / reps 1.59740447998e-05 t = Timer('itertools.combinations(range(1,100),3)', 'import itertools') print sum(t.repeat(repeat=reps, number=1)) / reps 1.74999237061e-05 t = Timer('list(itertools.combinations(range(1,10),3))', 'import itertools') print sum(t.repeat(repeat=reps, number=1)) / reps 5.31673431396e-05 t = Timer('list(itertools.combinations(range(1,100),3))', 'import itertools') print sum(t.repeat(repeat=reps, number=1)) / reps 0.0556231498718 You can see list(itertools.combinations(range(1,100),3)) is terrible!! If you change to range(1,10) your computer will lock. So I would like to know a good way to convert itertools.combinations object to ndarray? fast! without use list Is it possible? x = itertools.combinations(range(1,10),3) x itertools.combinations object at 0x25f1520 I tried this from http://docs.python.org/library/itertools.html?highlight=itertools#itertools.combinations numpy.fromiter(itertools.combinations(range(1,10),3), int, count=-1) Traceback (most recent call last): File stdin, line 1, in module ValueError: setting an array element with a sequence. and this from http://docs.python.org/library/itertools.html?highlight=itertools#itertools.combinations import numpy from itertools import * from numpy import * def combinations(iterable, r): pool = tuple(iterable) n = len(pool) for indices in permutations(range(n), r): if sorted(indices) == list(indices): yield tuple(pool[i] for i in indices) numpy.fromiter(combinations(range(1,10),3), int, count=-1) numpy.fromiter(combinations(range(1,10),3), int, count=-1) Traceback (most recent call last): File stdin, line 1, in module ValueError: setting an array element with a sequence. I like itertools.combinations performance but I need convert it to numpy. The docstring for numpy.fromiter() says it creates a 1D array. You can use it with itertools.combinations if you specify a dtype for a 1D structured array. Here's an example (I'm using ipython with the -pylab option, so the numpy functions have all been imported): In [1]: from itertools import combinations In [2]: dt = dtype('i,i,i') In [3]: a = fromiter(combinations(range(100),3), dtype=dt, count=-1) In [4]: b = array(list(combinations(range(100),3))) In [5]: all(a.view(int).reshape(-1,3) == b) Out[5]: True In [6]: timeit a = fromiter(combinations(range(100),3), dtype=dt, count=-1) 10 loops, best of 3: 92.7 ms per loop In [7]: timeit b = array(list(combinations(range(100),3))) 1 loops, best of 3: 627 ms per loop In [8]: a[:3] Out[8]: array([(0, 1, 2), (0, 1, 3), (0, 1, 4)], dtype=[('f0', 'i4'), ('f1', 'i4'), ('f2', 'i4')]) In [9]: b[:3] Out[9]: array([[0, 1, 2], [0, 1, 3], [0, 1, 4]]) In the above example, 'a' is a 1D structured array; each element of 'a' holds one of the combinations. If you need it, you can create a 2D view with a.view(int).reshape(-1,3). Warren ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] [PATCH] gfortran under macports
Hi all. Macports installs gfortran as part of the gcc package, but names it gfortran-mp-$version, without providing a symbolic link to a default gcfortran executable, and thus numpy.distutils is unable to find the right executable. The attached patch very simple, it just extends possible_executables with those names, but makes the build of scipy work without having to restore to obscure fc_config flags. Fabian. 0001-FIX-recognize-macports-gfortran-compiler.patch Description: Binary data ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpy.test() Program received signal SIGABRT, Aborted.
On Fri, Dec 3, 2010 at 12:56 AM, Nils Wagner nwag...@iam.uni-stuttgart.dewrote: On Fri, 03 Dec 2010 08:47:32 +0100 Nils Wagner nwag...@iam.uni-stuttgart.de wrote: On Fri, 3 Dec 2010 00:42:16 -0700 Charles R Harris charlesr.har...@gmail.com wrote: On Fri, Dec 3, 2010 at 12:29 AM, Nils Wagner nwag...@iam.uni-stuttgart.dewrote: Hi all, I have installed the latest version of numpy. numpy.__version__ '2.0.0.dev-6aacc2d' I don't see that here or on the buildbots. There was a problem with segfaults that was fixed in commit c0e1cf27b55dfd5a https://github.com/numpy/numpy/commit/c0e1cf27b55dfd5aa4b1674a8c1b6ac38c36 Can you check that your installation is clean, etc. Also, what platform are you running on? I have removed the build directory. Is it also neccessary to remove numpy in thr installation directory ? /data/home/nwagner/local/lib/python2.5/site-packages/ Platform 2.6.18-92.el5 #1 SMP Tue Jun 10 18:51:06 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux Nils ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion I have also removed the numpy directory within /data/home/nwagner/local/lib/python2.5/site-packages/. Now all tests pass. Ran 3080 tests in 12.288s OK (KNOWNFAIL=4, SKIP=1) nose.result.TextTestResult run=3080 errors=0 failures=0 Great. How is the build process implemented on the build bots ? I don't know the details, but it looks to me like they do a clean checkout and fresh install. Chuck ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] [PATCH] gfortran under macports
Hi Fabian, On Fri, Dec 3, 2010 at 8:24 AM, Fabian Pedregosa fabian.pedreg...@inria.frwrote: Hi all. Macports installs gfortran as part of the gcc package, but names it gfortran-mp-$version, without providing a symbolic link to a default gcfortran executable, and thus numpy.distutils is unable to find the right executable. The attached patch very simple, it just extends possible_executables with those names, but makes the build of scipy work without having to restore to obscure fc_config flags. Can you open a ticket for this so it doesn't get lost? Chuck ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] itertools.combinations to numpy
Hi Mr. Weckesser Thanks a lot! Works fine! Regards Mario 2010/12/3 Warren Weckesser warren.weckes...@enthought.com: On Fri, Dec 3, 2010 at 6:31 AM, Mario Moura moura.ma...@gmail.com wrote: Hi Folks I have this situation from timeit import Timer reps = 5 t = Timer('itertools.combinations(range(1,10),3)', 'import itertools') print sum(t.repeat(repeat=reps, number=1)) / reps 1.59740447998e-05 t = Timer('itertools.combinations(range(1,100),3)', 'import itertools') print sum(t.repeat(repeat=reps, number=1)) / reps 1.74999237061e-05 t = Timer('list(itertools.combinations(range(1,10),3))', 'import itertools') print sum(t.repeat(repeat=reps, number=1)) / reps 5.31673431396e-05 t = Timer('list(itertools.combinations(range(1,100),3))', 'import itertools') print sum(t.repeat(repeat=reps, number=1)) / reps 0.0556231498718 You can see list(itertools.combinations(range(1,100),3)) is terrible!! If you change to range(1,10) your computer will lock. So I would like to know a good way to convert itertools.combinations object to ndarray? fast! without use list Is it possible? x = itertools.combinations(range(1,10),3) x itertools.combinations object at 0x25f1520 I tried this from http://docs.python.org/library/itertools.html?highlight=itertools#itertools.combinations numpy.fromiter(itertools.combinations(range(1,10),3), int, count=-1) Traceback (most recent call last): File stdin, line 1, in module ValueError: setting an array element with a sequence. and this from http://docs.python.org/library/itertools.html?highlight=itertools#itertools.combinations import numpy from itertools import * from numpy import * def combinations(iterable, r): pool = tuple(iterable) n = len(pool) for indices in permutations(range(n), r): if sorted(indices) == list(indices): yield tuple(pool[i] for i in indices) numpy.fromiter(combinations(range(1,10),3), int, count=-1) numpy.fromiter(combinations(range(1,10),3), int, count=-1) Traceback (most recent call last): File stdin, line 1, in module ValueError: setting an array element with a sequence. I like itertools.combinations performance but I need convert it to numpy. The docstring for numpy.fromiter() says it creates a 1D array. You can use it with itertools.combinations if you specify a dtype for a 1D structured array. Here's an example (I'm using ipython with the -pylab option, so the numpy functions have all been imported): In [1]: from itertools import combinations In [2]: dt = dtype('i,i,i') In [3]: a = fromiter(combinations(range(100),3), dtype=dt, count=-1) In [4]: b = array(list(combinations(range(100),3))) In [5]: all(a.view(int).reshape(-1,3) == b) Out[5]: True In [6]: timeit a = fromiter(combinations(range(100),3), dtype=dt, count=-1) 10 loops, best of 3: 92.7 ms per loop In [7]: timeit b = array(list(combinations(range(100),3))) 1 loops, best of 3: 627 ms per loop In [8]: a[:3] Out[8]: array([(0, 1, 2), (0, 1, 3), (0, 1, 4)], dtype=[('f0', 'i4'), ('f1', 'i4'), ('f2', 'i4')]) In [9]: b[:3] Out[9]: array([[0, 1, 2], [0, 1, 3], [0, 1, 4]]) In the above example, 'a' is a 1D structured array; each element of 'a' holds one of the combinations. If you need it, you can create a 2D view with a.view(int).reshape(-1,3). Warren ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Float16 and PEP 3118
On Thu, Dec 2, 2010 at 10:16 AM, Pauli Virtanen p...@iki.fi wrote: Before introducing a PEP 3118 type code for half floats in the PEP, one would need to argue the Python people to add it to the struct module. Before that, the choices probably are: - refuse to export buffers containing half floats I think this is the better option, code that needs to do this can create an int16 view for the time being. - export half floats as two bytes This would throw away the byte-order, a problem much harder to track down for the user than the other option. -Mark ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Float16 and PEP 3118
Fri, 03 Dec 2010 09:23:15 -0800, Mark Wiebe wrote: [clip] - refuse to export buffers containing half floats I think this is the better option, code that needs to do this can create an int16 view for the time being. That's also easier to implement -- no changes are needed :) Pauli ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion