Pandas Pandas Pandas challenge.. what test 3 checks?? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
+ 3

# Pandas Pandas Pandas challenge.. what test 3 checks??

Pandas Pandas Pandas Challenge

26th Dec 2020, 1:00 AM
36 ответов
+ 11
import numpy as np first = np.array([[0., 0.]]) second = np.array([[2., 2.]]) n = int(input()) data = [] for i in range(n): data.append([float(i) for i in input().split()]) data = np.array(data).reshape((-1,2)) for i in range(n): dist1 = np.sqrt(((data[i]-first[0])**2).sum()) dist2 = np.sqrt(((data[i]-second[0])**2).sum()) if (dist1) <= (dist2): first = np.vstack((first,data[i])) else: second = np.vstack((second,data[i])) if first.size > 2: mean1 = np.mean(first[1:], axis=0) print(np.around(mean1, decimals=2)) else: print(None) if second.size > 2: mean2 = np.mean(second[1:], axis=0) print(np.around(mean2, decimals=2)) else: print(None)
23rd Mar 2021, 5:58 AM
Namrata Dattani
+ 8
Adriano Lopes Godoy I removed the colons on the columns (which is sometimes the cause of error) and because the output will be the same anyway. This is just a possibility. This is from Pranjal Tambe 's code. https://code.sololearn.com/c81T363EgrNn/?ref=app EDIT: Namrata Dattani Bruh! you just copied my code bit then pasted it here as your answer. At first, I thought that was yours but I noticed that it is an exact copy of my previous code (also OP's code), even spaces and variables. Solve and help on your own dude. That's not a nice thing to do! [original code: https://code.sololearn.com/c81T363EgrNn/?ref=app]
29th Dec 2020, 8:44 AM
noteve
+ 5
Aside from colons, others are just minor adjustment or improvement of readability such as: 1.) Instead of [0, 0] and [2, 2] it is [0., 0.] and [2., 2.] for it to be float-type from the start. 2.) Instead of input().split(' '), just input().split() cause whitespace is the default parameter 3.) Just some whitespaces for readability. And just to clarify I didnt remove colons, rather I remove columns because for example I want to get all the columns of the 3rd row: array[2, :] is the same with array[2] So I think it is safer to only have one number if you will access a row that includes all columns, but I also dont know whats the reason behind this.
29th Dec 2020, 11:49 AM
noteve
+ 3
Hmm... you're right but maybe you should post your attempt so someone who had the same problem know what needs to be adjusted.
26th Dec 2020, 4:22 AM
noteve
+ 3
My code doesn't pass test 3 too. Can someone check this and help https://code.sololearn.com/c8DKMv2ZnIj1/?ref=app
27th Dec 2020, 7:28 AM
Pranjal Tambe
+ 3
import numpy as np n = int(input()) d = [] for i in range(n): d.append([float(i) for i in input().split()]) data = np.array(d) r1 = [0, 0] r2 = [2, 2] c1 = [] c2 = [] for i in range(n): euclidean_dist1 = np.sqrt(((data[i]-r1)**2).sum()) euclidean_dist2 = np.sqrt(((data[i]-r2)**2).sum()) if euclidean_dist1 <= euclidean_dist2: c1.append(data[i]) else: c2.append(data[i]) if len(c1)==0: print('None') else: print((np.array(c1).mean(axis=0)).round(2)) if len(c2)==0: print('None') else: print((np.array(c2).mean(axis=0)).round(2))
18th Mar 2022, 8:55 PM
+ 2
I solved.. add else and print(None) Solution: else: print(None) Or if(len(array)==0): print(None) else: [Code] This solve test 3... this is the tip I needed
29th Dec 2020, 7:25 AM
+ 1
Adriano Lopes Godoy I tried with Pandas too, failing just test 3. Can not understand what's wrong
27th Dec 2020, 11:33 AM
Pranjal Tambe
+ 1
《 Nicko12 》 The challenge is as such https://code.sololearn.com/chdyvNqc68e6/?ref=app It won't require ML knowledge
27th Dec 2020, 11:40 AM
Pranjal Tambe
+ 1
distance calculation #initial centroid p1 = np.array([0.,0.]) p2 = np.array([2.,2.]) #loop for... for each point input.. p = new point d1 = np.sqrt(((p-p1)**2).sum()) d2 = np.sqrt(((p-p2)**2).sum()) if d2>=d1: c0.append(p) else: c2.append(p) mean use pandas to calculate and round this fail in test 3...
27th Dec 2020, 7:56 PM
+ 1
separated into 2 arrays for each centroid... c0 nearst p(0, 0) and c2 nearst p(2,2)... use pandas to calculate mean and round print(c0.mean().round(2).values) print(c2.mean().round(2).values) this work for test 1,2,4 and 5... fail in test 3..
27th Dec 2020, 8:04 PM
+ 1
So you solved it? I think the previous code already has that (else then print(None) ) or maybe its different.
29th Dec 2020, 7:26 AM
noteve
+ 1
Oh ok, but what will hapen if else: pass ??
29th Dec 2020, 7:32 AM
noteve
+ 1
Need use <= ... if tie... append centroid (0,0)
29th Dec 2020, 7:41 AM
+ 1
《 Nicko12 》 your code works too...
29th Dec 2020, 9:17 AM
+ 1
Yes.. I solved..
30th Dec 2020, 8:28 AM
+ 1
My final code is the same as the first.. When i use print(None)... i use split(' ')... this fail test 3 too... always test 3 to fail.... When use split()... not use print(None).. i try too print()... fail test 3 too.. 2 small details... only need use split() and print(None)...
30th Dec 2020, 9:28 AM