maxframe.tensor.array#

maxframe.tensor.array(x, dtype=None, copy=True, order='K', ndmin=None, chunk_size=None)[源代码]#

创建一个张量。

参数:
  • object (array_like) -- 一个数组,任何暴露数组接口的对象,其 __array__ 方法返回数组的对象,或任何(嵌套)序列。

  • dtype (data-type, optional) -- 数组的期望数据类型。如果未给出,则将类型确定为保存序列中对象所需的最小类型。此参数只能用于“向上转换”数组。如需向下转换,请使用 .astype(t) 方法。

  • copy (bool, optional) -- 如果为真(默认),则复制对象。否则,仅在 __array__ 返回副本、obj 为嵌套序列或需要副本以满足其他要求(dtypeorder 等)时才会进行复制。

  • order ({'K', 'A', 'C', 'F'}, optional) -- 指定数组的内存布局。如果对象不是数组,则新创建的数组将采用 C 顺序(行优先),除非指定了 'F',在这种情况下它将采用 Fortran 顺序(列优先)。如果对象是数组,则遵循以下规则。===== ========= =================================================== order no copy copy=True ===== ========= =================================================== 'K' unchanged F & C order preserved, otherwise most similar order 'A' unchanged F order if input is F and not C, otherwise C order 'C' C order C order 'F' F order F order ===== ========= =================================================== 当 copy=False 并且因其他原因进行复制时,结果与 copy=True 相同,但对于 A 有一些例外,请参见备注部分。默认顺序是 'K'。

  • ndmin (int, optional) -- 指定结果数组应具有的最小维度数。将根据需要在形状前添加 1 以满足此要求。

  • chunk_size (int, tuple, optional) -- 指定每个维度的块大小。

返回:

out -- 满足指定要求的张量对象。

返回类型:

Tensor

参见

empty, empty_like, zeros, zeros_like, ones, ones_like, full, full_like

示例

>>> import maxframe.tensor as mt
>>> mt.array([1, 2, 3]).execute()
array([1, 2, 3])

向上转换:

>>> mt.array([1, 2, 3.0]).execute()
array([ 1.,  2.,  3.])

多于一个维度:

>>> mt.array([[1, 2], [3, 4]]).execute()
array([[1, 2],
       [3, 4]])

最小维度 2:

>>> mt.array([1, 2, 3], ndmin=2).execute()
array([[1, 2, 3]])

提供了类型:

>>> mt.array([1, 2, 3], dtype=complex).execute()
array([ 1.+0.j,  2.+0.j,  3.+0.j])