maxframe.tensor.ones#
- maxframe.tensor.ones(shape, dtype=None, chunk_size=None, gpu=None, order='C')[源代码]#
返回一个给定形状和类型的全1新张量。
- 参数:
shape (int or sequence of ints) -- 新张量的形状,例如
(2, 3)或2。dtype (data-type, optional) -- 张量所需的数据类型,例如 mt.int8。默认为 mt.float64。
chunk_size (int or tuple of int or tuple of ints, optional) -- 每个维度上期望的分块大小
gpu (bool, optional) -- 如果为 True,则在 GPU 上分配张量,默认为 False
order ({'C', 'F'}, optional, default: C) -- 是否以行主序(C 风格)或列主序(Fortran 风格)方式在内存中存储多维数据。
- 返回:
out -- 具有给定形状、数据类型和存储顺序的全1张量。
- 返回类型:
Tensor
参见
zeros,ones_like示例
>>> import maxframe.tensor as mt
>>> mt.ones(5).execute() array([ 1., 1., 1., 1., 1.])
>>> mt.ones((5,), dtype=int).execute() array([1, 1, 1, 1, 1])
>>> mt.ones((2, 1)).execute() array([[ 1.], [ 1.]])
>>> s = (2,2) >>> mt.ones(s).execute() array([[ 1., 1.], [ 1., 1.]])