python中数组切片,在numpy数组中切片与在Python中切片列表之间有什么区别?

If curr_frames is a numpy array, what does the last line mean?

curr_frames = np.array(curr_frames)

idx = map(int,np.linspace(0,len(curr_frames)-1,80))

curr_frames = curr_frames[idx,:,:,:,]

解决方案

An important distinction from Python’s built-in lists to numpy arrays:

when slicing in the built-in list it creates a copy.

X=[1,2,3,4,5,6]

Y=X[:3] #[1,2,3]

by slicing X from 0-3 we have created a copy and stored it in the variable Y.

we can verify that by changing the Y and even if we change Y it does not effect X.

Y[0]=20

print(Y) # [20,2,3]

print(X) # [1,2,3,4,5,6]

when slicing in numpy doesn't create a new copy but it still referring to original array

A=np.array([1,2,3,4,5,6])

B=A[:3]

By slicing A here and assigning it to B, still B referring to original array A.

We can verify that by changing an element in B and it will change the value in A as well.

B[0]=20

print(B) # [20,2,3]

print(A) # [20,2,3,4,5,6]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值