From: Perry G. <pe...@st...> - 2004-06-23 15:10:22
|
John Hunter wrote: > > Now on to your problem. This is caused by a difference in how Numeric > and numarray treak rank 0 arrays > > >>> from Numeric import asarray > >>> len(asarray(0)) > 1 > >>> from numarray import asarray > >>> len(asarray(0)) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > ValueError: Rank-0 array has no length. > > I don't know why there is this difference but I'm sure Todd or Perry > can comment at length :-). > Boy can we (and we have on the numpy list in the past). But I risk boring those who really don't care. The issue relates to consistency. If rank-0 arrays have a shape of () (and they do), then they: 1) should not be indexable. 2) they have no length. Currently Numeric gives len=1 and allows indexing with [0] It's seemed to me that we need some sort of construct similar to array() that will turn scalars into rank-1 len-1 arrays which can be used like scalars for broadcasting purposes (albeit with different coercion rules; that's a different topic though), and where len() and indexing will work. Another proposal is to treat all arrays (including rank-0) as allowing indexing with any number of 0 indices beyond the defined shape: I.e., if x = arange(10) x[3,0] # same as x[3] So it's a known issue and we are thinking about how best to solve it. > To solve your vline problem, you need to make the vmin and vmax args > of vlines (or hlines) iterable. Ie > > old > > vlines(t, 0, s, color='k') > > new > > vlines(t, [0], s, color='k') > > Should work! Thanks for letting us know. > > |