mindspore.ops.HistogramFixedWidth

class mindspore.ops.HistogramFixedWidth(nbins, dtype='int32')[源代码]

Returns a rank 1 histogram counting the number of entries in values that fall into every bin. The bins are equal width and determined by the inputs range and the arguments nbins.

Parameters
  • dtype (str) – An optional attribute. The dtype must be “int32”. Default: “int32”.

  • nbins (int) – The number of histogram bins, the type is a positive integer.

Inputs:
  • x (Tensor) - Numeric Tensor. Must be one of the following types: int32, float32, float16.

  • range (Tensor) - Must have the same data type as x, and the shape is (2,). x <= range[0] will be mapped to histogram[0], x >= range[1] will be mapped to histogram[-1].

Outputs:

Tensor, the type is int32.

Raises
  • TypeError – If dtype is not a str or nbins is not an int.

  • ValueError – If nbins is less than 1.

  • ValueError – If dtype is neither ‘int32’ nor ‘int64’.

Supported Platforms:

Ascend GPU

Examples

>>> x = Tensor([-1.0, 0.0, 1.5, 2.0, 5.0, 15], mindspore.float16)
>>> range_op = Tensor([0.0, 5.0], mindspore.float16)
>>> hist = ops.HistogramFixedWidth(5)
>>> output = hist(x, range_op)
>>> print(output)
[2 1 1 0 2]