Chém gió

Python

Slicing in numpy

In numpy world slicing just refer to original data of source array. example we have arr[1,2,3,4,5,6,7,8,9], slicing arr to scl_arr = arr[0:4:2] ---> scl_arr contain [1,3] do assign scl_arr[:]=10 so element at 1 and 3 will become 10 arr now is [10,2,10,4,5,6,7,8,9].
Be careful with this, this is common mistake in numpy.
If you want to copy do this: scl_arr =  arr[0:4:2].copy()
:)

Không có nhận xét nào:

Đăng nhận xét