Problem with vlines ... and tcl !!!

Hello,

    > I try 'vline_demo' in directory 'example' and I have
    > problem with vlines ... error : "rank-O array has no
    > length". I try also with hlines and I have the same
    > problem ...

    > I also this error with all the demo : error reading
    > package index file C:/Python23/tcl/tix8.1/pkgIndex.tcl:
    > invalid command name "lt}]}"

    > Have you a explanation ?

This turns out to be numarray specific - most of my tests use Numeric
which is why I didn't catch that. I'll try and make sure I do a
numarray specific test in the future. Todd, perhaps you should also
make a note to run backend_driver on your numarray build, at least for
Agg. That wouldn't have helped this time, because vline_demo.py was
not in the regression suite, but I've added it.

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 :-).

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.

John Hunter

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.