gpt4 book ai didi

python - 获取 numpy.ndarray 中每个元素的日志?

转载 作者:太空宇宙 更新时间:2023-11-04 07:33:36 24 4
gpt4 key购买 nike

我目前正在努力获取 numpy.ndarray 的每个元素的日志。

根据文档应该可以只.log()..

但是我不能让它工作?

>>> import numpy
>>> x = numpy.random.rand(3,3)
>>> x
array([[ 0.42631996, 0.13211157, 0.09500156],
[ 0.5699495 , 0.39852007, 0.55909279],
[ 0.12059745, 0.40645911, 0.68107768]])
>>> x.log
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'log'
>>>

最佳答案

numpy.log()不是 numpy.ndarray 的方法,它是 numpy 模块中的函数,因此您必须这样调用它:

In [1]: import numpy

In [2]: x = numpy.random.rand(3,3)

In [3]: x
Out[3]:
array([[ 0.05047638, 0.40156621, 0.29631731],
[ 0.21764918, 0.49813348, 0.48520004],
[ 0.59433129, 0.53859086, 0.66388153]])

In [4]: numpy.log(x)
Out[4]:
array([[-2.98624972, -0.91238286, -1.21632442],
[-1.52487076, -0.69688721, -0.72319401],
[-0.52031839, -0.61879907, -0.40965157]])

关于python - 获取 numpy.ndarray 中每个元素的日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41643059/

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