(.venv) ziadh@Ziads-MacBook-Air cmps446 % python3
Python 3.11.5 (v3.11.5:cce6ba91b3, Aug 24 2023, 10:50:31) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> array: np.ndarray = np.zeros(shape=(3, 5, 5), dtype=np.uint8)
>>> array
array([[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]]], dtype=uint8)
>>> array[:,1:4,1:4] = 20
>>> array[:,:,:]
array([[[ 0, 0, 0, 0, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]],
[[ 0, 0, 0, 0, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]],
[[ 0, 0, 0, 0, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]]], dtype=uint8)
>>> copied_array: np.ndarray = np.copy(array)
>>> copied_array
array([[[ 0, 0, 0, 0, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]],
[[ 0, 0, 0, 0, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]],
[[ 0, 0, 0, 0, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]]], dtype=uint8)
>>> copied_array[:,1:3,1:3] = 70
>>> copied_array
array([[[ 0, 0, 0, 0, 0],
[ 0, 70, 70, 20, 0],
[ 0, 70, 70, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]],
[[ 0, 0, 0, 0, 0],
[ 0, 70, 70, 20, 0],
[ 0, 70, 70, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]],
[[ 0, 0, 0, 0, 0],
[ 0, 70, 70, 20, 0],
[ 0, 70, 70, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]]], dtype=uint8)
>>> array[:,:,:]
array([[[ 0, 0, 0, 0, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]],
[[ 0, 0, 0, 0, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]],
[[ 0, 0, 0, 0, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 20, 20, 20, 0],
[ 0, 0, 0, 0, 0]]], dtype=uint8)
>>> copied_array[:,1:3,1:3] = 255
>>> copied_array[:,1:3,1:3] = 256
<stdin>:1: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays. The conversion of 256 to uint8 will fail in the future.
For the old behavior, usually:
np.array(value).astype(dtype)
will give the desired result (the cast overflows).
>>> copied_array[:,1:3,1:3] = 700
<stdin>:1: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays. The conversion of 700 to uint8 will fail in the future.
For the old behavior, usually:
np.array(value).astype(dtype)
will give the desired result (the cast overflows).
>>>