duplicates

How to remove duplicate elements for two numpy arrays in python

百般思念 提交于 2019-12-24 00:27:03
问题 I have two array naming u,v, e.g. u=np.array([1.0,2.0,2.0,3.0,4.0]) v=np.array([10.0,21.0,18.0,30.0,40.0]) a=np.array([100.0,210.0,220.0,300.0,400.0]) If two elements in u are same, then delete that one which is higher in v value. For the above example,the result should be u_new=np.array([1.0,2.0,3.0,4.0]) v_new=np.array([10.0,18.0,30.0,40.0]) a_new=np.array([100.0,220.0,300.0,400.0]) def remove_duplicates(u,v,a): u_new, indices = np.unique(u, return_index=True) v_new = np.zeros(len(u_new),

sql query distinct on multiple columns

两盒软妹~` 提交于 2019-12-24 00:07:28
问题 i have this data and i am trying to find cases where there are different ids but duplicate data in Field 1,2,3,4 id field1 field2 field3 field4 ==== ====== ====== ===== ======= 1 A B C D 2 A B C D 3 A A C B 4 A A C B so, in whatever way possible, in this case i want it to somehow show me: 1 & 2 are duplicates 3 & 4 are duplicates 回答1: Instead of SELECT DISTINCT , select the fields and a count of rows. Use HAVING to filter out items with more than one row, e.g: select field1 ,field2 ,field3

Entity Framework - adding the same entity twice in many-to-many relationships

北城余情 提交于 2019-12-24 00:05:00
问题 Ok. So here is the deal. I have two entities - "Product" and "Parts". The product consists of parts. And parts are reusable in other products. The relation between those entities is many-to-many. And it all works great. The problem is that I cannot add the same part to the same product twice. EF seems to force all the related entities to be unique. Consider the following code: var product = context.Create<Product>(); var part = GetSomePart(); Console.WriteLine(product.Parts.Count); // will

removing duplicates - ** only when the duplicates occur in sequence

ε祈祈猫儿з 提交于 2019-12-23 18:35:32
问题 I would like to do something similar to the following, except I would only like to remove 'g' and'g' because they are the duplicates that occur one after each other. I would also like to keep the sequence the same. Any help would be appreciated!!! I have this cell array in MATLAB: y = { 'd' 'f' 'a' 'g' 'g' 'w' 'a' 'h'} ans = 'd' 'f' 'a' 'w' 'a' 'h' 回答1: There was an error in my first answer (below) when used on multiple duplicates (thanks grantnz). Here's an updated version: >> y = { 'd' 'f'

Jar merging for debug throwing duplicate entry with android?

淺唱寂寞╮ 提交于 2019-12-23 16:15:14
问题 Im getting this error when trying to run my build: Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.> com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry: android/support/annotation/AnimatorRes.class Here is my build.gradle dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.android.support:design:23.1.0' compile(

Python: merging tally data

痞子三分冷 提交于 2019-12-23 15:50:31
问题 Okay - I'm sure this has been answered here before but I can't find it.... My problem: I have a list of lists with this composition 0.2 A 0.1 A 0.3 A 0.3 B 0.2 C 0.5 C My goal is to output the following: 0.6 A 0.3 B 0.7 C In other words, I need to merge the data from multiple lines together. Here's the code I'm using: unique_percents = [] for line in percents: new_percent = float(line[0]) for inner_line in percents: if line[1] == inner_line[1]: new_percent += float(inner_line[0]) else: temp =

After duplicating a target in xcode 6 and building with iOS8 sdk unable to install / open it

本小妞迷上赌 提交于 2019-12-23 15:28:40
问题 All I get when trying to build that target is : "The file “appname.app” couldn’t be opened because you don’t have permission to view it." Any idea on how to fix that? 来源: https://stackoverflow.com/questions/26219300/after-duplicating-a-target-in-xcode-6-and-building-with-ios8-sdk-unable-to-insta

Pandas DataFrame count duplicate rows and fill in column

百般思念 提交于 2019-12-23 13:23:12
问题 I have created a DataFrame, and now need to count each duplicate row (by for example df['Gender']. Suppose Gender 'Male' occurs twice and Female three times, I need this column to be made: Gender Occurrence Male 1 Male 2 Female 1 Female 2 Female 3 Is there a way to do this with Pandas? 回答1: Use the cumcount method after grouping by Gender : df = pd.DataFrame({'Gender':['Male','Male','Female','Female','Female']}) df['Occurrence'] = df.groupby('Gender').cumcount() + 1 print(df) Gender

How to append count numbers to duplicates in a list in Python?

。_饼干妹妹 提交于 2019-12-23 12:56:17
问题 Here is a list containing duplicates: l1 = ['a', 'b', 'c', 'a', 'a', 'b'] Here is the desired result: l1 = ['a', 'b', 'c', 'a_1', 'a_2', 'b_1'] How can the duplicates be renamed by appending a count number? Here is an attempt to achieve this goal; however, is there a more Pythonic way? for index in range(len(l1)): counter = 1 list_of_duplicates_for_item = [dup_index for dup_index, item in enumerate(l1) if item == l1[index] and l1.count(l1[index]) > 1] for dup_index in list_of_duplicates_for

Laravel 4: avoid duplicate entry

梦想与她 提交于 2019-12-23 12:29:19
问题 In my app there is a simple form with one field (email) that give the possibility to register to the newsletter. If i entry a new email, all it works fine. If i entry an email that already exists in the database i get the error SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry... Because i had defined that field as unique in the database. All i want to do is to redirect::back()->with('message', 'email already registered') But i do not know how can i do this? I can just put