[Numpy-discussion] dimension along axis?
Hi all, It there a convenience way to get dimension along an axis? Say I have two ndarray: li1 = np.array([2,3,4]) li2 = np.array([[2,3,4],[5,6,7]]) I know my list is in C order so the two array is the same in someway. But li1.shape will give (3, ) and li2.shape will give (2,3). 3 appear in different position so it's inconvenient to identify them. Is there anyway to get dimension along axis? (In this case should be axis0) -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] dimension along axis?
On Tue, Apr 14, 2009 at 09:47, Charles R Harris charlesr.har...@gmail.comwrote: You mean something like this? In [1]: li1 = np.array([2,3,4]) In [2]: li1[np.newaxis,:].shape Out[2]: (1, 3) Or maybe like this? In [3]: li1 = np.array([[2,3,4]]) In [4]: li1.shape Out[4]: (1, 3) Chuck This is exactly what I want. Thanks ;) -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] DVCS at PyCon
On Thu, Apr 9, 2009 at 21:38, Matthieu Brucher matthieu.bruc...@gmail.comwrote: 2009/4/9 David Cournapeau courn...@gmail.com: On Wed, Apr 8, 2009 at 3:34 AM, Ondrej Certik ond...@certik.cz wrote: Yes. Do you have any windows developers (I am sorry, I am not familiar at all with sympy)? My main concern with git are: - you may need the command line - the index can be confusing (you can avoid learning it at first, but still some errors won't make sense before you get it). - git is not discoverable (you need to read some documentation) I tried to install git on my computer, as git-svn seemed so nice. I tried git-svn and it told me that some .pm files are missing. Why did it install git-svn if some files are missing? And why isn't it possible to get some information on how to install those missing files on the Internet. git seems nice, but lacks documentation and usability :| Matthieu The saying that git lacks documentation and usability was a long-long ago history in my eyes. Although I'm not a sympy developer nor numpy developer but I use git for my own project and enjoy working with it. You may find some useful documentation here: http://git-scm.com/ and a tutorial: http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html What really lacks is a little bit learning and using. -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] using assertEqual in unittest to test two np.ndarray?
On Sat, Mar 21, 2009 at 10:15, josef.p...@gmail.com wrote: The testing assert functions are not well documented, I usually just use assert_array_almost_equal with decimal precision for float arrays. useful is also assert_() which is better than the assert statement since it survives optimization flag for python compile. You can browse the help editor http://docs.scipy.org/numpy/docs/numpy.testing.utils/ To see the precise definition and difference between the different asserts you have to check the source, source button on editor page. There are also the http://projects.scipy.org/numpy/wiki/TestingGuidelines , if you haven't seen them yet, they describe the general test setup with nose but not the assert functions. Josef If you know where to look there is some information: help(numpy.testing.utils) Help on module numpy.testing.utils in numpy.testing: NAME numpy.testing.utils - Utility function to facilitate testing. FILE c:\programs\python25\lib\site-packages\numpy\testing\utils.py FUNCTIONS assert_almost_equal(actual, desired, decimal=7, err_msg='', verbose=True) Raise an assertion if two items are not equal. I think this should be part of unittest.py The test i ... Thanks really~ It helped a lot. ;) -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] using assertEqual in unittest to test two np.ndarray?
Hi all, When I try to use assertEqual in unittest to test my numpy codes I got this: == ERROR: test_test (__main__.Test_data_ana) -- Traceback (most recent call last): File ./unit_test.py, line 24, in test_test [4, 5, 6]])) File /usr/lib/python2.5/unittest.py, line 332, in failUnlessEqual if not first == second: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() -- Ran 2 tests in 0.003s FAILED (errors=1) I know I should use array_equal to test two arrays but it will be more convenient to implement it as __eq__. Any hints? Thanks in advance. -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] using assertEqual in unittest to test two np.ndarray?
On Sat, Mar 21, 2009 at 05:03, josef.p...@gmail.com wrote: for testing purposes it is available in numpy testing: from numpy.testing import assert_equal, assert_almost_equal, assert_array_equal a = np.array([ 1., 2., np.NaN, 4.]) assert_array_equal(a,a) does not raise AssertionError assert_array_equal(a,a+1) Traceback (most recent call last): File pyshell#6, line 1, in module assert_array_equal(a,a+1) File C:\Programs\Python25\lib\site-packages\numpy\testing\utils.py, line 303, in assert_array_equal verbose=verbose, header='Arrays are not equal') File C:\Programs\Python25\lib\site-packages\numpy\testing\utils.py, line 295, in assert_array_compare raise AssertionError(msg) AssertionError: Arrays are not equal (mismatch 100.0%) x: array([ 1., 2., NaN, 4.]) y: array([ 2., 3., NaN, 5.]) Great! Thanks! In my case, a NaN is indicating something goes wrong and I want testing fail on it. So it meet my demand. One thing more, when I help(np.testing) I only got this: = Help on package numpy.testing in numpy: NAME numpy.testing - Common test support for all numpy test scripts. FILE /usr/lib/python2.5/site-packages/numpy/testing/__init__.py DESCRIPTION This single module should provide all the common functionality for numpy tests in a single location, so that test scripts can just import it and work right away. PACKAGE CONTENTS decorators noseclasses nosetester nulltester numpytest parametric setup setupscons utils DATA verbose = 0 So I have to dir it to see is there any other useful functions. It will be perfect to document package method like assert_equal here. Thanks very much~;) -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] linalg.norm along axis?
Hi all, Is there any possibility to calculate norm along axis? For example: a = np.array(( (3,4), (6,8))) And I want to get: array([5.0, 10.0]) I currently use a for loop to achieve this, Is there any more elegant way to do this? -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] linalg.norm along axis?
On Thu, Feb 19, 2009 at 12:12, Nicolas Pinto pi...@mit.edu wrote: Grissiom, Using the following doesn't require any loop: In [9]: sqrt((a**2.).sum(1)) Out[9]: array([ 5., 10.]) Best, Got it~ Thanks really ;) -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] minor improvment to ones
On Fri, Jan 30, 2009 at 21:54, Scott Sinclair scott.sinclair...@gmail.comwrote: 2009/1/30 David Cournapeau da...@ar.media.kyoto-u.ac.jp: Neal Becker wrote: A nit, but it would be nice if 'ones' could fill with a value other than 1. Maybe an optional val= keyword? What would be the advantage compared to fill ? I would guess ones and zeros are special because those two values are special (they can be defined for many types, as neutral elements for + and *), I couldn't find the numpy fill function, until my tiny brain realized you meant the ndarray method: http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.fill.html Cheers, Scott Is fill function has any advantage over ones(size)*x ? -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] minor improvment to ones
On Fri, Jan 30, 2009 at 22:16, Sturla Molden stu...@molden.no wrote: On 1/30/2009 3:07 PM, Grissiom wrote: Is fill function has any advantage over ones(size)*x ? You avoid filling with ones, all the multiplications and creating an temporary array. It can be done like this: a = empty(size) a[:] = x Which would be slightly faster and more memory efficient. Hmm, I +1 on this one. It's more pythonic ;) -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Numpy performance vs Matlab.
On Wed, Jan 7, 2009 at 23:44, Ryan May rma...@gmail.com wrote: Nicolas ROUX wrote: Hi, I need help ;-) I have here a testcase which works much faster in Matlab than Numpy. The following code takes less than 0.9sec in Matlab, but 21sec in Python. Numpy is 24 times slower than Matlab ! The big trouble I have is a large team of people within my company is ready to replace Matlab by Numpy/Scipy/Matplotlib, but I have to demonstrate that this kind of Python Code is executed with the same performance than Matlab, without writing C extension. This is becoming a critical point for us. This is a testcase that people would like to see working without any code restructuring. The reasons are: - this way of writing is fairly natural. - the original code which showed me the matlab/Numpy performance differences is much more complex, and can't benefit from broadcasting or other numpy tips (I can later give this code) ...So I really need to use the code below, without restructuring. Numpy/Python code: # import numpy import time print Start test \n dim = 3000 a = numpy.zeros((dim,dim,3)) start = time.clock() for i in range(dim): for j in range(dim): a[i,j,0] = a[i,j,1] a[i,j,2] = a[i,j,0] a[i,j,1] = a[i,j,2] end = time.clock() - start print Test done, %f sec % end # SNIP Any idea on it ? Did I missed something ? I think you may have reduced the complexity a bit too much. The python code above sets all of the elements equal to a[i,j,1]. Is there any reason you can't use slicing to avoid the loops? Yes, I think so. I think the testcase is a matter of python loop vs matlab loop rather than python vs matlab. -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Failing to build numpy properly on Ubuntu Hardy
On Thu, Dec 11, 2008 at 06:10, Gael Varoquaux [EMAIL PROTECTED] wrote: Hi all, Looks like I am following the long line of people failing to build numpy :). I must admit I am clueless with building problems. Numpy builds alright, but I get: ImportError: /usr/lib/sse2/atlas/libblas.so.3gf: undefined symbol: _gfortran_st_write_done On import. This used to work a while ago. I am not sure what I changed, but it sure does fail. I really don't understand where the gfortran comes in. I tried building numpy with or without gfortran. From what I gather it is the numpy is being built by a different compiler than the atlas libraries (hurray for ABI compatibility), but I don't really understand how this is possible. How can I debug this? Cheers, Gaƫl I have encountered with such problem before. My solution is recompile the problem package(maybe atlas in your case) with -ff2c option passed to gfortran. -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Failing to build numpy properly on Ubuntu Hardy
On Thu, Dec 11, 2008 at 15:13, David Cournapeau [EMAIL PROTECTED] wrote: Grissiom wrote: I have encountered with such problem before. My solution is recompile the problem package(maybe atlas in your case) with -ff2c option passed to gfortran. This is a bad idea: it won't work with libraries which are not built with this option, and the error won't always be easy to detect (one key difference is that wo ff2c, complex variables are passed by value by gfortran, whereas they are passed by reference with the ff2c option - which means crash and/or corruption). http://wiki.debian.org/GfortranTransition The only viable solution is to avoid mixing g77-built and gfortran-built libraries (there is now a simple test which tries to detect those mix in both numpy and scipy), cheers, David Thanks for pointing out my mistake ;) -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] How to unitize a array in numpy?
Hi all, Nice to neet you all. I am a newbie in numpy. Is there any function that could unitize a array? Thanks in advance. -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] How to unitize a array in numpy?
On Wed, Dec 10, 2008 at 10:36, Robert Kern [EMAIL PROTECTED] wrote: On Tue, Dec 9, 2008 at 20:24, Grissiom [EMAIL PROTECTED] wrote: Hi all, Nice to neet you all. I am a newbie in numpy. Is there any function that could unitize a array? If you mean like the Mathematica function Unitize[] defined here: http://reference.wolfram.com/mathematica/ref/Unitize.html Then .astype(bool) is probably sufficient. -- Robert Kern I'm sorry for my poor English. I mean a function that could return a unit vector which have the same direction with the original one. Thanks. -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] How to unitize a array in numpy?
On Wed, Dec 10, 2008 at 11:04, Robert Kern [EMAIL PROTECTED] wrote: v / numpy.linalg.norm(v) Thanks a lot ~;) -- Cheers, Grissiom ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion