numpy array - convert hex to int

Sharan Basappa sharan.basappa at gmail.com
Mon Sep 9 23:19:03 EDT 2019


On Sunday, 8 September 2019 11:16:52 UTC-4, Luciano Ramalho  wrote:
> >>> int('C0FFEE', 16)
> 12648430
> 
> There you go!
> 
> On Sun, Sep 8, 2019 at 12:02 PM Sharan Basappa <sharan.basappa at gmail.com> wrote:
> >
> > I have a numpy array that has data in the form of hex.
> > I would like to convert that into decimal/integer.
> > Need suggestions please.
> > --

I am sorry. I forgot to mention that I have the data in a numpy array.
So, when I try to convert to int, I get the following error.

sample code here
#####################
my_data_3 = int(my_data_2)

my_data_4 = my_data_3.astype(np.float)
#####################

Error here
###############
#np.core.defchararray.replace(my_data_2,",'')
     27 
---> 28 my_data_3 = int(my_data_2)
     29 
     30 my_data_4 = my_data_3.astype(np.float)
TypeError: only length-1 arrays can be converted to Python scalars 
#########################



More information about the Python-list mailing list