[Numpy-discussion] (no subject)
Hi, I would like to make a sanity test to check that calling the same function with different parameters actually gives different results. I am currently using:: try: npt.assert_almost_equal(numpy_result, result) except AssertionError: assert True else: assert False But maybe you have a better way? I couldn't find a 'assert_not_equal' and the above just feels stupid. thanks for your advice. V- -- Valentin Hänel Scientific Software Developer Blue Brain Project http://bluebrain.epfl.ch/ ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] (no subject)
Not sure if there's a better way, but you can do it with assert not numpy.allclose(numpy_result, result) -=- Olivier 2012/1/20 Hänel Nikolaus Valentin valentin.hae...@epfl.ch Hi, I would like to make a sanity test to check that calling the same function with different parameters actually gives different results. I am currently using:: try: npt.assert_almost_equal(numpy_result, result) except AssertionError: assert True else: assert False But maybe you have a better way? I couldn't find a 'assert_not_equal' and the above just feels stupid. thanks for your advice. V- -- Valentin Hänel Scientific Software Developer Blue Brain Project http://bluebrain.epfl.ch/ ___ 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] (no subject)
* Olivier Delalleau sh...@keba.be [120120]: Not sure if there's a better way, but you can do it with assert not numpy.allclose(numpy_result, result) Okay, thats already better than what I have. thanks V- ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Cross-covariance function
Hi Eliot, Le 19/01/2012 07:50, Elliot Saba a écrit : I recently needed to calculate the cross-covariance of two random vectors, (e.g. I have two matricies, X and Y, the columns of which are observations of one variable, and I wish to generate a matrix pairing each value of X and Y) I don't see how does your function relates to numpy.cov [1]. Is it an extended case function or is there a difference in the underlying math ? Best, Pierre [1] numpy.cov docstring : http://docs.scipy.org/doc/numpy/reference/generated/numpy.cov.html ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] getting position index from array
Exactly what I need - thank you very much. Ruby On Thu, Jan 19, 2012 at 11:33 PM, Benjamin Root ben.r...@ou.edu wrote: On Thursday, January 19, 2012, Ruby Stevenson ruby...@gmail.com wrote: hi, all I am a newbie on numpy ... I am trying to figure out, given an array, how to get back position value based on some conditions. Say, array([1, 0, 0, 0 1], and I want to get a list of indices where it is none-zero, [ 0 , 4 ] The closest thing I can find from the doc is select(), but I can't figure out how to use it properly. Thanks for your help. Ruby np.nonzero() Note that you typically use it with a Boolean array result like a = 4. Also note that it returns a tuple of index lists, on for each dimension. This can the be feed back into the array to get the values as a flat array. Ben Root ___ 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
[Numpy-discussion] condense array along one dimension
hi, all Say I have a three dimension array, X, Y, Z, how can I condense into two dimensions: for example, compute 2-D array with (X, Z) and summarize along Y dimensions ... is it possible? thanks Ruby ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] condense array along one dimension
What do you mean by summarize? If for instance you want to sum along Y, just do my_array.sum(axis=1) -=- Olivier 2012/1/20 Ruby Stevenson ruby...@gmail.com hi, all Say I have a three dimension array, X, Y, Z, how can I condense into two dimensions: for example, compute 2-D array with (X, Z) and summarize along Y dimensions ... is it possible? thanks Ruby ___ 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] Cross-covariance function
Den 20.01.2012 13:39, skrev Pierre Haessig: I don't see how does your function relates to numpy.cov [1]. Is it an extended case function or is there a difference in the underlying math ? If X is rank n x p, then np.cov(X, rowvar=False) is equal to S after cX = X - X.mean(axis=0)[np.newaxis,:] S = np.dot(cX.T, cX)/(n-1.) If we also have Y rank n x p, then the upper p x p quadrant of np.cov(X, y=Y, rowvar=False) is equal to S after XY = np.hstack(X,Y) cXY = XY - XY.mean(axis=0)[np.newaxis,:] S = np.dot(cXY.T, cXY)/(n-1.) Thus we can see thatthe total cocariance is composed of four parts: S[:p,:p] = np.dot(cX.T, cX)/(n-1.) # upper left S[:p,p:] = np.dot(cXY.T, cYY)/(n-1.) # upper right S[p:,:p] = np.dot(cY.T, cX)/(n-1.) # lower left S[p:,:p] = np.dot(cYX.T, cYX)/(n-1.) # lower right Often we just want the upper-right p x p quadrant. Thus we can save 75 % of the cpu time by not computing the rest. Sturla ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Upgrade to 1.6.x: frompyfunc() ufunc casting issue
Hi everyone, A long time ago, Aditya Sethi ady.sethi@gmail... wrote: I am facing an issue upgrading numpy from 1.5.1 to 1.6.1. In numPy 1.6, the casting behaviour for ufunc has changed and has become stricter. Can someone advise how to implement the below simple example which worked in 1.5.1 but fails in 1.6.1? import numpy as np def add(a,b): ...return (a+b) uadd = np.frompyfunc(add,2,1) uadd ufunc 'add (vectorized)' uadd.accumulate([1,2,3]) Traceback (most recent call last): File stdin, line 1, in module ValueError: could not find a matching type for add (vectorized).accumulate, requested type has type code 'l' Here's the workaround I found to that problem: uadd.accumulate([1,2,3], dtype='object') array([1, 3, 6], dtype=object) It seems like accumulate infers that 'l' is the required output dtype, but does not have the appropriate implementation: uadd.types ['OO-O'] Forcing the output dtype to be 'object' (the only supported dtype) seems to do the trick. Hope this helps, -- Pascal ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion