0

I'm trying to resolve an exercise (By SoloLearn) that I need to transform 1D array to 2D array. So, the site uses 5 tests to evaluate the code, my code just passes in the first two first tests. Can someone give me a hint?

Task: Given a list of numbers and the number of rows (r), reshape the list into a 2-dimensional array. Note that r divides the length of the list evenly.

Sample Input

2

1.2 0 0.5 -1

Sample Output

[[ 1.2 0. ]

[ 0.5 -1. ]]

Me code:

import numpy as np

r = int(input()) #numbers of row
lst = [float(x) for x in input().split()] #numbers in array
arr = np.array(lst)
arr = np.round(arr, 2) #round to the second decimal

two_dim = np.reshape(arr, (r, 2))
print(two_dim)

0 Answers0