[Numpy-discussion] rank-0 chararrays?
jmiller at stsci.edu
Tue Feb 18 04:28:03 CST 2003
Francesc Alted wrote:
>I'm trying to map Numeric character typecode ('c') to chararrays, but I have
>a problem to distinguish between
>In : chararray.array("qqqq")
>In : chararray.array(["qqqq"]) # Note the extra "[" "]"
>Out: CharArray(['qqqq']) # The same result as 109
The chararray API pre-dates our awareness, ultimate implemenation, and
final rejection of rank-0 arrays. In retrospect, your usage above
makes sense. Whether we change things now or not is another matter.
You are giving me interface angst... :)
You can create rank-0 arrays by specifying shape=() and
itemsize=len(buffer). However, these do not repr correctly (unless you
update from CVS).
>while in Numeric we have:
>In : Numeric.array("qqqq")
>Out: array([q, q, q, q],'c')
>In : Numeric.array(["qqqq"])
>Out: array([ [q, q, q, q]],'c') # Differs from 113
>even in numarray objects, rank-0 seems to work well:
>In : numarray.array(1)
>In : numarray.array()
>Out: array() # Objects differ
This was not always so, be we made it work when we thought rank-0 had
something to offer. After some discussion on numpy-discussion-list,
rank-0 went out of vogue.
>So, it seems like if chararray does not support well rank-0 objects.
That is true. CharArray never caught up because rank-0 became vestigal
even for NumArray.
>the expected behavior?.
Yes. But, rank-0 support for chararray is not far off, with the
possible exception of breaking the public interface.
>If yes, we have no possibility to distinguish
>between object 109 and 110, and I'd like to distinguish between this two.
Why exactly do you need rank-0?
>What can be done to achieve this?
1. Add a little special casing to chararray._charArrayToStringList() to
handle rank-0. I did this already in CVS.
2. Debate whether or not to change chararray.array() to work as you've
shown above. Proceed from there.
More information about the Numpy-discussion