I am trying to translate couple of columns in cloud MySQL table using googletrans’s Translator function. Here I read the MySQL table: And then here I try to translate it: But when I try to see if the translation took place using below code, I get no output. I am new to SQLALchemy and unable to find a so…
Tensorflow Datasets: Crop/Resize images per batch after dataset.batch()
Is it possible to Crop/Resize images per batch ? I’m using Tensorflow dataset API as below: I want, within the batch all the images should have the same size. However across the batches it can have different sizes. For example, 1st batch has all the images of shape (batch_size, 300, 300, 3). Next batch …
Skip all the test instead of decorating each test function with @pytest.mark.skipif()?
I have a pytest file which requires environment being set. So I add the following decorator on every function. Is it a way to skip all the test instead of decorating each test function? BTW, it just skip the tests with the following message. Is it a way to display a warning information of missing environment …
Python: Vectorize Calculation Implemented using Iterative Approach
I’m trying to implement some calculation, but I can’t figure how to vectorize my code and not using loops. Let me explain: I have a matrix M[N,C] of either 0 or 1. Another matrix Y[N,1] containing values of [0,C-1] (My classes). Another matrix ds[N,M] which is my dataset. My output matrix is of si…
Selling tokens and get BNB instead of wBNB?
I made a function that sells a token in the BSC smartchain. However, I want to receive it in BNB directly instead of wBNB. How can I unwrap the wBNB I receive? Answer I managed to see what’s wrong, It should be
Python skipping functions when ran in VS Code
I have written the following python code to read in XYZ data as CSV and then grid to a GTiff format. When I run the code I am getting no errors. However, after trying to debug, I added some print statements and noticed that the functions aren’t actually being called. How can I run this script so that it…
Cannot run Carlini and Wagner Attack using foolbox on a tensorflow Model
I am using the latest version of foolbox (3.3.1), and my code simply load a RESNET-50 CNN, adds some layers for a transferred learning application, and loads the weights as follows. Now I would like to attack it using the foolbox 3.3.1 Carlini and Wagner attack, here is the way I load the model for foolbox My…
Find the indices where a sorted list of integer changes
Assuming a sorted list of integers as below: I want to find the indices where the values changes, i.e. One approach is to use itertools.groupby: Output This approach is O(n). Another possible approach is to use bisect.bisect_left: Output This approach is O(k*log n) where k is the number of distinct elements. …
How to trim the characters in the string?
I have a list. I want to trim the strings in the list to remove the characters including . sign and the numbers. Expected output: Answer You can use regex with pattern as r’.d+’. This will literally match . followed by one ore more digits.
Get the lines of txt file which not the first part or not exist in another file’s lines in python
I have two txt files and need to get the output in a new txt file : one file has the below (named f.txt): and another file has the below lines (named x.txt): i need to get the lines of f.txt file which not the first part or not exist in x.txt lines to get the output like below :