#for loop in python
Explore tagged Tumblr posts
Text
Balance
#math#art#geometry#processing#symmetry#perfect loop#mathematics#python#square#mathblr#minimalism#polygon
1K notes
·
View notes
Text
Due to recent experiences, I am feeling an urge to make an anti-drug-style PSA except it's warning impressionable machine-learning-curious teens to never, ever try a thing called "Huggingface transformers Trainer"
Not. Even. Once.
#and don't even get me started on “unsloth”#this week i learned what “unsloth” actually does when you import it and... man.#i thought i'd seen the worst of “hacky brittle 'it-just-works' (by doing the most cursed shit imaginable) ML python code” but no.#no. unsloth was Worse#and huggingface Trainer is bad enough by itself#did you know it has 131 (one hundred and thirty one!) config arguments and yet it cannot log *more than one loss number at once*#(for like multitask training or whatever)#i don't just mean it's hard to do - i mean its logging mechanism is built from the ground up on the assumption you would never do this.#you'd have to rewrite a bunch of internals to get it working - i.e. basically write a new nontrivial feature on HF's behalf#and just writing your own damn training loop is easier than that lol#it's not that hard kids. take it from me. dataset + dataloader + model(*args) + loss.backward() + opt.step() + opt.zero_grad(). that's it#it'll take you 30 minutes and save you a billion hours down the road#i do not understand computers#(is a category tag)
81 notes
·
View notes
Text
Unmute the loop!
121 notes
·
View notes
Text
potent.
#kaleidoscope#blue#visuals#hypnotic#vaporwave#abstract#loop#animation#art#blender#python#artist#artists on tumblr#digital art#animated#artwork#online art#visual art#python3#perfect loop#seamless#seamless loop#vj#vj loop#vj visuals
11 notes
·
View notes
Text
I love replying to Tumblr comments :3
*is hiding in the bathroom avoiding doing my python coding homework*
#python is easier that C sharp but i still fucking hate doing it#coding is the bane of my existence#the fuck you mean a for loop
3 notes
·
View notes
Text
please god please PLEASE say that someone else ships Lemming and Stapleton from monty python
#help me they make me weak in tje knees its so embarrassing#stapleton keeps protecting lemming#and he stamds in front of him yo protect him#and keeps saying things like “no tjere isnt” wjen lemming is aaying “theres something going on jere”#and he keeps explaining eberything to Lemming#he cares about him so muchhhh#their arms are crossed wjen LaFarge storms in and theyre tpuching#their arms are literally LOOPED together#monty python#monty pythons flying circus#lemming of the bda
33 notes
·
View notes
Text
Iterations - for loop
Iteration, aka repeating, is a solution for tasks that need to be done over and over again.
Instead of writing dozens of lines of code for the same purpose, we can simplify it and shorten it to just a couple of lines. This way the code is both easier to read for the other programmers (fellow people hehe) and faster to process for the computer.
Also, simpler code reduces errors rate.
Examples of iterations are loops.
Looping means repeating something until a particular condition is satisfied.
Python has 3 Basic Loops:
For Loop - used when we know number of iterations (repetitions) in advance.
While Loop - for situations where the number of iterations is unknown beforehand.
Nested Loop - using one looping statement inside another looping statement.
For loop is used to execute the same instruction over and over again, a specific number of times.
for i in range(5): print(“Hello!”) Output: Hello! Hello! Hello! Hello! Hello!
In the first line, we declared how many repetitions are needed. In the second line, we wrote what should be repeated a given number of times. In this case, we asked Python to print the string “Hello!” 5 times.
Basic structure of the for loop:
for i in range(5): print(“Hello!”)
for - a keyword that signals that “for loop” is starting.
i - internal variable name which is keeping the counter value. Stands for “iteration”. We can read the whole line as “for 5 iterations/repetitions, please do the following:” For every loop, the 'i' variable increases by 1 because it's the counter. 'i' doesn't have to be 'i', we can switch it to another letter or another word, that are python approved for this (for example, you can’t use name of defined function instead of 'i').
#Loop using "unicorn" as internal variable, instead of "i" for unicorn in range(10): print(unicorn) #still works!
in range() - represents the list of numbers we are looping through (number of time the iteration is running). Python starts the counter from 0. It means that range(5) - will give a sequence of 5 numbers: 0, 1, 2, 3, 4 range() function has 3 parameters(start, end, steps), default values for start is 0 and step is 1. When we write range(5), we only give one parameter, and the function still works, because Python reads it as range(0,5,1) and the sequence starts with 0, increases by 5 counts, with step between each number being 1, by default.
We can change the parameters: range(1,20,3) this would result in iterations that starts from 1, goes up by 3 steps with the upper limit of 20: 1, 4,7,10,13,16,19.
Example: #print every 2 numbers (evens): for i in range (2, 10, 2): print(x) output: 2 4 6 8 (!) output does not include 10 because 10 is the upper limit (result only includes number under 10)
: adding a colon sign in the end of the first line is mandatory, otherwise an error will occur. Finally in the next line, we start writing the instruction, that is supposed to be repeated. This part isn’t starting right away, it should be indented. Indentation is the blank gap at the beginning of lines. Normal indentation is 4 spaces/tab long. Python would recognize 2 spaces or 4 spaces as an indentation, but 4 spaces length is more agreed upon and is used more wildly.
tip: How to write an instruction to get output of a list that starts from 1 instead of 0, accompanied by a string:
for i in range(10): print(i+1, "I love you")
4 notes
·
View notes
Text
I'm taking a class on like. advanced data structures and blah blah whatever blah. riveting stuff. Anyway one the main things we're being taught in the class is runtime optimization which makes sense. but like. why is it being taught in python of all languages
#also the professor writes python like he's writing c sharp. its really bizarre#ramblings#whatever. wearing a t-shirt that says “I <3 nested for loops”
2 notes
·
View notes
Text
Python Interpreter Loop Counter
3 notes
·
View notes
Text
On the sides you can see two curves of constant width, that is a curve whose width is the same in all directions. This is the reason they always touch the two lines as they rotate. The existence of curves of constant width is well known by now. What is much less known is that you can morph between any two such curves such that during the morph the curve stays a curve of constant width. For these two curves the morphing can be seen in the middle. (Actually, you can see two different morphs. )
286 notes
·
View notes
Text
the difference between my enthusiasm after one day of the japanese class and my enthusiasm after one day of the programming class are night and fucking day, to the extent I'm considering just dropping the programming one on the spot
#the professor for the programming class seems like a jackass#and it's also apparently structured more like an 'intro to programming' class instead of a dedicated python thing#I can't see like a full list of topics the class will cover#so I can't tell if they're gonna get around to explaining what python's weird ass loop setups or dictionaries or whatever are#or if it's just gonna be a rehash of the stuff I learned in c programming a decade ago but with a teacher I like less
7 notes
·
View notes
Text
reading a programming book that is using a program that simulates rock paper scissors as the tutorial for loops and it's just. ah. this is me associating ISAT with unrelated things now
#I JUST NEED TO FIND WHERE THEY COVER DO-WHILE LOOPS#--and then I thought to google#guess what: I wasn't finding it because do-while loops aren't a thing in Python#SHAME#but there's other ways to do it
6 notes
·
View notes
Text
Python Loops Tutorial | Loops In Python | Python Loops Tutorial for Beginners
Let's go through a basic tutorial on loops in Python. This tutorial is designed for beginners, and we'll cover the two main types of loops in Python: for and while loops.
1. For Loop:
The for loop is used to iterate over a sequence (such as a list, tuple, string, or range).# Example 1: Iterate over a list fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit) # Output: # apple # banana # cherry # Example 2: Iterate over a range of numbers for i in range(5): print(i) # Output: # 0 # 1 # 2 # 3 # 4
2. While Loop:
The while loop is used to repeatedly execute a block of code as long as the specified condition is true.# Example 3: Simple while loop count = 0 while count < 5: print(count) count += 1 # Output: # 0 # 1 # 2 # 3 # 4
3. Loop Control Statements:
break: Terminates the loop.
continue: Skips the rest of the code inside the loop for the current iteration.
else clause with loops: Executed when the loop condition becomes False.
# Example 4: Using break and continue for i in range(10): if i == 3: continue # Skip the rest of the code for this iteration elif i == 8: break # Exit the loop when i is 8 print(i) else: print("Loop completed") # Output: # 0 # 1 # 2 # 4 # 5 # 6 # 7
4. Nested Loops:
You can use loops inside other loops.# Example 5: Nested loops for i in range(3): for j in range(2): print(f"({i}, {j})") # Output: # (0, 0) # (0, 1) # (1, 0) # (1, 1) # (2, 0) # (2, 1)
This is a basic introduction to loops in Python. Practice with different examples to solidify your understanding. In Part 2, you can explore more advanced concepts and practical applications of loops in Python.
Watch Now: -The Knowledge Academy
2 notes
·
View notes
Text
optimization journey: glue 10000+ arrays together for each data channel -> reduce number of array glueing required by doing 32 sequences at once -> NO array glueing at all!
#tütensuppe#the previous problem i complained about happened bc you cant trick python into skipping for loop iterations#so when you do for i in range(100) and then i+=5 it wont eat it#what i got stuck on was the second flips. im calculating microseconds but the timestamps are not on the full second#so every 32 runs you have a second flip within the 500 data point run#but! you know what you can do!!#calculate the number of total datapoints. first timestamp+total*timestep gets you the final array value.#then do linspace over ALL those values. array%1000000. tada!! all the microseconds#including accurate time flips!#its not running yet though bc i mathed wrong somewhere#but once i fix that i bet its gonna be sooo fast
3 notes
·
View notes
Text
someone remind me at like 6pm bst to put more brackets in the queue i only did enough to cover until tonight
#i spent a uni lecture playing openttd and adding stuff to the queue#i love the lecturer but its basic python he spent the whole lecture rambling about loops and making monty python references
2 notes
·
View notes
Text
i saw this post and decided that i had some time spare, i could give AI another go. (link to post https://www.tumblr.com/dibelonious/778852078032404480/now-that-ai-made-troubleshooting-ridiculously. dont harass the poor old sod obviously.)
i hear a lot of people irl at uni and some online say ai is great for coding, and so every couple months i try it out. sometimes with a very small project in a popular language (python or c, usually. though im forgiveful with c as everyone fucks up c.), sometimes with something simple (i.e. a couple lines tops with a naive approach if written idiomatically) but in a more unusual language with full documentation online. (like sed! yay!)
but every single time i come to the conclusion that even with being handheld chatgpt could not do what it was asked to do. even if someone tells it every issue in its outputs, itll remember for only one prompt. even if someone tells it the solution, itll find a new way to fuck it up.
below the cut is me trying to get chatgpt to make a working sed script that prints "meowwwwwwwwwwwwwwwww..." (long post warning)
(if anything reads weirdly, this was originally a reblog to the screenshotted post, then i decided to make it its own post. so that may be why.)
i cant remember the last time i ran into an issue that i couldnt fix in like ... 5 minutes. but knowing what chatgpt is like, any ask i give it will give me issues to troubleshoot. (yes this example is code, not linux proper. but its more of the same doing that.)
the other day i decided to write "meowwwwwwwwwwwwwwwwwwwwwwwwwwwww....." in many different languages, after seeing @brainfuck-official do it in BF. (link to post https://www.tumblr.com/brainfuck-official/773510105608192000) as is my blog, i asked it to do this in sed.
great! this script doesnt work! it doesnt even come *close* to working, giving me plenty to try out chatgpt's troubleshooting skills! it also just doesnt make much sense. why the shebang but not making it executable? and why are the flags different (ones -f, ones -nf). also a counter? why though? thats not what im asking for? (you can see tags for a brief explanation on how to add a counter)
after telling it the script doesnt work (and why, something someone troubleshooting likely wont know) it just adds in a P. a command that prints a damn newline. but it lies about it printing a newline.
(if you dont believe it prints a trailing newline and believe the AI instead, just try echo -n foo | sed -n 'P ; P')
anyways it alternated between no print statements and printing with newlines for the next ... 8 prompts, by which time i felt sorry for the poor bugger and told it to use e to print without a newline.
all the while it was trying to be more useful and add a count - making it print my string after n repeats instead of the infinite that i asked for. it was trying to subtract 1 with effectively s/[0-9]+/&-1/ which just appends the string "-1" to a number!
anyways, i tell it to use "the e command". there are three different versions of the e command in sed, and only one of them makes sense here. which did chatgpt use? none! it used the e regex modifier! which executes your pattern hold, then turns the output into the new pattern hold. and does not print anything.
ill just screenshot the last couple interactions minus only the useless exposition it adds to every response so you can see how stupid it is
ignoring sed's requirement for an input this is equivalent to the python
to be fair i never said there shouldnt be infinite meows, and this does have infinite Ws. but come the fuck on. this is clearly not whats being asked for.
#linux is best - yes. but learn to troubleshoot properly.#blindly copying code online without understanding it isnt troubleshooting.#regardless if that code came from stackoverflow or chatgpt.#anyways maybe it wouldve been better to write the equivalent in C with gotos and labels?#but at least everyone knows python#and i dont need to write c this way#also decided to see if it could find any info about me if i give it my name and county of origin#which is identifiable information but its outdated as ive changed my name (trans :3) and moved away.#anyways it thought i was from l*nd*n.#i told it where i was from (West Country. Very Much Not london.) and it thought i was a londoner. what in the hell.#yes if i said the name of most counties to an american online theyd probably think its in london.#but thats before they google the damn place! and this bot has access to the whole internet!#(for the yanks: it did the equivalent of calling an appalachian a californian)#(or at least i think thats close enough. im not really all that sure about what happens over the pond. and i like my ignorance here.)#wait the documentation tells you how to make a counter. at least twice.#IT COULD COPY CODE FROM THE INFO PAGES FOR THE COUNTER AND IT STILL GOT IT WRONG EVEN AFTER BEING TOLD WHY ITS WRONG#oh my god.#anyways in the docs they wanted to print the number. you can just hold n chars and remove one each loop#then break the loop when your hold is empty.#thats the easiest way ive found of looping n times (if you need the hold do this on a prepended line)#(not efficient but you can make it more efficient if you want. the docs explain how to! but its more effort and easy to fuck up soooooo...)#printing n ws though? just use e printf like it bloody demonstrates itself#no need to do inefficient shit in sed when someones written it in c for you.
0 notes