User contributions for Davrot
From Master of Neuroscience Wiki
17 October 2025
- 14:2714:27, 17 October 2025 diff hist +20,114 N Simple plot and imshow examples Created page with "== The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund]<blockquote>'''pylab''' is a historic interface and '''its use is strongly discouraged'''. The equivalent replacement is matplotlib.pyplot</blockquote> == Simple example with plot == <div class="figure"> File:6 0.png </div><syntaxhighlight lang="python">import numpy as np import matplotlib.pyplot as plt # type: ignore f: float = 10 t = np.linspace(0, 1.0, 10000) y = np.sin(t * 2 * np.pi * f)..." Tag: Visual edit
- 14:2714:27, 17 October 2025 diff hist +3 N File:6 0.png No edit summary current
- 14:2614:26, 17 October 2025 diff hist +3 N File:6 1.png No edit summary current
- 14:2214:22, 17 October 2025 diff hist +33,066 N Basics Created page with "== The goal == Pandas can be e.g. used for handling meta data from experiments. It is a kind of SQL / Excel extension for Python. Questions to [mailto:davrot@uni-bremen.de David Rotermund]<syntaxhighlight lang="shell">pip install pandas</syntaxhighlight> == [https://pandas.pydata.org/ Pandas] == The two most important data types of Pandas are: * Series * Data Frames<blockquote>“Pandas is a fast, powerful, flexible and easy to use open source data analysis and m..." Tag: Visual edit
- 14:2114:21, 17 October 2025 diff hist +1,114 Python Tutorial →Numpy: Matlab topics Tag: Visual edit
- 14:0614:06, 17 October 2025 diff hist +451 N NumPy for MATLAB users Created page with "== The goal == In the case you are already familiar with Matlab there is an guide for switching to NumPy Questions to [mailto:davrot@uni-bremen.de David Rotermund] == NumPy for MATLAB users == <blockquote>MATLAB® and NumPy have a lot in common, but NumPy was created to work with Python, not to be a MATLAB clone. [https://numpy.org/doc/stable/user/numpy-for-matlab-users.html This guide] will help MATLAB users get started with NumPy.</blockquote>" Tag: Visual edit
- 14:0514:05, 17 October 2025 diff hist −74 Python Tutorial →Numpy: Matlab topics Tag: Visual edit
- 14:0514:05, 17 October 2025 diff hist +5,375 N Running Python remotely from Matlab Created page with "== The goal == We want to integrate Python files and code into our Matlab workflow. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Check if you are ready == [https://de.mathworks.com/support/requirements/python-compatibility.html Versions of Python Compatible with MATLAB Products by Release] You need to ask yourself or better Matlab if it is using the correct Python. You can check this via:<syntaxhighlight lang="matlab">>> pyenv ans = PythonEnviron..." Tag: Visual edit
- 14:0414:04, 17 October 2025 diff hist 0 N File:2023-12-21 16-56.png No edit summary current
- 14:0314:03, 17 October 2025 diff hist +9,576 N Matlab is also just a Python package Created page with "== The goal == Remote controlling Matlab from Python using the Matlab engine package. (Note: A similar approach can be used with C/C++ instead of Python.) Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Installing Matlab under Python == [https://de.mathworks.com/support/requirements/python-compatibility.html Versions of Python Compatible with MATLAB Products by Release] Obviously you need a working Matlab and Python installation first. Then… === Linux..." Tag: Visual edit
- 13:5713:57, 17 October 2025 diff hist +5,877 N Dealing with Matlab files Created page with "== The goal == We want to read and write Matlab files under Python. Questions to [mailto:davrot@uni-bremen.de David Rotermund] Reminder: Learning Python as Matlab user Please read [https://numpy.org/doc/stable/user/numpy-for-matlab-users.html NumPy for MATLAB users] == Mat files under Python == === MATLAB < 7.3 format mat files === This is a job for [https://docs.scipy.org/doc/scipy/reference/io.html#module-scipy.io scipy.io] {| class="wikitable" |[https://docs...." Tag: Visual edit
- 13:5613:56, 17 October 2025 diff hist +3,619 N Dealing with the main diagonal / triangles of a matrix Created page with "== Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''This is an optional topic!''' == [https://numpy.org/doc/stable/reference/generated/numpy.fill_diagonal.html numpy.fill_diagonal] == <syntaxhighlight lang="python">numpy.fill_diagonal(a, val, wrap=False)</syntaxhighlight><blockquote>Fill the main diagonal of the given array of any dimensionality. For an array a with a.ndim >= 2, the diagonal is the list of locations with indices a[i, …, i] a..." Tag: Visual edit
- 13:5513:55, 17 October 2025 diff hist +2,935 N Resize: Compensation for bad planning? Don't! Created page with "== Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''Try to avoid using this function!''' Do better planning. Resize does its work on the linear memory segment. * If it is resized to a bigger array, the beginning of the original memory segment is copied into the new end segment. * If it is resized to a smaller array, the memory segment is shrunken by cutting of the end. == [https://numpy.org/doc/stable/reference/generated/numpy.resize.html numpy.res..." Tag: Visual edit
- 13:5413:54, 17 October 2025 diff hist +3,657 N Numpy and JSON over Pandas Created page with "== The goal == Normally we can not use JSON with Numpy. However, if we use [https://pandas.pydata.org/ Pandas] as an intermediary then we can do it. Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''Note: Pandas can also be used for many other formats beside JSON.''' == Writing JSON [https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_json.html#pandas-dataframe-to-json pandas.DataFrame.to_json] == <syntaxhighlight lang="python">DataFrame.to_js..." Tag: Visual edit
- 13:5313:53, 17 October 2025 diff hist +5,585 N Manipulation of integers and their bits Created page with "== The goal == Manipulation of integers and their bits Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.ndarray.byteswap.html numpy.ndarray.byteswap] == <syntaxhighlight lang="python">ndarray.byteswap(inplace=False)</syntaxhighlight><blockquote>Swap the bytes of the array elements Toggle between low-endian and big-endian data representation by returning a byteswapped array, optionally swapped in-plac..." Tag: Visual edit
- 13:5213:52, 17 October 2025 diff hist +4,897 N Nested iters Created page with "== Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''This is an optional topic!''' == [https://numpy.org/doc/stable/reference/generated/numpy.nested_iters.html numpy.nested_iters] == <syntaxhighlight lang="python">numpy.nested_iters(op, axes, flags=None, op_flags=None, op_dtypes=None, order='K', casting='safe', buffersize=0)</syntaxhighlight><blockquote>Create nditers for use in nested loops Create a tuple of nditer objects which iterate in nested l..." Tag: Visual edit
- 13:5013:50, 17 October 2025 diff hist +4,275 N Replacing an inner for loop with apply along axis Created page with "== The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''This is an optional topic!''' == [https://numpy.org/doc/stable/reference/generated/numpy.apply_along_axis.html numpy.apply_along_axis] == <syntaxhighlight lang="python">numpy.apply_along_axis(func1d, axis, arr, *args, **kwargs)</syntaxhighlight><blockquote>Apply a function to 1-D slices along the given axis. Execute func1d(a, *args, **kwargs) where func1d operates on 1-D arrays and a is a 1-D..." Tag: Visual edit
- 13:4813:48, 17 October 2025 diff hist +18,425 N Nditer provides many ways to visit all the elements of one or more arrays Created page with "== The goal == More iterating over an array… Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''This is an optional topic!''' == [https://numpy.org/doc/stable/reference/generated/numpy.nditer.html numpy.nditer] == <syntaxhighlight lang="python">class numpy.nditer(op, flags=None, op_flags=None, op_dtypes=None, order='K', casting='safe', op_axes=None, itershape=None, buffersize=0)</syntaxhighlight><blockquote>Efficient multi-dimensional iterator object to i..." Tag: Visual edit
- 13:4613:46, 17 October 2025 diff hist +726 N Trim Zeros of a 1d array Created page with "== Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.trim_zeros.html numpy.trim_zeros] == <syntaxhighlight lang="python">numpy.trim_zeros(filt, trim='fb')</syntaxhighlight><blockquote>Trim the leading and/or trailing zeros from a 1-D array or sequence.</blockquote><syntaxhighlight lang="python">import numpy as np a = np.arange(0, 10) b = np.zeros((5), dtype=np.int64) c = np.r_[b, a, b] print(c)..." Tag: Visual edit
- 13:4013:40, 17 October 2025 diff hist +5,090 N Beyond normal np.save Created page with "== The goal == Let’s [https://numpy.org/doc/stable/reference/routines.io.html save and load data under numpy]. This can be more complicated than expected. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Normal [https://numpy.org/doc/stable/reference/generated/numpy.save.html np.save] and [https://numpy.org/doc/stable/reference/generated/numpy.load.html np.load] == A normal np.save and np.load cycle may look like this:<syntaxhighlight lang="python">impor..." Tag: Visual edit
- 13:3913:39, 17 October 2025 diff hist +10,621 N Stack and Split, Compress Created page with "== The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''This is an optional topic!''' == [https://numpy.org/doc/stable/reference/generated/numpy.column_stack.html numpy.column_stack] == <syntaxhighlight lang="python">numpy.column_stack(tup)</syntaxhighlight><blockquote>Stack 1-D arrays as columns into a 2-D array. Take a sequence of 1-D arrays and stack them as columns to make a single 2-D array. 2-D arrays are stacked as-is, just like with hstack..." Tag: Visual edit
- 13:3513:35, 17 October 2025 diff hist +4,520 N Memory layout of Numpy matrices Created page with "== The goal == More information about the Numpy matrices and the memory structure behind it. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Memory layouts (row-major vs column-major) == C order (or row-major)<blockquote>In row-major order, the last dimension is contiguous, so that the memory-offset of this element is given by:</blockquote><math display="block"> n_{d}+N_{d}\cdot (n_{d-1}+N_{d-1}\cdot (n_{d-2}+N..." Tag: Visual edit
- 13:3513:35, 17 October 2025 diff hist +16 N File:2025-10-17 15-34.png No edit summary current
- 13:3313:33, 17 October 2025 diff hist +28,768 N Numba: Numpy just in time compiler -- speeding Numpy up Created page with "== The goal == [https://numba.pydata.org/ “Numba is an open source JIT compiler that translates a subset of Python and NumPy code into fast machine code.”] Questions to [mailto:davrot@uni-bremen.de David Rotermund]<syntaxhighlight lang="shell">pip install numba</syntaxhighlight>[https://numba.pydata.org/numba-doc/latest/user/5minguide.html A ~5 minute guide to Numba] == [https://numba.pydata.org/numba-doc/dev/reference/types.html Numba basic types] == For the examp..." Tag: Visual edit
- 13:3213:32, 17 October 2025 diff hist +8,441 N Einstein summation Created page with "== Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Examples == <math display="block">b = \sum_i a_{i,i}</math><syntaxhighlight lang="python">import numpy as np a = np.arange(0, 25).reshape(5, 5) print(a) print(a.shape) # -> (5, 5) print(np.einsum("ii", a)) # -> 60 print(np.einsum(a, [0, 0])) # -> 60 print(np.einsum(a, [0, 0], [])) # -> 60</syntaxhighlight>Output:<syntaxhighlight lang="python">[[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14..." Tag: Visual edit
- 13:3013:30, 17 October 2025 diff hist +1,369 N Flat Created page with "== Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.ndarray.flat.html numpy.ndarray.flat] == <syntaxhighlight lang="python">ndarray.flat</syntaxhighlight><blockquote>A 1-D iterator over the array. This is a numpy.flatiter instance, which acts similarly to, but is not a subclass of, Python’s built-in iterator object.</blockquote><syntaxhighlight lang="python">import numpy as np a = np.arange(..." Tag: Visual edit
- 13:3013:30, 17 October 2025 diff hist +749 N Ndindex Created page with "== Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.ndindex.html numpy.ndindex] == <syntaxhighlight lang="python">class numpy.ndindex(*shape)[source]</syntaxhighlight><blockquote>An N-dimensional iterator object to index arrays. Given the shape of an array, an ndindex instance iterates over the N-dimensional index of the array. At each iteration a tuple of indices is returned, the last dimensio..." Tag: Visual edit
- 13:2713:27, 17 October 2025 diff hist +781 N Ndenumerate Created page with " = ndenumerate = == Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.ndenumerate.html numpy.ndenumerate] == <syntaxhighlight lang="python">class numpy.ndenumerate(arr)</syntaxhighlight><blockquote>Multidimensional index iterator. Return an iterator yielding pairs of array coordinates and values.</blockquote><syntaxhighlight lang="python">import numpy as np a = np.arange(0, 12).reshape((4, 3))..." Tag: Visual edit
- 13:2613:26, 17 October 2025 diff hist +3,686 N Flip, rot90, and roll a matrix Created page with "== The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.flip.html numpy.flip] == <syntaxhighlight lang="python">numpy.flip(m, axis=None)</syntaxhighlight><blockquote>Reverse the order of elements in an array along the given axis. The shape of the array is preserved, but the elements are reordered. '''m''': array_like Input array. '''axis''': None or int or tuple of ints, optional Axis or a..." Tag: Visual edit
- 13:2513:25, 17 October 2025 diff hist +9,373 N Meshgrid Created page with "== The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html numpy.meshgrid] == <syntaxhighlight lang="python">numpy.meshgrid(*xi, copy=True, sparse=False, indexing='xy')</syntaxhighlight><blockquote>Return a list of coordinate matrices from coordinate vectors. Make N-D coordinate arrays for vectorized evaluations of N-D scalar/vector fields over N-D grids, given one-dimensional coord..." Tag: Visual edit
- 13:2213:22, 17 October 2025 diff hist +3 N File:5 4.png No edit summary current
- 13:2113:21, 17 October 2025 diff hist +3 N File:5 2.png No edit summary current
- 13:2113:21, 17 October 2025 diff hist +3 N File:5 1.png No edit summary current
- 13:2013:20, 17 October 2025 diff hist +3 N File:5 0.png No edit summary current
- 13:1113:11, 17 October 2025 diff hist +3,453 N Spectral power and averaging over trials Created page with "== Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == The order is important == You are not allowed to average over the trials before calculating the power. This is the same for calculating the fft power as well as the wavelet power. The worst case senario would be two waves in anti-phase:<syntaxhighlight lang="python">import numpy as np import matplotlib.pyplot as plt t: np.ndarray = np.linspace(0, 1.0, 10000) f: float = 10 sinus_a = np.sin(f * t *..." Tag: Visual edit
- 13:1013:10, 17 October 2025 diff hist +7 N File:43897 3.png No edit summary current
- 13:1013:10, 17 October 2025 diff hist +7 N File:43897 2.png No edit summary current
- 13:1013:10, 17 October 2025 diff hist +7 N File:43897 1.png No edit summary current
- 13:0913:09, 17 October 2025 diff hist +7 N File:43897 0.png No edit summary current
- 13:0813:08, 17 October 2025 diff hist +3,327 N Rfft and spectral power Created page with "== Goal == We want to calculate a well behaved power spectral density from a 1 dimensional time series. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Generation of test data == We will generate a sine wave with 10 Hz.<syntaxhighlight lang="python">import numpy as np time_series_length: int = 1000 dt: float = 1.0 / 1000.0 # time resolution is 1ms sampling_frequency: float = 1.0 / dt frequency_hz: float = 10.0 t: np.ndarray = np.arange(0, time_series_le..." Tag: Visual edit
- 13:0713:07, 17 October 2025 diff hist +7 N File:33897 3.png No edit summary current
- 13:0713:07, 17 October 2025 diff hist +7 N File:33897 2.png No edit summary current
- 13:0713:07, 17 October 2025 diff hist +7 N File:33897 1.png No edit summary current
- 13:0413:04, 17 October 2025 diff hist +9,344 N FFT Created page with "== The goal == Fouriert transformations are an important part of data analysis. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/routines.fft.html Numpy] vs [https://docs.scipy.org/doc/scipy/tutorial/fft.html#fourier-transforms-scipy-fft scipy] == <syntaxhighlight lang="shell">pip install scipy</syntaxhighlight>Numpy says [https://numpy.org/doc/stable/reference/routines.fft.html#discrete-fourier-transform-numpy-fft i..." Tag: Visual edit
- 13:0413:04, 17 October 2025 diff hist +8 N File:23897 4b.png No edit summary current
- 13:0313:03, 17 October 2025 diff hist +7 N File:23897 4.png No edit summary current
- 13:0313:03, 17 October 2025 diff hist +8 N File:23897 3b.png No edit summary current
- 13:0213:02, 17 October 2025 diff hist +8 N File:23897 3a.png No edit summary current
- 13:0213:02, 17 October 2025 diff hist +7 N File:23897 2.png No edit summary current
- 13:0213:02, 17 October 2025 diff hist +7 N File:23897 1.png No edit summary current