Problem

9 /12


Two-dimensional NumPy arrays. Referencing elements

Theory Click to read/hide

2D NumPy arrays

An element of a two-dimensional array is accessed by specifying the coordinates of the element, first the row number, then the column number. Coordinates are separated by commas. 
Any array can be converted to a two-dimensional array using the reshape(). function

Example
1
2
3
4
5
6
7
8
# The reshape() function changes the shape of an array without changing its data. x = np.arange(12).reshape(3, 4) print(x) # [[ 0 1 2 3] # [ 4 5 6 7] # [ 8 9 10 11]] # To access an element, specify its coordinates separated by commas print(x[1, 2]) # 6

Problem

The numbers n and m are given as input. Output an array of size n by m, in which the first line (the line with zero index) contains numbers from 0  up to m-1 and the remaining numbers are 0. The type of array elements must be np.int8.
 

 

Examples
# Input Output
1 3
4
[[0 1 2 3]
 [0 0 0 0]
 [0 0 0 0]]