Skip to content

How do I iterate over two lists?

I have troubles in using for loops in Python. I wrote this code: and the output is: But I would like the output to be: Is there a way to make the for loop iterate over first “Mary” and “she” and then “Joe” and “he” ? I thank you in advance. Answer Why, you can g…

Whats the purpose of torch.positive?

From the documentation: torch.positive(input) → Tensor Returns input. Throws a runtime error if input is a bool tensor. It just returns the input and throws error if its a bool tensor, but that’s not an efficient nor readable way of checking if a tensor is bool. Answer It seems like pytorch added pytorc…

Python String .strip() function returning wrong output

I have the following string I am trying to get 256:0:10.0:34:26:-1478_B02_10m.tif from the string above but if I run It outputs ‘_B02_10m’ Same with filepath.rstrip(‘data/imagery/256:0:10.0:34:26:-1478’) Answer Assuming you want all the string data after the / you can always use string…

web3 python ethereum raw transaction

im getting this error while trying to send ethereum using my local geth node. here is how i build the tx My ethereum account has more than 2 ETH available What am I doing wrong? Answer The node error does not lie, so the node does not think you have 2 ETH available. You can easily check with web3.eth.getBalan…

How to combine line by line dictionary into one?

I currently have a line by line dictionary: Is there a way to turn this into a one line dictionary? The outcome I would like: I’m new to Python and a little lost how to do it to a dictionary. Answer Based on the comments, here is version that reads lines from a file and converts them to one dictionary:

String modification and sampling change

i have this table: ID points values (x1;y1|x2;y2|x3;y3|x4;y4……….) 1 8 0,5;1|1;1,5|4;6|5;7|6;9|8;10|10;12|15;18 2 4 20;30|21;32|22;36|25;37 3 306 1;2|3;6|7;9|10;17|11;18|13;22|14;25|19;26|.. the points determine the number of points. It means for example – 306 (306 x points and 306 y po…

Making legend for subplot with scatter points

I’m trying to make a legend for my subplot using Python. Here’s part of my code: This method works when I was not using subplot, but now it returns me the following error message: I’m not pretty sure how I can fix this issue. Thanks for the help! Answer The code has an object which should no…