Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • The reasoning for using numpy arrays of strings was because matplotlib requires a correctly shaped iterable of strings which represent numbers between 0 and 1 in order to represent grayscale, (which at the time I wanted). It seemed easiest to convert the array of numbers that I had to an array of strings. I wasn't anticipating the length complication. Commented Mar 23, 2011 at 10:13
  • helpful also in this situation: 1.) read data from file 2.) assume all entries are float, however, some are nan. 3.) if all are read as float, there will be double64 variables in the list which show up as nan but aren't recognized as numpy.nan 4.) in order to replace those, I successfully used: if V[-1].astype('|S3') == 'nan': V[-1] = numpy.nan Commented Mar 21, 2014 at 15:25
  • you can use np.genfromtxt and deal with this (more or less) automatically. It is always a bad idea to convert floats to strings if you intend to use them as float. Commented May 16, 2016 at 17:10
  • 2
    I know this is ~7 years old, but I'm commenting because this is no longer the case (python 3.6; np 1.14.0) Commented Feb 13, 2018 at 17:17