Category "python"

error: Incompatible return value type (got "Tuple[Tuple[float, float], ...]", expected "List[Any]")

Context While trying to implement static typing, I'm experiencing some difficulties in specifying the return type of the following function: def create_hexagon_

Is there a way to shorten this code to fewer lines?

some_var = 0 for i in range(16): if 0x7777 >> i & 1: some_var += 1 Is there a way to shorten this code to use fewer lines? It's a simple

Pandas implement an any check

How do I check a Pandas column for "any" row that matches a condition? (in my case, I want to test for type string). Background: I was using the df.columnName.d

Imposing constraints on all (numbered) diagonals in CVXPY

I am looking to implement a constraint on an optimization on all diagonals of a matrix using CVXPY. The diag function in CVXPY only returns the main diagonal.

tensorflow: Fail to find dnn implementation

I'm trying to run my code Keras CuDNNGRU on tensorflow using gpu but it always get error "Fail to find dnn implementation" even though I already installed CUDA

How to deal with files with no extension in Python

I am currently writing a script for work, which goes through every file in a directory and its many sub directories and counts the amount of lines in each file.

Read and group json files by date element using pyspark

I have multiple JSON files (10 TB ~) on a S3 bucket, and I need to organize these files by a date element present in every json document. What I think that my c

KeyError: 'Failed to format this callback filepath: "skintype_64_rmsprop_{val_loss:.3f}.h5". Reason: \'val_loss\''

I have been trying to train my skin type classification model but it shows error. model_name = f"skintype_{batch_size}_{optimizer}" tensorboard = tf.keras.callb

Count all NaNs in a pandas DataFrame

I'm trying to count NaN element (data type class 'numpy.float64')in pandas series to know how many are there which data type is class 'pandas.core.series.Seri

Python program works only from pycharm, not somewhere else

The script works fine when I run it in pycharm, but if I run it from somewhere else it just doesn't work. When I run it via cmd it gives me this error: Tracebac

How do I mock a function with no parameters that sets a class attribute for Python unit tests?

My class, Foo, has a calculate method that takes no parameters, makes a call to a database and does some calculations using class attributes, and sets another c

Review the \n (newline) values with proper representation in DataFrame

I have this: test = ['hey\nthere'] Output: ['hey\nthere'] And when I insert in into the DataFrame it stays the same way: test_pd = pd.DataFrame({'salute': test

Reordering the high-level clusters from seaborn clustermap results

Is there a way to get from a to b in the following figure with scripting? I am using seaborn.clustermap() to get to a (i.e. the order of the rows are preserved.

x and y must be the same size

Using python I'm trying to plot a sin wave and random distribution, then show where the ratio is greater than or equal to 3. I think I'm 90% of the way there bu

RL + optimization: how to do it better?

I am learning about how to optimize using reinforcement learning. I have chosen the problem of maximum matching in a bipartite graph as I can easily compute the

Python 3.8.6 says I have a newer version of Python installed, but I don't

I just installed Python 3.9.0 and I found out Pygame hasn't been fully released yet in this Python version. I then tried to uninstall Python and it said it unin

Adding new multiindex level

I have a DataFrame: d = pd.DataFrame({'i1': ['A', 'B', 'C', 'D', 'E'], 'i2': ['I', 'II', 'III', 'IV', 'V'], 'val': ["lol1",

Changing column order in python pandas using pivot table pd

I would love to change the order of my pivot table using pd (pandas) Current layout Code: pd.pivot_table(df.loc[filt], index=['region','brand'], values

The method np_utils.to_categorical give me an error

np_utils.to_categorical Keras method give me an error when i gived it a a vector of [962] element which contain 3 classes [1,1,1,...,2,2,2,...3,3,3]. The used

Pydantic - Dynamically create a model with multiple base classes?

From the pydantic docs I understand this: import pydantic class User(pydantic.BaseModel): id: int name: str class Student(pydantic.BaseModel): sem