the following code generates a kind of 'skyline' profile where the initial values are 0's and the profile is made with 1's. I implemented using a for loop and I wonder if there is a more efficient way to obtain the same result.
#https://app.codility.com/programmers/task/max_square_on_matrix/
import numpy as np
np.random.seed(2)
A = np.zeros((5,5), dtype=int)
X = np.random.randint(low=1, high=5, size = 5)
print('A ')
print(A)
print('----------------------')
print('X ')
print(X)
#
for j in range(len(A)):
A[5-X[j]:5,j] = 1
print('----------------------')
print('A modified ')
print(A)
A[5-X, np.arange(5)] =1. But with slice to the end, that approach doesn't work. We need to generate a mask array with something likeX[:,None]<np.arange(5). But details need to worked out in an answer.