numpy.ndarray.copy()
返回数组的副本。
用法: numpy.ndarray.copy(order=’C’)
参数:
order : 控制副本的内存布局。 “ C”表示C-order,“ F”表示F-order,如果a与Fortran相邻,则“ A”表示“ F”,否则为“ C”。 “ K”表示尽可能匹配a的布局。
代码1:
# Python program explaining
# numpy.ndarray.copy() function
import numpy as geek
x = geek.array([[0, 1, 2, 3], [4, 5, 6, 7]],
order ='F')
print("x is: \n", x)
# copying x to y
y = x.copy()
print("y is :\n", y)
print("\nx is copied to y")
输出:
x is: [[0 1 2 3] [4 5 6 7]] y is : [[0 1 2 3] [4 5 6 7]] x is copied to y
代码2:
# Python program explaining
# numpy.ndarray.copy() function
import numpy as geek
x = geek.array([[0, 1, ], [2, 3]])
print("x is:\n", x)
# copying x to y
y = x.copy()
# filling x with 1's
x.fill(1)
print("\n Now x is : \n", x)
print("\n y is: \n", y)
输出:
x is: [[0 1] [2 3]] Now x is : [[1 1] [1 1]] y is: [[0 1] [2 3]]
相关用法
注:本文由纯净天空筛选整理自ArkadipGhosh大神的英文原创作品 numpy.ndarray.copy() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。