mindspore.Tensor.histc

查看源文件
mindspore.Tensor.histc(bins=100, min=0, max=0)

计算 self 的直方图。

元素被分类到 minmax 之间的等宽箱中。 如果 minmax 均为0,则使用 self 的最小值和最大值。

低于最小值和高于最大值的元素将被忽略。

警告

如果 self 是int64,有效取值在int32范围内,超出范围可能产生精度误差。

参数:
  • bins (int, 可选) - 直方图箱的数量,可选。默认值: 100 。若指定,则必须为正数。

  • min (int, float, 可选) - 范围下限(含),可选。默认值: 0

  • max (int, float, 可选) - 范围上限(含),可选。默认值: 0

返回:

1-D Tensor,shape为 \((bins, )\),数据类型与 self 相同。

异常:
  • TypeError - 如果 self 不是Tensor。

  • TypeError - 如果属性 minmax 不是float类型或int类型。

  • TypeError - 如果属性 bins 不是整数。

  • ValueError - 如果属性 min > max

  • ValueError - 如果属性 bins <= 0。

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor
>>> input = Tensor(np.array([1., 2., 1.]), mindspore.float32)
>>> output = input.histc(bins=4, min=0, max=3)
>>> print(output)
[0. 2. 1. 0.]