numpy

How to sort GridSearchCV.cv results

I'm taking a course in data science and they use the sklearn library, where there is a GridSearchCV method, the problem is th ... ain_fin, y_train_fin) sorted(gridsearch.cv_results_,key = lambda x: -x.mean_validation_score) What could be the problem ?

How to generate a list or array in Python

I have the original random array: np.array([0, 1, 2]). You need to get two rows of numbers (lists or one-dimensional arrays ... _2] Is there a faster way to generate such series of numbers m_1 and m_2 in another way, for example, using list generation?

How do I make an image mask that changes part of the image to grayscale?

You need to put a circle on the image, outside of which the image will change color to grayscale, and inside the circle the c ... = img1-41 ax_1.axis('off') ax_1.imshow(ax_1.Img) Who knows how this can be implemented? The first picture in the image: .

How do I create a two-dimensional numpy array with a certain dimension?

I can't figure out how to create an array with a certain dimension, that's what I mean, that's how I create it now: A = np.a ... ad the documentation and didn't really understand the append method and the meaning of "axis". Please help me how to do this?

How do I delete duplicate rows in an array?

Given a NumPy array: [[1 0 1 0 0 1] [1 1 1 0 0 1] [1 0 1 0 0 1] [1 0 1 0 1 1] [1 0 1 0 0 1]] a = [[1, 0, 1, 0, 0, 1], ... np.array(a) How can I delete duplicate rows? That is, the output should be: [[1 0 1 0 0 1] [1 1 1 0 0 1] [1 0 1 0 1 1]]

Why does numpy incorrectly count the determinant of a matrix

import numpy as np A = np.array([[1, 1, 2, -1], [2, -1, 0, -5], [-1, -1, 0, -2], ... r 5.329070518200744e-15. What am I doing wrong? Maybe I was inattentive somewhere, and if not, how is it better to calculate?

Finding the root of a function by the dichotomy method

I am doing a course work assignment on Numerical Methods and Computer Modeling: find the root of a function and display the f ... ction itself, so that it searches for values only in the array, or the plotting function. Help, please, kursach is close. ;)

How to fill in NaN if one value is possible?

Let's imagine a table of two columns in a dataframe: 0 NaN 0 NaN 0 1 1 0 1 5 1 NaN 2 0 0 NaN 0 1 2 1 2 NaN 3 NaN 3 500 3 N ... y the only non - NaN value on the right? Desired result: 0 1 0 1 0 1 1 0 1 5 1 NaN 2 0 0 1 0 1 2 1 2 NaN 3 500 3 500 3 500

Replacing values with NaN

I work with a table of data that has both positive and negative values. How can I replace all positive values in a certain column with NaN? I tried it like this: df.loc[df['days_employed'] > 0, 'days_employed'] = "NaN" But I got an error.

Functions (metrics) for assessing the quality of classification

How can I use sklearn or numpy to find the fraction of wrongly predicted values? There are two arrays of numbers of the same ... d to compare them, and divide the number of incorrect answers by the length. Is it possible to do this somehow in 1 function?

How do I add a new column with a category as a result of grouping the previous ones?

There is a DataFrame with columns 'floor' and 'floors_total'. I need to add a separate column with their grouping: 'First', ' ... re not correct in most cases (they do not fit the 'floor' == 'floors_total' condition). Can you tell me what I'm doing wrong?

numpy. Python does not change the list item. (does not modify) Gauss algorithm for SLOUGH

My program should solve SLA with square matrices without FSR by the Gaussian algorithm. SLOUGH is represented as Ax = f. im ... 'VECTOR f:\n',f,'\n\n') AA = A ff = f xx = np.linalg.solve(AA, ff) print('My solution:\n',x) print('Numpy solution\n',xx)

How do I check if all the elements in a numpy array are the same? Python

An array is given: import numpy as np a = np.array([1, 0, 1, 1, 0]) [1 0 1 1 0] Please tell me how you can check whether all the elements in the array are the same or not?

ValueError error: The truth value of an array with more than one element is ambiguous.Use a.any() or a.all()

import pandas as pd import numpy as np from sklearn.tree import DecisionTreeClassifier from sklearn.model_selection import tr ... an error. ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

scipy.linalg.solve banded. Which matrix should I use for the run-through method?

I want to use the scipy.linalg.solve_banded method to solve SLOUGH, but I can't figure out how the ribbon matrix is represent ... од x[n-1] = f[n-1]/A[n-1][n-1]; for i in range(n - 2, -1, -1): x[i]=(f[i] - A[i][i + 1]*x[i+1]) / A[i][i] #Вывод print(x)

The exe file is instantly closed if the numpy library is imported

There is a code: import numpy while True: print(123) If you make an exe from it, the file will instantly close when op ... sted in why it causes the exe to close instantly. Maybe someone knows?) If you import, let's say only argmin, nothing changes

sorting a numpy array string

You need to sort only the first row of the two-dimensional array in ascending order so that the second row is associated with ... It turns out: [[10 20 30] [ 0 1 2]] It is necessary that the second row is not sorted, but is linked to the first row.

Libraries for working with images

I need to go through all the pixels of the image. What libraries can I use to do this?

Reducing the lower triangular matrix to a symmetric one

There is a lower triangular matrix of the form: 0.0 0.5 0.0 0.4 0.6 0.0 Written as a list of lists [[0.0], [0.5, 0.0], [0. ... 0.0 0.6 0.4 0.6 0.0 I guess that there is some method in numpy, but I'm not very familiar with this package, I can't find

How to find the Euclidean distance of two matrices?

There is a numpy array X, with dimension (num_test, D), where D is a matrix of some size. There is a numpy array X_train, wit ... trying to figure out how to do it. Therefore, it will be even better if you explain in terms of check out what you're doing.