Re: [Numpy-discussion] preferred way of testing empty arrays

2012-01-30 Thread Chris Barker
On Fri, Jan 27, 2012 at 1:29 PM, Robert Kern wrote: > Well, if you really need to do this in more than one place, define a > utility function and call it a day. > > def should_not_plot(x): >    if x is None: >        return True >    elif isinstance(x, np.ndarray): >        return x.size == 0 >  

Re: [Numpy-discussion] preferred way of testing empty arrays

2012-01-27 Thread Bartosz Telenczuk
This will be indeed very helpful. Thanks. > Well, if you really need to do this in more than one place, define a > utility function and call it a day. > > def should_not_plot(x): >if x is None: >return True >elif isinstance(x, np.ndarray): >return x.size == 0 >else: >

Re: [Numpy-discussion] preferred way of testing empty arrays

2012-01-27 Thread Robert Kern
On Fri, Jan 27, 2012 at 21:24, Bartosz Telenczuk wrote: > 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 th

Re: [Numpy-discussion] preferred way of testing empty arrays

2012-01-27 Thread Bartosz Telenczuk
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 i

Re: [Numpy-discussion] preferred way of testing empty arrays

2012-01-27 Thread Robert Kern
On Fri, Jan 27, 2012 at 20:46, Bartosz Telenczuk wrote: > 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:

Re: [Numpy-discussion] preferred way of testing empty arrays

2012-01-27 Thread Benjamin Root
On Fri, Jan 27, 2012 at 2:46 PM, Bartosz Telenczuk < b.telenc...@biologie.hu-berlin.de> wrote: > 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

[Numpy-discussion] preferred way of testing empty arrays

2012-01-27 Thread Bartosz Telenczuk
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 list