Re: [Numpy-discussion] Which NumPy/Numpy/numpy spelling?
> The footer appended by the mailing list shows that the name it’s right but > only the subject tag is wrong. It’s trivial to fix. You are probably right, but I wouldn't like to mess up with people's mail filters (some of which may depend on the subject tag). Cheers, Bartosz ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Which NumPy/Numpy/numpy spelling?
Hi, The general consensus seems to be in favour of using "NumPy" when referring to the project and "numpy" as a module name. Please note that there are currently PRs in 3 different repositories implementing this practice: - numpy docs: https://github.com/numpy/numpy/pull/8021 - numpy.org website: https://github.com/numpy/numpy.org/pull/5 - Scipy Lecture Notes: https://github.com/scipy-lectures/scipy-lecture-notes/pull/265 The name of the mailing lists still conflicts with the practice, but perhaps it would be more hassle to rename it than it's worth it. :). There is also some instances of "Numpy" spelling in numpy sources, but changing them would probably need more care and time. If everyone agrees the PRs could be merged together. Please review and comment! Thanks in advance, Bartosz ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Which NumPy/Numpy/numpy spelling?
Hi, I would not mind any choice as long as it's consistent. I agree that using all-lowercase spelling may avoid some common errors. However, PEP8 requires all module/package names to be lower case [1]. If we force the name of the library and the corresponding package to be the same, all Python libraries would be named in lowercase. This would not be the best choice for libraries, which have multi-component names (like NumPy = Numerical Python). Note also that both the Wikipedia page [2] and the official NumPy logo [3] use "NumPy" spelling. Some other popular [4] libraries use similar dichotomies: - Django - import django - Cython - import cython - PyYAML - import yaml - scikit-learn - import sklearn On the other hand all standard Python libraries are lower-case named. Cheers, Bartosz [1] https://www.python.org/dev/peps/pep-0008/#package-and-module-names [2] https://en.wikipedia.org/wiki/NumPy [3] http://www.numpy.org/_static/numpy_logo.png [4] http://pypi-ranking.info/alltime > On 08/29/2016 07:43 AM, m...@telenczuk.pl wrote: > > What is the official spelling of NumPy/Numpy/numpy? > > IMHO it should be written numpy, because ... > > >>> import NumPy > Traceback (most recent call last): >File "", line 1, in > ImportError: No module named NumPy > >>> import Numpy > Traceback (most recent call last): >File "", line 1, in > ImportError: No module named Numpy > >>> import numpy > >>> > > Phil > ___ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > https://mail.scipy.org/mailman/listinfo/numpy-discussion ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] preferred way of testing empty arrays
I have been using numpy for several years and I am very impressed with its flexibility. However, there is one problem that has always bothered me. Quite often I need to test consistently whether a variable is any of the following: an empty list, an empty array or None. Since both arrays and lists are ordered sequences I usually allow for both, and convert if necessary. However, when the (optional) argument is an empty list/array or None, I skip its processing and do nothing. Now, how should I test for 'emptiness'? PEP8 recommends: For sequences, (strings, lists, tuples), use the fact that empty sequences are false. seq = [] if not seq: ...print 'Hello' It works for empty numpy arrays: a = np.array(seq) if not a: ... print 'Hello Hello but if 'a' is non-empty it raises an exception: a = np.array([1,2]) if not a: ... print 'Hello ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() One solution is to test lengths: if len(seq) 0: ... if len(a) 0: ... ... but for None it fails again: opt = None if len(opt): ... TypeError: object of type 'NoneType' has no len() even worse we can not test for None, because it will fail if someone accidentally wraps None in an array: a = np.array(opt) if opt is not None: ... print 'hello' hello Although this behaviour is expected, it may be very confusing and it easily leads to errors. Even worse it adds unnecessary complexity in the code, because arrays, lists and None have to be handled differently. I hoped the I managed to explain the problem well. Is there a recommended way to test for empty arrays? Cheers, Bartosz ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] preferred way of testing empty arrays
Thank you for your tips. I was not aware of the possible problems with len. There is no way to test all of the cases (empty sequence, empty array, None) in the same way. Usually, it's a bad idea to conflate the three. I agree that this should be avoided. However, there are cases in which it is not possible or hard. My case is that I get some extra data to add to my plots from a database. The dataset may be undefined (which means None), empty array or empty list. In all cases the data should not be plotted. If I want to test for all the cases, my program becomes quite complex. In fact, Python provides False values for most empty objects, but NumPy seems to ignore this. It might be a good idea to have a helper function which handles all objects consistently. Yours, Bartosz ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] numpy.var fails on memmap
Hi, numpy.var on a memory mapped array returns a 0-d memmap object instead of a scalar (like with numpy arrays): import numpy as np fp = np.memmap('test.mm', dtype='float32', mode='w+', shape=(10,)) fp[:] = np.random.rand(10) fp_var= np.var(fp) print type(fp_var) class 'numpy.core.memmap.memmap' print fp_var.ndim 0 Moreover, the obtained object is missing 'filename' attribute, so that it can not be reused in further calculations: fp_std = np.sqrt(fp_var) ... AttributeError: 'memmap' object has no attribute 'filename' I can produce this bug in numpy 1.5.1 with python2.6 (from macports). Cheers, Bartosz Institute for Theoretical Biology Humboldt University of Berlin Germany http://neuroscience.telenczuk.pl ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion