Skip to content

Tag: python

Python script for ‘ps aux’ command

I have tried to use subprocess.check_output() for getting the ps aux command using python but it looks like not working with the large grep string. Can anyone have any solution? Answer Yes, I have found the solution to achieve the output, We can use the following code snippet to find the PID as output. Instea…

save the cropped bounding box

I want to crop and save images from all the dataset which contains multi classes. but there is no output. and thank you. Answer Assuming everything else are correct (since I don’t have your dataset and detector code), you may want to try to correct couple indentations to see if you can get some differen…

python – Weight for weight from CodeWars

The code works, but at the same time it outputs a string in which the same value can be reversed. Therefore, it gives an error in tests Here is the code itself: enter image description here Answer Find it’s harder to follow your logic, but this will be my simple approach: Please read and compare with yo…

Mark selected pixels in an image with circle

I have an image, and I have to mark pixels whose intensity value is less than threshold value with a circle. How do you do this, Scatter plot wont work as we need two input. Help in this regard is appreciated. Answer You can use the Circle patch function from matplotlib (see doc here). Here is an example insp…

expend valid string in byte array

array x contains string followed by all zeros. I need expand the string but keep x array’s size the same. e.g.: expected output: What’s propery way to do it in python3? Answer You can use ljust to add a number of characters to make the resulting bytes the length you want: So, all in all: strip the…

Pandas adding rows to dataframe

I’m trying to add more rows or records to my data frame, let’s say it looks like this: and I have a CSV file stored in another data frame without headers now I want a new data frame that looks like this I have tried using append and concat but I didn’t get the result that I wanted Answer Ass…