Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 months ago.
Improve this question
I've been struggling to understand this code despite having searched google for codes that look like this (or parts of the code) for some while now and was wondering if someone could help me understand this.
(img.sum(dim=1)!=0).float()[:, None, :, :]
(for reference, the original code is from line 561 of this file.)
From what I've understood so far,
It seems like img.sum(dim=1) wants to sum up all the values of the img along their columns (so sum up horizontally across columns).
I'm not sure what exactly the !=0 part is doing, but I assume it's going to give me a boolean value of img.sum(dim=1), with 1 or 0 for each row depending on the sum's value.
And the values are converted to float through .float()
This is where I'm getting most confused. I had thought that (img.sum(dim=1)!=0) gave me just four rows, with one value in each row. Then why would be have ":", which I understand to select everything? (Are my interpretations 1-3 wrong?) Also, what exactly is the None doing?
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 11 months ago.
This post was edited and submitted for review 10 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
When I have a number that has a decimal in it I set it to a float but that seems to stop the greater than and less then from working
nm=".01"
nm=int(float(nm))
if nm >= .01:
print("True")
else:
print("False")
When the script finishes it prints False when it should be True because .01 is equal to .01
I've tried stuff like switching which order the code is in, rearranging the code, and even getting rid of the float but nothing is working.
I am really new to coding so please bare with me.
nm=int(float(nm))
lets say the input is "0.1" as input() returns string
it first gets converted to 0.1 by float()
then it gets converted to 0 by int()
and 0 happens to be less than .00000000001
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
The problem he faced is briefly. I need to write a function that calculates the factorial. This function must calculate the factorial of the numbers I send (of more than one number). After calculating the factorial of the numbers I sent him, he should add them all and send them back to me. I do both separately, but I cannot do it together. I leave the link of the codes.
https://pastebin.ubuntu.com/p/dRJnMT7fkt/
enter image description here
Maybe you can use this:
def Faktoriyel(a):
sonuc=0
for f in a:
sonucumuz=1
for i in range(1,f+1):
sonucumuz *= i
sonuc += sonucumuz
return sonuc
Here you go as you requested one function.
If it helps you please upvote and accept the answer.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
This is my first week at college (Cyber security), and I don't have any coding background.
For a python assignment, I have to round the amounts to two decimal places, but if the last decimal is a zero, it should not show in the output. What is the appropriate rounding code I should use?
This is my code:
if (valuta == 1):
print("Voor", bedrag, "US Dollar krijgt u ", round(USDollar,2),"Euro, De transactiekosten bedragen", round(DollarTransactiekosten,2), "Euro. U ontvangt",round(AfgerondDollar,2), "Euro" )
Edit: Thanks for all the answers and help guys
It looks like you're new to programming, so here's a few pointers. I'm not going to write all the code you need for an answer here because then how will you learn? Instead, here's the thought process behind coming up with a way to code a solution to your problem.
We have a number x.
We want to round it to two decimal places.. Think about what format specifier you'll use. Let's save this result in str_x.
If the last character in this string is a zero, we want to get rid of it.
What we have now is what we required.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm currently experimenting with the Black code formatter for Python.
In >90% of the cases I am happy with the output (with default configs), but it regularly happens, that it formats some lines in a way that seems rather ugly to me.
Here an example, before and after formatting with black.
Before:
After:
The syntax of these two lines is originally identical (same function, same number of arguments...), so it makes sense to format them in the same way. However, as the first line is slightly longer, Black formats it differently, which makes it much more difficult to read and interpret the code.
Of course, in this particular case, you could just increase the linelength parameter of Black, but that doesn't really solve the problem in general, and I would like to stick with the default configuration.
I have come across many such situations, also using other formatters such as Prettier for JavaScript.
How do you handle these situations? Is there for example a way to tell Black, to ignore these particular lines and not format them?
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
For an online assignment to be submitted for a MOOC, I have written a python program that takes in text data (The name, roll numbers, grades, etc of a list of students) in a particular format and prints the output after processing the data. The output is printed from a list of tuples using a for loop to iterate through the list and using the str.join() function to join the elements in the tuples.
The list of tuples is sorted already and when I run it in the Spyder IDE console, it prints the output in the order that it appears in the list. But, when I submit in the window of the online judge and run it, the output is obtained in a random order and my answer doesn't get accepted. Can anyone please help? I am all ready to clarify further if my question isn't clear.
Thank you.
As #Epo rightly pointed out, I tested my input with alphabetically sorted data while the online judge used the same data sorted differently as input. Adding a "sorted()" function to the input did the job.