sample_set ={‘a’, 1234, ‘xyz’, 12.454} print(sample_set.add(‘1232’)) Gives output as : None What I am trying to understand is , why doesn’t the nested ‘.add’ function work and prints a set with an additional element 1232 ? Source: Python..

#### Category : function

I want to sort a hand of cards by alphabetical order first (Club, Diamond, Heart, Spade) and then by rank (Ace to King). I have the following (very lengthy and inefficient) code but the output seems wrong. I feel like it is an issue with the bubble sort that I use. What am I missing ..

I’ve got an error in python trying to do my homework for python course. The task was to create an array of expenses using operations such as add and list(printing all the elements) The error persists in any version of Python (3.7,3.8,3.9) and in different IDEs ( Visual Studio, PyCharm, some online interpretator) To describe ..

I have a function that should return a gradient. def numerical_derivative_2d(func, epsilon): def grad_func(x): grad_func = (func(x + np.array([epsilon, 0])) – func(x)) / epsilon, (func(x + np.array([0, epsilon])) – func(x)) / epsilon return grad_func But when calculating the gradient at a specific point, I get None. t1 = lambda x: ( -1 / ((x[0] – ..

I am currently in the process of creating a "hangman" game. Below is a function I have developed that returns the unused letters. However I am not sure how to save the value I receive from the function and use it again when it loops in in the while loop… This is what it is ..

I use this function: from sklearn.datasets import load_iris from sklearn.linear_model import LogisticRegression X, y = load_iris(return_X_y=True) for i in range(X.shape[1]): clf = LogisticRegression(random_state=0, verbose=0, max_iter=1000).fit(X[:,i].reshape(-1,1), y) print(clf.score(X[:,i].reshape(-1,1),y)) and i get 4 values as output: 0.7466666666666667 0.5533333333333333 0.9533333333333334 0.96 But when i try to add these 4 values to list: from sklearn.datasets import load_iris from sklearn.linear_model ..

I have a dataframes. X is dataframe with features. Y is predicted values. I want to write a function to get all accuracies ifI train with model with each column from X. I try this code but it doesn’t work: import sklearn.metrics as mtr from sklearn import linear_model model = linear_model.LogisticRegression(max_iter=3000,solver=’lbfgs’) model.fit(X, Y) def accuracies_find(X, ..

I have table with three columns : years, pop1 and pop2, when pop1 and pop2 are population size in two different countries during 300 years. My goal is to create unction that finds the year where the population size shrinked in two times/10times/100 times. For that I have built a function with conditions that checks ..

I have table of population size in two countries in different years that looks like this: year pop1 pop2 0 0 1.000000e+08 1.000000e+08 1 1 9.620000e+07 9.970000e+07 2 2 9.254440e+07 9.940090e+07 3 3 8.902771e+07 9.910270e+07 4 4 8.564466e+07 9.880539e+07 The table has information only about the first 300 years. I’m trying to create a function ..

So i have this class: import matplotlib.pyplot as plt import numpy as np class F: def __init__(self,n,m): self.n=n self.m=m def __call__(self,x): return np.sin(self.n*x)*np.cos(self.m*x) pi=2*np.pi u = F(7, 1) v = F(3, 5) x=np.linspace(0,2*np.pi,10000) plt.plot(u,v) plt.show So I get the error: TypeError: float() argument must be a string or a number, not ‘F’ When I print ..

## Recent Comments