0

Reshape project. I've been working on this and am getting close... I pass the first 2 tests, but not the hidden tests. Any tips?

import numpy as np r = int(input()) lst = [float(x) for x in input().split()] arr = np.array(lst) round_arr=arr.round(2) print(round_arr.reshape(r,2))

14th Feb 2021, 4:52 PM
Michele Rene Machado
Michele Rene Machado - avatar
6 odpowiedzi
+ 3
This one worked: import numpy as np r = int(input()) lst = [float(x) for x in input().split()] arr = np.array(lst) arr=arr.reshape(r,int(len(lst)/r)) print(arr)
11th Mar 2021, 7:28 PM
Frank Kober
Frank Kober - avatar
+ 2
Michele Rene Machado , what is missing is the reshaping of the array, right? something like: arr.reshape(...) if you do not remember how it works, please read this chapter of the tutorial again.
14th Feb 2021, 6:36 PM
Lothar
Lothar - avatar
+ 2
I think it's just to do with the columns. The number of columns isn't always 2. I believe you have to write the formula for calculating the number of columns given the length of the list and the number of rows.
21st Feb 2021, 2:25 PM
Okan
Okan - avatar
+ 1
It's in the print method, not sure what is wrong the tests that weren't passed are hidden from me.
14th Feb 2021, 8:35 PM
Michele Rene Machado
Michele Rene Machado - avatar
0
Since this was in the pandas section of the course I found reshape function in pandas docs and completed with similar solution to Frank Kober above but changed numpy array to pandas dataframe before modification. import numpy as np import pandas as pd r = int(input()) lst = [float(x) for x in input().split()] arr = np.array(lst) arr_df = pd.DataFrame(arr) print(arr_df.values.reshape(r, int(len(lst)/r)))
11th Aug 2021, 3:00 AM
The Owl
The Owl - avatar
0
these one worked (thank you for the help , i was missing arr=arr.reshape(r,int(1st)/r)) import numpy as np r = int(input()) lst = [float(x) for x in input().split()] arr = np.array(lst) arr=arr.reshape(r,int(len(lst)/r)) print(arr)
18th Jan 2022, 9:42 AM
Oscar D Diaz
Oscar D  Diaz - avatar