numpy ndarray.reshape()(返回一个数组,其中包含具有新形状的相同数据)(不会改变原数据)

from \numpy\core_multiarray_umath.py

def reshape(self, shape, order='C'): # real signature unknown; restored from __doc__
    """
    a.reshape(shape, order='C')
    
        Returns an array containing the same data with a new shape.
    
        Refer to `numpy.reshape` for full documentation.

		返回一个数组,其中包含具有新形状的相同数据。
    
         请参阅`numpy.reshape`以获取完整的文档。
    
        See Also
        --------
        numpy.reshape : equivalent function
    
        Notes
        -----
        Unlike the free function `numpy.reshape`, this method on `ndarray` allows
        the elements of the shape parameter to be passed in as separate arguments.
        
        与free函数numpy.reshape不同,
        在ndarray上的此方法允许shape参数的元素作为单独的参数传递。
        
        For example, ``a.reshape(10, 11)`` is equivalent to
        ``a.reshape((10, 11))``.
    """
    pass

示例

# -*- encoding: utf-8 -*-
"""
@File    : 20200310_python_test.py
@Time    : 2020/3/10 23:29
@Author  : Dontla
@Email   : [email protected]
@Software: PyCharm
"""
import numpy as np

a = np.array([1, 2, 3, 4, 5, 6])
b = a.reshape(2, 3)
print(a)
# [1 2 3 4 5 6]
print(b)
# [[1 2 3]
#  [4 5 6]]

print(id(a))  # 2080594380720
print(id(b))  # 2080595240640

你可能感兴趣的:(numpy)