mindspore.ops.BiasAdd
- class mindspore.ops.BiasAdd(data_format='NCHW')[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 float16 or float32.
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 float16 or float32.
- Outputs:
Tensor, with the same shape and data type as input_x.
- Raises
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> input_x = Tensor(np.arange(6).reshape((2, 3)), mindspore.float32) >>> bias = Tensor(np.random.random(3).reshape((3,)), mindspore.float32) >>> bias_add = ops.BiasAdd() >>> output = bias_add(input_x, bias) >>> print(output.shape) (2, 3)