I am developing a Keras model. My dataset is badly unbalanced, so I want to set a threshold for training and testing. If I’m not mistaken, when doing a backward propagation, neural network checks the predicted values with the original ones and calculate the error and based on the error, set new weights …
How to receive and send message to specific channel in Discord.py?
Yesterday I was working on something simple where a bot on command of !name Barty would print back Hello Barty However the problem I am facing at this moment is that the bot would response to any channel where I do use the !name XXXX and what I am trying to do is that I want only to react to
Python – How to send an html email and attach an image with Python?
I am getting an “error: ValueError: Cannot convert mixed to alternative.” I get this error when I insert the open image and msg.add_attachment block (highlighted in btw #### ####). Without it, the code runs fine. I need to send the email as html and with the image attachment. For the end result, I…
While loop spamming output instead of printing output once?
I’m making a regular guess the number game. I’m having problems when I enter the guess and the program spams lower or higher instead of just typing it once, since I’m using a while True loop. Here I’m just opening the CSV file and picking a random number. Here I’m importing numbe…
Different types of inner classes in Python 2 and Python 3
I am upgrading my project from Python 2.7 to Python 3.7 and in my code I have something like this: now type(A.B()) returns different things in the two Python versions: In Python 2.7 I get: <class ‘__main__.B’> In Python 3.7 I get: <class ‘__main__.A.B’> Can anybody explain …
How to write timestamp to txt file when milliseconds are zeroes in python
I’m extracting create timestamp from DB/2 table and writing it to a txt file to be used in later processing. Python writes the timestamp correctly except when the milliseconds are zeroes. When the milliseconds are zeroes, it does not write the milliseconds. How can I make it write the zero milliseconds?…
Compiling and executing simple user defined code in Python
I want to allow my users a way to run very simple Python functions for a project. Of course, eval() comes to mind, but it is a huge risk. After thinking about it for a time, I realized that most of the functions that a user might need are very rudimentary, similar to the most common excel functions. So I
How to rotate square numpy array of 2 dimensional by 45 degree in python?
I have a numpy array of images. The dimension is 2 and the shape is (100,100). I want to augment more data as I have only 52 set of numpy array. I want to rotate the given array by 45 degree. What should I do for that?? Suppose the array be like Please rotate the given array by 45 degree.
How to get the Toggle flag value and sum of rows between the flag toggle
In continuation to my previous Question I need some more help. The dataframe is like I am trying to have the flag state value along with the toggle count, Means flag toggling state. The output should look like this Can someone help with this? Answer Create helper Series with shift and cumsum and aggregate sum…
Pandas .isin on column entries containing lists
I am trying to filter a dataframe using the isin() function by passing in a list and comparing with a dataframe column that also contains lists. This is an extension of the question below: How to implement ‘in’ and ‘not in’ for Pandas dataframe For example, instead of having one countr…