gpt4 book ai didi

python - 将 numpy 字符串数组转换为 base-16 中的整数

转载 作者:太空狗 更新时间:2023-10-30 01:29:34 25 4
gpt4 key购买 nike

我正在寻找一种方法将 numpy 中的字符串数组转换为它们以十六进制表示的整数。所以换句话说,数组版本:

int("f040", 16)

我可以通过调用 arr.astype(numpy.int32) 将字符串数组转换为以 10 为底的整数,但我看不到任何将它们转换为以 16 为底的明显方法。有谁知道这样做的方法吗?

最佳答案

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

输出:

[61504, 3735928495L]

关于python - 将 numpy 字符串数组转换为 base-16 中的整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16339704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com