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))
6 Antworten
+ 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)
+ 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.
+ 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.
+ 1
It's in the print method, not sure what is wrong the tests that weren't passed are hidden from me.
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)))
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)