normalization

How to normalize a NumPy array to a unit vector?

How to normalize a numpy array to a unit vector Question: I would like to convert a NumPy array to a unit vector. More specifically, I am looking for an equivalent version of this normalisation function: def normalize(v): norm = np.linalg.norm(v) if norm == 0: return v return v / norm This function handles the …

Total answers: 16

How to normalize a confusion matrix?

How to normalize a confusion matrix? Question: I calculated a confusion matrix for my classifier using confusion_matrix() from scikit-learn. The diagonal elements of the confusion matrix represent the number of points for which the predicted label is equal to the true label, while off-diagonal elements are those that are mislabeled by the classifier. I would …

Total answers: 9

Normalizing pandas DataFrame rows by their sums

Normalizing pandas DataFrame rows by their sums Question: What is the most idiomatic way to normalize each row of a pandas DataFrame? Normalizing the columns is easy, so one (very ugly!) option is: (df.T / df.T.sum()).T Pandas broadcasting rules prevent df / df.sum(axis=1) from doing this Asked By: ChrisB || Source Answers: To overcome the …

Total answers: 2

Finding the max and min in a tuple of tuples

Finding the max and min in a tuple of tuples Question: I’m new to python and having some problems finding the minimum and maximum values for a tuple of tuples. I need them to normalise my data. So, basically, I have a list that is a row of 13 numbers, each representing something. Each number …

Total answers: 3

How to normalize a 2-dimensional numpy array in python less verbose?

How to normalize a 2-dimensional numpy array in python less verbose? Question: Given a 3 times 3 numpy array a = numpy.arange(0,27,3).reshape(3,3) # array([[ 0, 3, 6], # [ 9, 12, 15], # [18, 21, 24]]) To normalize the rows of the 2-dimensional array I thought of row_sums = a.sum(axis=1) # array([ 9, 36, 63]) …

Total answers: 12

Intensity normalization of image using Python+PIL – Speed issues

Intensity normalization of image using Python+PIL – Speed issues Question: I’m working on a little problem in my sparetime involving analysis of some images obtained through a microscope. It is a wafer with some stuff here and there, and ultimately I want to make a program to detect when certain materials show up. Anyways, first …

Total answers: 3

Figure out if a business name is very similar to another one – Python

Figure out if a business name is very similar to another one – Python Question: I’m working with a large database of businesses. I’d like to be able to compare two business names for similarity to see if they possibly might be duplicates. Below is a list of business names that should test as having …

Total answers: 10