I am taking multiple different different sorting algos and benchmarking their times based on different sizes of arrays and different sorting of arrays. IE sorted, random, and reverse arrays ranging from 10^0 to 10^8. I am getting an error whenever I try to use a random_swap function within the main benchmarking function, and I cannot ..
I am a student who tries to learn OOP in python and in general, and for the sake of practice, I am writing a class that makes right triangles and calculates their hypotenuse using the Pythagoras theorem. A pretty straightforward program, but it revealed that I have some practice to do when it comes to ..
I’m writing a script for a deck of card in an OO way as shown below. class Deck: def __init__(self): self.card_list = self.build() def build(self): suit = ["S", "H", "D", "C"] val = ["ace", "two", "thr", "fou", "fiv", "six", "sev", "eig", "nin", "ten", "jac", "que", "kin"] return list(itertools.product(suit, val)) def deal(self): cards = random.choices(population=self.card_list, k=3) ..
I have a matrix like this and I want the diagonal to be 1 if the row sums to 0. In this case, (2,2) and (3,3) will become 1. I wrote a for loop. Though using .all(), it is giving me a value error point to the if line. Markov_sub 1 2 3 4 5 ..
I downloaded a zipped file from S3 and unzipped it: with zipfile.ZipFile(‘/tmp/DataPump_10000838.zip’, ‘r’) as zip_ref: testList =  for i in zip_ref.namelist(): if (i.startswith("__MACOSX/") == False): val = ‘/tmp/’+i testList.append(val) Now, I have a few unzipped files in my /tmp folder. I want to open those files, gzip and move them to an S3 bucket. ..
I was writing a function to read csv by pandas and preprocesses its columns types by ast.literal_eval(). my function However, I got this ValueError: malformed node or string: <_ast.Name object at 0x7f02ef6e6290>. I know that ast.literal_eval(node or string) and I already use str(x) in my lambda function to transform the entry to string type first ..
I want to check the input format for a given function with a list of lists as input. I have used the code below to indicate at which index the input file has the wrong format: for i, doc in enumerate(input_file): if not isinstance(doc,list): raise ValueError("The element of input_file at index ‘ + str(i) + ..
I’m trying to do cross validation to select the maximum degree of polynomial to add to my features in a Logistic regression. But I get the following error ValueError: could not broadcast input array from shape (928,2) into shape (928,0), which I understand means elements in my input array must be equal to elements of ..
I have Data Frame in Python Pandas like below with str values: NR ——– 910517196 921122192 020612567 And I try to calculate age based on values in column "NR" using below code: ABT_DATE = pd.Timestamp(year=2021, month=6, day=30) df[‘age’] = (ABT_DATE – pd.to_datetime(df.NR.str[:6], format = ‘%y%m%d’)) / np.timedelta64(1, ‘Y’) df["age"] = df.age.astype("int") Logic of above code ..
I am working with a text file where I’m making a dict and zip function for a login page. But for some reasons, it gives me the ValueError from time to time. This usually happens when I manually edit or remove data from the text file and will be fixed if I create another text ..