|
From: Travis O. <oli...@ie...> - 2006-02-14 04:37:53
|
Tim Hochberg wrote: > Travis Oliphant wrote: > >> Russel Howe wrote: >> >>> I am converting some numarray code to numpy and I noticed this >>> behavior: >>> >>> >>> from numpy import * >>> >>> sta=array(['abc', 'def', 'ghi']) >>> >>> stb=array(['abc', 'jkl', 'ghi']) >>> >>> sta==stb >>> False >>> >>> I expected the same as this: >>> >>> a1=array([1,2,3]) >>> >>> a2=array([1,4,3]) >>> >>> a1==a2 >>> array([True, False, True], dtype=bool) >>> >>> I am trying to figure out how to fix this now... >> >> >> >> >> Equality testing on string arrays does not work (equality testing >> uses ufuncs internally which are not supported generally for flexible >> arrays). You must use chararray's. > > > Should string arrays then perhaps raise an exception here to keep > people out of trouble? Probably. The equal (not_equal) rich comparison code has some left-over stuff from Numeric which is implemented so that if the ufunc equal (not_equal) failed False (True) was returned. I did not special-case the string arrays in this code. -Travis > > -tim > > >> >> Thus, >> >> sta.view(chararray) == stb.view(chararray) >> >> Or create chararray's from the beginning: >> >> sta = char.array(['abc','def','ghi']) >> stb = char.array(['abc','jkl','ghi']) >> >> Char arrays are a special subclass of the ndarray that give arrays >> all the methods of strings (and unicode) elements and allow (rich) >> comparison operations. >> >> -Travis >> >> >> >> >> >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: Splunk Inc. Do you grep through >> log files >> for problems? Stop! Download the new AJAX search engine that makes >> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! >> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 >> _______________________________________________ >> Numpy-discussion mailing list >> Num...@li... >> https://lists.sourceforge.net/lists/listinfo/numpy-discussion >> >> > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log > files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion |