Re: [Numpy-discussion] sum and prod
Hi, On Sun, Sep 9, 2012 at 12:56 AM, nicky van foreest wrote: > Hi, > > I ran the following code: > > args = np.array([4,8]) > print np.sum( (arg > 0) for arg in args) > print np.sum([(arg > 0) for arg in args]) > print np.prod( (arg > 0) for arg in args) > print np.prod([(arg > 0) for arg in args]) > Can't see why someone would write code like above, but anyway: In []: args = np.array([4,8]) In []: print np.sum( (arg > 0) for arg in args) 2 In []: print np.sum([(arg > 0) for arg in args]) 2 In []: print np.prod( (arg > 0) for arg in args) at 0x062BDA08> In []: print np.prod([(arg > 0) for arg in args]) 1 In []: print np.prod( (arg > 0) for arg in args).next() True In []: sys.version Out[]: '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]' In []: np.version.version Out[]: '1.6.0' My 2 cents, -eat > > with this result: > > 2 > 1 > at 0x1c70410> > 1 > > Is the difference between prod and sum intentional? I would expect > that numpy.prod would also work on a generator, just like numpy.sum. > > BTW: the last line does what I need: the product over the truth values > of all elements of args. Is there perhaps a nicer (conciser) way to > achieve this? Thanks. > > Nicky > ___ > 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] sum and prod
On Sat, Sep 8, 2012 at 4:56 PM, nicky van foreest wrote: > Hi, > > I ran the following code: > > args = np.array([4,8]) > print np.sum( (arg > 0) for arg in args) > print np.sum([(arg > 0) for arg in args]) > print np.prod( (arg > 0) for arg in args) > print np.prod([(arg > 0) for arg in args]) > > with this result: > > 2 > 1 > I get 2 here, not 1 (numpy version 1.6.1). > at 0x1c70410> > 1 > > Is the difference between prod and sum intentional? I would expect > that numpy.prod would also work on a generator, just like numpy.sum. > Whatever the correct result may be, I would expect them to have the same behavior with respect to a generator argument. > BTW: the last line does what I need: the product over the truth values > of all elements of args. Is there perhaps a nicer (conciser) way to > achieve this? Thanks. > How about: In [15]: np.all(args > 0) Out[15]: True Warren > Nicky > ___ > 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] sum and prod
Hi, Maybe try something like this? >>> args = np.array([4,8]) >>> np.prod(args > 0) 1 >>> np.sum(args > 0) 2 Cheers, Han ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] sum and prod
Hi, I ran the following code: args = np.array([4,8]) print np.sum( (arg > 0) for arg in args) print np.sum([(arg > 0) for arg in args]) print np.prod( (arg > 0) for arg in args) print np.prod([(arg > 0) for arg in args]) with this result: 2 1 at 0x1c70410> 1 Is the difference between prod and sum intentional? I would expect that numpy.prod would also work on a generator, just like numpy.sum. BTW: the last line does what I need: the product over the truth values of all elements of args. Is there perhaps a nicer (conciser) way to achieve this? Thanks. Nicky ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] problem with scipy's test
On Wed, Sep 5, 2012 at 6:57 PM, 心如烛光 <275438...@qq.com> wrote: > Hi,every body. > I encounter the error while the scipy is testing . > I wanna know why and how to fix it.(OSX lion 10.7.4) > here is part of the respond: > See http://thread.gmane.org/gmane.comp.python.scientific.devel/15289/focus=15297 Seems hard to fix. Using gfortran 4.4 is a workaround. Ralf > > AssertionError: > Not equal to tolerance rtol=4.44089e-13, atol=4.44089e-13 > error for eigsh:general, typ=d, which=SA, sigma=0.5, mattype=asarray, > OPpart=None, mode=buckling > (mismatch 100.0%) > x: array([[ 15.86892331, 0.0549568 ], >[ 14.15864153, 0.31381369], >[ 10.99691307, 0.37543458],... > y: array([[ 3.19549052, 0.0549568 ], >[ 2.79856422, 0.31381369], >[ 1.67526354, 0.37543458],... > > == > FAIL: test_arpack.test_symmetric_modes(True, , 'd', 2, > 'SA', None, 0.5, , None, 'cayley') > -- > Traceback (most recent call last): > File > "/Library/Python/2.7/site-packages/nose-1.1.2-py2.7.egg/nose/case.py", line > 197, in runTest > self.test(*self.arg) > File > "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py", > line 249, in eval_evec > assert_allclose(LHS, RHS, rtol=rtol, atol=atol, err_msg=err) > File > "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/utils.py", > line 1178, in assert_allclose > verbose=verbose, header=header) > File > "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/utils.py", > line 644, in assert_array_compare > raise AssertionError(msg) > AssertionError: > Not equal to tolerance rtol=4.44089e-13, atol=4.44089e-13 > error for eigsh:general, typ=d, which=SA, sigma=0.5, mattype=asarray, > OPpart=None, mode=cayley > (mismatch 100.0%) > x: array([[-0.36892684, -0.01935691], >[-0.26850996, -0.11053158], >[-0.40976156, -0.13223572],... > y: array([[-0.43633077, -0.01935691], >[-0.25161386, -0.11053158], >[-0.36756684, -0.13223572],... > > -- > Ran 5501 tests in 56.993s > > FAILED (KNOWNFAIL=13, SKIP=42, failures=76) > > > ___ > 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