User contributions for Davrot
From Master of Neuroscience Wiki
15 October 2025
- 13:2613:26, 15 October 2025 diff hist +8,182 N Files Created page with " == The goal == How to deal with (non-numpy) files under Python? Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://docs.python.org/3/library/functions.html#open Open] a file == <syntaxhighlight lang="python">open(file, mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)</syntaxhighlight>The available modes are: {| class="wikitable" !Character !Meaning |- |'''‘r’''' |'''open for reading (default)''' |..." Tag: Visual edit
- 13:2513:25, 15 October 2025 diff hist +12,997 N Type annotations Created page with " == Goal == We want to use static type checking and type annotations in our Python code for detecting errors we made. We will use the mypy extension in VS code for that.<syntaxhighlight lang="python">a: int = 0 b: float = 0.0 a = b Incompatible types in assignment (expression has type "float", variable has type "int")</syntaxhighlight>Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Why [https://peps.python.org/pep-0484/ Type hints]? == Why we got type..." Tag: Visual edit
- 13:2513:25, 15 October 2025 diff hist +14 N File:9087234 image0.png No edit summary current
- 13:1713:17, 15 October 2025 diff hist +11,492 N Functions Created page with " == The goal == A function allows to separate a part of the code in a logical module that can be reused. Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''Logic blocks need to be indented. Preferable with 4 spaces!''' == [https://docs.python.org/3/tutorial/controlflow.html#defining-functions Most simple function] == These three functions are equivalent:<syntaxhighlight lang="python">def my_function(): pass def my_function(): return def my_func..." Tag: Visual edit
- 13:1513:15, 15 October 2025 diff hist +6,733 N Dict Created page with " == The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://docs.python.org/3/library/stdtypes.html#mapping-types-dict Mapping Types - dict] == <blockquote>A mapping object maps hashable values to arbitrary objects. Mappings are mutable objects. There is currently only one standard mapping type, the dictionary. A dictionary’s keys are almost arbitrary values. Values that are not hashable, that is, values containing lists, dictionaries or..." Tag: Visual edit
- 13:1413:14, 15 October 2025 diff hist +1,352 N Zip Created page with " == Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://docs.python.org/3/library/functions.html#zip zip] == <syntaxhighlight lang="python">zip(*iterables, strict=False)</syntaxhighlight><blockquote>Iterate over several iterables in parallel, producing tuples with an item from each one.</blockquote><syntaxhighlight lang="python">a = zip([1, 2, 3], ["sugar", "spice", "everything nice"]) print(a) # -> <zip object at 0x7f34987f4380> for item in..." Tag: Visual edit
- 13:1313:13, 15 October 2025 diff hist +4,102 N Tuple Created page with " == The goal == Tuple are a non-mutable container which is typically used for heterogenic data types and is very important for functions with multiple return values. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://docs.python.org/3/library/stdtypes.html#tuple Tuples] == <blockquote>Tuples are immutable sequences, typically used to store collections of heterogeneous data (such as the 2-tuples produced by the enumerate() built-in). Tuples are..." current Tag: Visual edit
- 13:1213:12, 15 October 2025 diff hist +1,375 N List Comprehensions Created page with " == Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions List Comprehension] == <blockquote>List comprehensions provide a concise way to create lists. Common applications are to make new lists where each element is the result of some operations applied to each member of another sequence or iterable, or to create a subsequence of those elements that satisfy a certain condition.</b..." Tag: Visual edit
- 13:0613:06, 15 October 2025 diff hist +8,519 N Lists Created page with " == The goal == <blockquote>Lists are '''mutable''' sequences, '''typically''' used to store collections of '''homogeneous''' items (where the precise degree of similarity will vary by application).</blockquote>[https://docs.python.org/3/library/stdtypes.html#lists Quote] Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Example Lists == With homogeneous items:<syntaxhighlight lang="python">primes = [2, 3, 5, 7] collection_of_strings = [ "AA", "BB"..." Tag: Visual edit
- 13:0313:03, 15 October 2025 diff hist +451 Python Tutorial →Python: The Basics of the basics Tag: Visual edit
- 11:0211:02, 15 October 2025 diff hist +9,341 N Flow Control: match case Created page with " == The goal == There is a new flow control in town. A switch case replacement, called match case. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == The [https://docs.python.org/3/reference/compound_stmts.html#the-match-statement match] statement == The match statement is used for pattern matching. Syntax:<syntaxhighlight lang="python">match_stmt ::= 'match' subject_expr ":" NEWLINE INDENT case_block+ DEDENT subject_expr ::= star_named_expression "," st..." Tag: Visual edit
- 11:0111:01, 15 October 2025 diff hist +2,389 N Flow Control: while, pass, break, continue Created page with " == The goal == While we wait… Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''Logic blocks need to be indented. Preferable with 4 spaces!''' == [https://docs.python.org/3/reference/compound_stmts.html#the-while-statement The while statement] == <syntaxhighlight lang="python">i = 0 while i < 3: print(i) i += 1</syntaxhighlight>Output<syntaxhighlight lang="python">0 1 2</syntaxhighlight> == The full statement == <syntaxhighlig..." Tag: Visual edit
- 11:0011:00, 15 October 2025 diff hist +5,377 N Flow Control: for-loop Created page with " == The goal == For what reason… Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''Logic blocks need to be indented. Preferable with 4 spaces!''' == [https://docs.python.org/3/reference/compound_stmts.html#the-for-statement The for statement] == <blockquote>The for statement is used to iterate over the elements of a sequence (such as a string, tuple or list) or other iterable object</blockquote> === With range() === <syntaxhighlight lang="python">for..." Tag: Visual edit
- 10:5910:59, 15 October 2025 diff hist +1,127 N Flow Control: if, elif, else Created page with " == The goal == If I would have… Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''Logic blocks need to be indented. Preferable with 4 spaces!''' == [https://docs.python.org/3/reference/compound_stmts.html#the-if-statement The if statement] == <syntaxhighlight lang="python">if i == 1: print("if") elif i == 2: print("elif brach A") elif i == 3: print("elif brach B") else: print("else -- default")</syntaxhighlight..." Tag: Visual edit
- 10:5810:58, 15 October 2025 diff hist +1,547 N Flow Control Overview Created page with " == The goal == Let us look what kind of options we have for flow control in Python. Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''Logic blocks need to be indented. Preferable with 4 spaces!''' There is called a so called [https://docs.python.org/3/reference/index.html The Python Language Reference] {| class="wikitable" !Selection statements |- |[https://docs.python.org/3/reference/compound_stmts.html#the-if-statement if, elif, else] |- |[https://do..." Tag: Visual edit
- 10:5610:56, 15 October 2025 diff hist +7,860 N Formatted String Literals Created page with " == The goal == Using formated string literals is an easy way to produce formated strings from data / variables. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Basic Formatted String Literals == A formatted string literals starts with an f and the variables that you want to print are placed at their intended position embeded into { }. For example:<syntaxhighlight lang="python">import numpy as np a: str = "Hello" b: int = 1 c: float = np.pi mystring: st..." Tag: Visual edit
- 10:5210:52, 15 October 2025 diff hist +3,259 N Truth Value Testing Created page with "Questions to [mailto:davrot@uni-bremen.de David Rotermund] [https://docs.python.org/3/library/stdtypes.html#truth-value-testing “Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below.”] = Common mistake to avoid = For True, False, None we use is and is not for comparisons. They are objects and not values thus we need to use is and is not. Correct<syntaxhighlight lang="python">if a: # "a is True"..." current Tag: Visual edit
- 10:3410:34, 15 October 2025 diff hist +8,303 N Basic Math Operations Created page with "Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Number is Python == In Python everything is a class. Numbers are classes as well. === Integer === <syntaxhighlight lang="python">a_number = 0 print(type(a_number)) # -> <class 'int'></syntaxhighlight> == FLOATing point number == <syntaxhighlight lang="python">a_second_number = 3.33 print(type(a_second_number)) # -> <class 'float'></syntaxhighlight> == Conversion (i.e. casts) between types..." Tag: Visual edit
14 October 2025
- 16:0416:04, 14 October 2025 diff hist +5,248 N Assert Created page with " == The goal == assert helps you to check your assumptions and stops the program if they are not met. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement The assert statement] == <blockquote>Assert statements are a convenient way to insert debugging assertions into a program:</blockquote><syntaxhighlight lang="python">assert_stmt ::= "assert" expression ["," expression]</syntaxhighli..." Tag: Visual edit
- 16:0216:02, 14 October 2025 diff hist +3,543 N Programming Recommendations Created page with " == The goal == We want to improve the quality of the code. Questions to [mailto:davrot@uni-bremen.de David Rotermund] = The recommendations = * Comparisons to singletons like None should always be done with is or is not, never the equality operators. *Use is not operator rather than not … is. While both expressions are functionally identical, the former is more readable and preferred: <syntaxhighlight lang="python"># Correct: if foo is not None:</syntaxhighlight>..." Tag: Visual edit
- 16:0016:00, 14 October 2025 diff hist +20,367 N Style Rulez Created page with " == The goal == Obviously, you can write your code as YOU want. However, if there is at least a small probability that you will exchange your code with someone (e.g. me!) or the source code is required to accompany a paper then… '''… you should NOT ignore PEP 8.''' A good source code editor (like Visual Studio Code) will try to enforce many of the PEP 8 rules on you automatically. You need to allow it to help you… Don’t work against it! This is one of the main..." Tag: Visual edit
- 15:5915:59, 14 October 2025 diff hist +12,707 N Input, print, string, int, float Created page with " == The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Examples == === Input / Print === <syntaxhighlight lang="python">a = input() # <- test print(a) # -> test</syntaxhighlight> === String to int === <syntaxhighlight lang="python">a = int(5) print(a) # -> 5 print(type(a)) # -> <class 'int'> a = int(-5) print(a) # -> -5 print(type(a)) # -> <class 'int'> a = int("5") print(a) # -> 5 print(type(a)) # -> <class 'int'> a = int("-5") print(a)..." Tag: Visual edit
- 15:5815:58, 14 October 2025 diff hist +3,383 N Hello, Python Created page with " == The goal == This is the first step in running something in Python. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == These are the same stings == <syntaxhighlight lang="python">some_string = "this is a string" some_string = 'this is a string'</syntaxhighlight><syntaxhighlight lang="python">print(some_string)</syntaxhighlight>Output:<syntaxhighlight lang="python">this is a string</syntaxhighlight> == These are comments == <syntaxhighlight lang="py..." Tag: Visual edit
- 15:5415:54, 14 October 2025 diff hist +3,762 N Overview Created page with " == The goal == We have to start somewhere. Why not with an overview? Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://www.python.org/ Python] == <blockquote>Python is a programming language that lets you work quickly and integrate systems more effectively.</blockquote> * There is an offical [https://docs.python.org/3/tutorial/ Python Tutorial] * YouTube: Socratica Channel [https://www.youtube.com/watch?v=bY6m6_IIN94&list=PLi01XoE8jYohWFPpC17Z..." Tag: Visual edit
- 15:4015:40, 14 October 2025 diff hist 0 N File:2022-04-01 18-20 0.png No edit summary current
- 15:4015:40, 14 October 2025 diff hist 0 N File:2022-04-01 18-17 1.png No edit summary current
- 15:4015:40, 14 October 2025 diff hist 0 N File:2022-04-01 18-17.png No edit summary current
- 15:4015:40, 14 October 2025 diff hist 0 N File:2022-04-01 18-16.png No edit summary current
- 15:4015:40, 14 October 2025 diff hist 0 N File:2022-04-01 18-13 0.png No edit summary current
- 15:3915:39, 14 October 2025 diff hist 0 N File:2022-04-01 18-11 0.png No edit summary current
- 15:3915:39, 14 October 2025 diff hist 0 N File:2022-04-01 18-09 0.png No edit summary current
- 15:3915:39, 14 October 2025 diff hist 0 N File:2022-04-01 17-52 0.png No edit summary current
- 15:3915:39, 14 October 2025 diff hist 0 N File:2022-04-01 17-45.png No edit summary current
- 15:3915:39, 14 October 2025 diff hist 0 N File:2022-04-01 17-43 0.png No edit summary current
- 15:3815:38, 14 October 2025 diff hist 0 N File:2022-04-01 17-41.png No edit summary current
- 15:3815:38, 14 October 2025 diff hist 0 N File:2022-04-01 17-40.png No edit summary current
- 15:3815:38, 14 October 2025 diff hist 0 N File:2022-04-01 17-29.png No edit summary current
- 15:3815:38, 14 October 2025 diff hist 0 N File:2022-04-01 17-28.png No edit summary current
- 15:3715:37, 14 October 2025 diff hist 0 N File:2022-04-01 17-25 1.png No edit summary current
- 15:3715:37, 14 October 2025 diff hist 0 N File:2022-04-01 17-25.png No edit summary current
- 15:3715:37, 14 October 2025 diff hist 0 N File:2022-04-01 17-24.png No edit summary current
- 15:3715:37, 14 October 2025 diff hist 0 N File:2022-04-01 17-22.png No edit summary current
- 15:3615:36, 14 October 2025 diff hist 0 N File:2022-04-01 17-17.png No edit summary current
- 15:3615:36, 14 October 2025 diff hist +4,776 N VS Code Working remotely via ssh Created page with " == Top == Develop your code with [https://code.visualstudio.com/docs/remote/ssh VS code remotely via a ssh connection]. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Installation == We need to install the Remote ssh extension<div class="figure"> File:98723h image0.png </div>and these one too:<div class="figure">File:98723h image1.png </div>However, the second one should be installed automatically. == Configuration == <div class="figure"> Fil..." Tag: Visual edit
- 15:3615:36, 14 October 2025 diff hist +13 N File:98723h image1.png No edit summary current
- 15:3515:35, 14 October 2025 diff hist +13 N File:98723h image0.png No edit summary current
- 15:3115:31, 14 October 2025 diff hist −2 VS Code Debugging →Step Into Tag: Visual edit
- 15:3115:31, 14 October 2025 diff hist +16 N File:2025-10-14 17-30.png No edit summary current
- 15:2015:20, 14 October 2025 diff hist 0 N File:2022-04-01 21-18.png No edit summary current
- 15:2015:20, 14 October 2025 diff hist 0 N File:2022-04-01 21-20.png No edit summary current