如何获取np.array中每个数字的指数? [英] How can I get the exponent of each number in a np.array?
本文介绍了如何获取np.array中每个数字的指数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我说我拥有数组:
x = np.array([0.00001,0.001])
numpy将使数字变为
numpy will make the numbers to
array([ 1.00000000e-05, 1.00000000e-03])
现在我想获得指数,类似
Now I want to get the exponents, something like
x.get_exponent()
有结果
[-5,-3]
推荐答案
您可以使用np.floor(np.log10(np.abs(x)))
.
例如:
In [13]: x = np.array([0.00001, -0.001, 0.0000025, 0.09, -13.25, 9876.5])
In [14]: x
Out[14]:
array([ 1.00000000e-05, -1.00000000e-03, 2.50000000e-06,
9.00000000e-02, -1.32500000e+01, 9.87650000e+03])
In [15]: np.floor(np.log10(np.abs(x))).astype(int)
Out[15]: array([-5, -3, -6, -2, 1, 3])
这篇关于如何获取np.array中每个数字的指数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文