mindspore.ops.Dense
- class mindspore.ops.Dense[source]
The dense connected fusion operator.
Applies dense connected operator for the input. The implement of the operation is as:
where
is the input tensor, is a weight matrix with the same data type as the , and is a bias vector with the same data type as the (only if b is notNone
).- Inputs:
x (Tensor) - The shape must meet the following requirement:
.w (Tensor) - The shape must meet the following requirements: If
, . If , . .b (Union[Tensor, None]) - If b is not
None
, the shape must meet the following requirements: If , or . If , . If , .
- Outputs:
If
, Tensor of shape . If , Tensor of shape .- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor, ops >>> x = Tensor(np.random.random((4, 5, 6, 7)).astype(np.float32)) >>> weight = Tensor(np.random.random((6, 7)).astype(np.float32)) >>> bias = Tensor(np.random.random((6,)).astype(np.float32)) >>> dense = ops.Dense() >>> output = dense(x, weight, bias) >>> print(output.shape) (4, 5, 6, 6)