335 Star 1.5K Fork 861

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
logical_not.md 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
宦晓玲 提交于 2023-07-21 15:21 . modify the md links in 1.6

比较与torch.logical_not的功能差异

查看源文件

torch.logical_not

class torch.logical_not(input, out=None)

更多内容详见 torch.logical_not

mindspore.numpy.logical_not

class mindspore.numpy.logical_not(a, dtype=None)

更多内容详见 mindspore.numpy.logical_not

使用方式

PyTorch: 计算给定输入张量的逐元素逻辑非。零被视为“False”,非零被视为“True”。

MindSpore: 按元素计算输入张量的逻辑非。输入应该是一个dtype为bool的张量。

代码示例

import mindspore.numpy as np
import torch

# MindSpore
print(np.logical_not(np.array([True, False])))
# Tensor(shape=[2], dtype=Bool, value= [False,  True])
print(np.logical_not(np.array([0, 1, -10])))
# TypeError: For primitive[LogicalNot], the input argument[x] must be a type of {Tensor[Bool],}, but got Int32.

# PyTorch
print(torch.logical_not(torch.tensor([True, False])))
# tensor([False,  True])
print(torch.logical_not(torch.tensor([0, 1, -10], dtype=torch.int8)))
# tensor([ True, False, False])
print(torch.logical_not(torch.tensor([0., 1.5, -10.], dtype=torch.double)))
# tensor([ True, False, False])
print(torch.logical_not(torch.tensor([0., 1., -10.], dtype=torch.double), out=torch.empty(3, dtype=torch.int16)))
# tensor([1, 0, 0], dtype=torch.int16)
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
r1.6

搜索帮助

53164aa7 5694891 3bd8fe86 5694891