Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a numpy string array to integers in base-16

Tags:

python

numpy

I am looking for a way to convert an array of strings in numpy to the integers they represent in hexadecimal. So in other words, the array version of:

int("f040", 16)

I can convert a string array to integers base-10 by calling arr.astype(numpy.int32), but I can't see any obvious way to convert them base-16. Does anyone know of a way to do this?

like image 776
dpitch40 Avatar asked Oct 21 '22 10:10

dpitch40


1 Answers

ar = ['f040', 'deadbeaf'] 
int_array = [int(a, 16) for a in ar]
print int_array

output:

[61504, 3735928495L]

like image 61
Michel Keijzers Avatar answered Oct 27 '22 08:10

Michel Keijzers