[英]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.