Python Forum
Numpy, dash and em-dash
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Numpy, dash and em-dash
#1
I was trying to read a table with many columns in scientific notation into a numpy array. When I tried to cnvert the input strings into flating points numbers using:

M_d1 = M_d1.astype(float)

I got this error:

ValueError: could not convert string to float: np.str_('1.01E−03')

I took me a while to catch the issue: it lies in that little "−". It is not a dash ("-") , but an em-dash ("−"). I then changed all the occurrences of this em-dash in my table and now numpy runs smoothly, thus it does not recognize em-dash.
Reply
#2
Can confirm: big dash is not little dash:

ord('−') # 8722
ord('-') # 45
chr(8722) # '−'
chr(45) # '-'
When I use Chinese input, pressing Shift and dash gets me this super-dash!

Output:
——
which is 2 of these:

ord("—") # 8212
Dashed if I know why!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 4,095 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 5,433 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 4,569 Apr-09-2019, 04:54 PM
Last Post: PhysChem
  Plot Pandas DataFrame using Dash niks250891 0 6,200 Apr-28-2018, 05:07 PM
Last Post: niks250891
  Python+Dash+ Can't get menu page to feed to page georgelza 0 3,149 Apr-15-2018, 02:09 PM
Last Post: georgelza

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020