![](/img/trans.png)
[英]How to convert numpy.ndarray to string and then find substring from each element of the array using a delimiter
[英]Taking the log of each element in a numpy.ndarray?
我目前正在努力获取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]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.