Пример #1
0
def rands(shape, requires_grad=False):
    """
    将 np.random.random(shape) 填入Tensor的数据中
    :return
    返回一个给定shape的随机Tensor
    """
    return Tensor(np.random.random(shape), requires_grad=requires_grad)
Пример #2
0
def empty(shape, dtype=np.float32, requires_grad=False):
    """
    将 np.empty(shape, dtype) 填入Tensor的数据中
    :return
    返回一个给定shape和dtype的Tensor
    """
    return Tensor(np.empty(shape, dtype), requires_grad=requires_grad)
Пример #3
0
def zeros_like(other, dtype=None, requires_grad=False):
    """
    将 np.zeros_like(other, dtype) 填入Tensor的数据中
    :return
    返回一个与目标形状和类型一致的Tensor
    """
    if isinstance(other, Tensor):
        other = other.data

    return Tensor(np.zeros_like(other, dtype), requires_grad=requires_grad)