how to find the unique items in a list in python
I have a list,
mylist=[4, 4, 2, 1, 2] my expected output is =
list(set(mylist)) but its not helping
thanks in advance
You may use
collections.Counterto get the count of all the items present in the list, then filter it using list comprehension the items having count as
>>> from collections import Counter >>> mylist=[4, 4, 2, 1, 2] >>> [k for k, v in Counter(mylist).items() if v==1] 
See also questions close to this topic
Tied weights in tensorflow recurrent cell
In the context of an fully-connected autoencoder this paper states that one type of regularization is to use tied weights for weight matrixes (section 2in the paper). In the paper the weight matrix for the decoder is the transposed of the encoding matrix of the encoder. A pseudo-python writing of this in tensorflow can be:
import tensorflow as tf encoder_activation = tf.add(tf.matmul(input_data, W_encoder),self.b_encoder) encoder = tf.tanh(activation) decoder_activation = tf.add(tf.matmul(encoder, tf.transpose(W_encoder)),self.b_decoder) decoder = tf.tanh(decoder_activation)
Where input_data is a placeholder and b_* and W_encoder are the biases and tied weight matrix of the encoder. Shapes are given so that no dimensionality problems arises.
My question would be how would I use tied-weight matrix on a Tensorflow recurrent cell ? If possible a pseudo python/code hint of the main idea is verry appreciated. I'm not too familiar with the inner workings of the rnn cell. Consider the most basic cell that make illustration of this more easy
Imitate the copy function of Excel or Libre Office with openpyxl and python3 (copy with properties to new position)
is there a way to imitate the copy function of "Excel" or "LibreOffice Calc" using openpyxl and python3?
I would like to specify a certain range (e.g. "A1:E5") and copy the "border", "alignment", "number_format", "value", "merged_cells", ... properties of each cell to an other position (and probably to another worksheet), whereby the used formulas should be updated automatically to the new position. The new formulas are intended to refer to cells within the target worksheet and not to the old cells in the original worksheet.
I generate a workbook for every month. This workbook contains yield monitoring tables that list all working days. Although the tables differ from month to month, all have the same structure within a workbook, so I would like to create a template and paste it into the individual worksheets.
Copying the entire worksheet is not really a solution because I also want to specify the position of the table in the target worksheet.
My current code (where the formulas are not automatically updated):
import copy # The tuple "topLeftCell" represents the assumed new position in the target worksheet. It is zero-based. (e.g. (0,0) or (7,3)) # "templateSheet" is the template from which to copy. # "worksheet" is the target worksheet # Create the same "merged_cells" as in the template at the new positioin for cell_range in templateSheet.merged_cells.ranges: startCol, startRow, endCol, endRow = cell_range.bounds worksheet.merge_cells(start_column=topLeftCell + startCol, start_row=topLeftCell + startRow, end_column=topLeftCell + endCol, end_row=topLeftCell + endRow) colNumber = topLeftCell + 1 # 1 is added up because topLeftCell is zero based. rowNumber = topLeftCell + 1 # 1 is added up because topLeftcell is zero based. # Copy the properties of the old cells into the target worksheet for row in templateSheet[templateSheet.dimensions]: tmpCol = colNumber # sets the column back to the original value for cell in row: ws_cell = worksheet.cell(column=tmpCol, row=rowNumber) ws_cell.alignment = copy.copy(cell.alignment) ws_cell.border = copy.copy(cell.border) ws_cell.font = copy.copy(cell.font) ws_cell.number_format = copy.copy(cell.number_format) ws_cell.value = cell.value tmpCol += 1 # move one column further rowNumber += 1 # moves to the next line
Since copying ranges is actually a common task, I assumed that openpyxl provides a function or method for doing so. Unfortunately, I could not find one so far.
I'm using openpyxl version 2.5.1 (and Python 3.5.2).
Best regards AFoeee
sigmoid + binary_crossentropy and flow_from_directory
If we want to use sigmoid + binary_crossentropy for multilabel classification (like each image can have multi labels) in Keras, we need to write custom batch generator,
flow_from_directory can't be used?
3 Tiered Drop-Down Lists with Data Validation in Excel
I am trying to create a drop down list to filter to a specific combination that exists in a table e.g. here
But the named ranges and INDIRECT method doesn't work for me because I have duplicates across the columns. Does anyone know how to do this in a different way , don't mind if it has to be a macro.
Data example HERE
Apply a list of filters to a dataframe coming from a list using pandas
I have a list of columns to apply filters in a dataframe which comes from a list. The filter values comes from another list.
Earlier when the lists were of fixed, I used the following statement to get the job done:
df_result= df[(df[filterfieldList] == filterValuesList) & (df[filterfieldList] == filterValuesList) & (df[filterfieldList] == filterValuesList)]
But as the weeks progressed I get a new requirement that the filtering list would be dynamic and I couldn't figure out how to do that now. As in, sometimes, the filters list will have only 2 fields to filter, sometime 3 or 5. How to do the filtering in this situation?
A B C D E Project 1 Org_1 Directory MSTR Configuration Project 1 Org_1 Directory MSTR Unable to Login Project 1 Org_1 Desktop Software MSTR Configuration Project 1 Org_1 Desktop Software MSTR Configuration] Project 1 Org_1 Directory MSTR Unable to Login
List of mathematical operations in Prolog
I've created a list of a mathematic expression such as
[1,+,2,-,3]and I'm trying to get this evaluated as
1+2-3 i.e 0. However, I'm having trouble implementing this.
Here is the code I've tried:
test(List, Atom) :- atomic_list_concat(List, '', Val), Atom is Val.
Any help would be much appreciated.