I want to select range in array like image.
If there is 12X8 array A, i want to select A[0~3,9~12][4,5] and change to 0.
So i wrote code like A[[:3,8:],4:5] = 0
, but it occurred error.
Please help me.
I want to select range in array like image.
If there is 12X8 array A, i want to select A[0~3,9~12][4,5] and change to 0.
So i wrote code like A[[:3,8:],4:5] = 0
, but it occurred error.
Please help me.
This is a solution with numpy,
import numpy as np
A = np.ones((12,8))
A[np.r_[0:4,8:12],3:5] = 0
print(A)
Output:
[[1. 1. 1. 0. 0. 1. 1. 1.]
[1. 1. 1. 0. 0. 1. 1. 1.]
[1. 1. 1. 0. 0. 1. 1. 1.]
[1. 1. 1. 0. 0. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 0. 0. 1. 1. 1.]
[1. 1. 1. 0. 0. 1. 1. 1.]
[1. 1. 1. 0. 0. 1. 1. 1.]
[1. 1. 1. 0. 0. 1. 1. 1.]]
Similar questions,
It's probably easiest just to do it in two lines.
A[:4,3:5] = 0
A[8:,3:5] = 0
(indices based on your picture)