User contributions for Davrot

From Master of Neuroscience Wiki
A user with 853 edits. Account created on 14 October 2025.
Search for contributionsExpandCollapse
⧼contribs-top⧽
⧼contribs-date⧽
(newest | oldest) View ( | ) (20 | 50 | 100 | 250 | 500)

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

(newest | oldest) View ( | ) (20 | 50 | 100 | 250 | 500)