- 2

numpy reshape

You are given an array that represents the occupancy of seats in a movie theater. A seat marked with 1 is occupied, while one marked 0 means the seat is free. However, the array is flat and 1-dimensional. Transform it into a 2-dimensional array, representing the rows of the seats. Each row in the theater has 5 seats and there are a total of 30 seats. Reshape the array into the corresponding shape and output the row at the given index, which is taken from user input. The row index is taken from user input in the given code. import numpy as np data = np.array([1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0]) row = int(input()) data=data.reshape(5,6) print(data[row]) why im not getting correct output.

3rd Jul 2021, 4:49 PM
Dharmendra Singh
Dharmendra Singh - avatar
3 Respostas
+ 3
data=data.reshape(6,5) # reshape take first rows, then cols
3rd Jul 2021, 5:03 PM
visph
visph - avatar
0
Don't you? Looks good
3rd Jul 2021, 5:02 PM
Oma Falk
Oma Falk - avatar
0
import numpy as np data = np.array([1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0]) row = int(input()) data=data.reshape(6,5) print(data[row])
11th Dec 2021, 1:23 PM
Jibran Abdul Jabbar
Jibran Abdul Jabbar - avatar