mindspore.ops.BiasAdd
- class mindspore.ops.BiasAdd(*args, **kwargs)[source]
Returns sum of input and bias tensor.
Adds the 1-D bias tensor to the input tensor, and broadcasts the shape on all axis except for the channel axis.
- Parameters
data_format (str) – The format of input and output data. It should be ‘NHWC’, ‘NCHW’ or ‘NCDHW’. Default is ‘NCHW’.
- Inputs:
input_x (Tensor) - The input tensor. The shape can be 2-5 dimensions. The data type should be Number
bias (Tensor) - The bias tensor, with shape \((C)\). The shape of bias must be the same as input_x’s channel dimension. The data type should be Number
- Outputs:
Tensor, with the same shape and data type as input_x.
- Raises
TypeError – If data_format, input_x or bias is not a Tensor.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor >>> import mindspore.ops as ops >>> from mindspore.common import dtype as mstype >>> input_x = Tensor(np.arange(6).reshape((2, 3)), mstype.float32) >>> bias = Tensor(np.random.random(3).reshape((3,)), mstype.float32) >>> bias_add = ops.BiasAdd() >>> output = bias_add(input_x, bias) >>> print(output.shape) (2, 3)