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.


data_format (str) – The format of input and output data. It should be ‘NHWC’, ‘NCHW’ or ‘NCDHW’. Default is ‘NCHW’.

  • 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.


Tensor, with the same shape and data type as input_x.

  • TypeError – If data_format is not a str.

  • TypeError – If input_x or bias is not a Tensor.

  • TypeError – If dtype of input_x or bias is neither float16 nor float32.

Supported Platforms:

Ascend GPU CPU


>>> 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)