---
title: log
description: "计算每个元素（非负）的自然对数，即ln(x)。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_1090.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_1090.html
indexId: 5ee39ba14b9100e66b34e9820242b84622ba46691662196e2aa519199a78fd0661
---
# log

#### 功能描述

计算每个元素（非负）的自然对数，即ln(x)。


#### 必选输入参数

| 参数名 | 类型 | 说明 |
| --- | --- | --- |
| x | array\_like | 输入的数组或标量。 |


#### 可选输入参数

| 参数名 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| out | ndarray/ndarray的元组 | None | 计算结果保存的位置。如果提供，其形状必须与输入数组广播后的形状一致。未指定时，返回一个新的数组。 |
| where | array\_like | None | 将被广播至输入的条件数组。在条件为真处的元素，其计算结果会存入out中，其余位置保留原有值。 |
| \*\*kwargs | \- | \- | 其他关键字参数，请参见NumPy官方文档Universal functions (ufunc)(https://numpy.org/doc/stable/reference/ufuncs.html\#ufuncs\-kwargs)。 |


#### 返回数据

| 类型 | 说明 |
| --- | --- |
| ndarray/scalar | 每个元素（非负）自然对数的结果。 |


#### 示例

```
>>> import numpy as np
>>> np.log(1.0)
0.0
>>> x = np.array([1.0, np.e, np.e**2, 0])
>>> np.log(x)
array([  0.,   1.,   2., -inf])
>>>
```
