30 NumPy slicing pattern-filling exercises — crafted to strengthen your understanding of slicing and filling in NumPy arrays:
🧩 NumPy Slicing Pattern-Filling Exercises (Only Questions)
-
Fill the diagonal of a 5x5 zero array with
1
s using slicing. -
Create a 6x6 array and fill the border with
5
s, rest with0
s. -
Fill only the last row of a 4x4 array with
7
s. -
Fill every alternate column of a 5x5 array with
9
s. -
Create a 6x6 array and fill the center 2x2 block with
8
s. -
In a 7x7 array, fill a cross pattern (both diagonals) with
3
s. -
Create a 5x5 array, fill all odd-indexed rows with
2
s. -
Fill only the first column of a 6x6 array with
4
s. -
Create an 8x8 array, fill all elements except the border with
6
s. -
Fill the top-left 3x3 quadrant of a 6x6 array with
1
s. -
Create a 10x10 array, fill an L-shape pattern on the left and bottom sides with
9
s. -
Fill a checkerboard pattern (alternating 0 and 1) in an 8x8 array.
-
Create a 7x7 array and fill all even-indexed rows and columns with
7
s. -
In a 5x5 array, fill the second and fourth rows with
5
s. -
Fill the middle row and middle column of a 9x9 array with
1
s. -
In a 6x6 array, fill a square ring (excluding diagonals) with
2
s. -
Fill the first and last two columns of an 8x8 array with
3
s. -
Fill every 3rd row of a 9x9 array with
4
s using slicing. -
Create a 10x10 array, fill values in a diagonal band of width 3 with
6
s. -
Fill the lower triangle (below main diagonal) of a 5x5 array with
1
s. -
Fill the upper triangle (above main diagonal) of a 5x5 array with
1
s. -
Fill a centered diamond pattern in a 7x7 array with
5
s using slicing logic. -
Fill the border of a 10x10 array with
2
s and the inner 8x8 with8
s. -
Fill a vertical band (columns 3 to 5) in an 8x8 array with
9
s. -
Create a 6x6 array and fill only the corners with
7
s. -
Fill a "plus" shape in the center of a 5x5 array with
4
s. -
Fill a horizontal stripe (rows 2 to 4) in a 7x7 array with
3
s. -
Create a 9x9 array, fill the four quadrants with values 1, 2, 3, and 4.
-
Fill the even-numbered columns with
6
s and odd-numbered rows with3
s. -
Create an 8x8 array, fill all elements where row index > column index with
2
s.
Let me know if you’d like more then comments and which topic