Thanks Sebastian. Casting it to an array would certainly help.<div><br></div><div>Another oddity of zero-ranked scalars is that they look iterable, but in fact are not. Because all they do is generate an error.</div><div><br>
</div><div><div>>>> a = np.array(22)</div></div><div><br></div><div>Test if iterable:</div><div><br></div><div><div>>>> hasattr(a, __iter__)</div></div><div><div>True</div><div><br></div><div>Or:</div><div>
<br></div><div><div>>>> import collections</div><div>>>> isinstance(a, collections.Iterable)</div></div><div>True</div><div><br></div><div>>>> for e in a:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>print e</div>
</div><div>TypeError: iteration over a 0-d array</div><div><br></div><div>Wouldn't it be better to have a different type altogether for numpy scalars? Because scalars don't seem to quack quite like arrays...</div>
<div>(I haven't been following the discussion around scalars, so if this is a silly remark just ignore it)</div><div><br></div><div>Another question. What would be the preferred method of testing for zero-ranked array?</div>
<div>Something like this?</div><div><br></div><div><div>>>> if a.shape:</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>print "array"</div><div>else:</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>print "scalar"</div>
<div><br></div><div>Regards,</div></div><div><br></div><div>Wim</div>