New pages

From Master of Neuroscience Wiki
New pages
Hide registered users | Hide bots | Show redirects
(newest | oldest) View ( | ) (20 | 50 | 100 | 250 | 500)

17 October 2025

  • 14:0614:06, 17 October 2025 NumPy for MATLAB users (hist | edit) [436 bytes] Davrot (talk | contribs) (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 Running Python remotely from Matlab (hist | edit) [5,360 bytes] Davrot (talk | contribs) (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:0314:03, 17 October 2025 Matlab is also just a Python package (hist | edit) [9,560 bytes] Davrot (talk | contribs) (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 Dealing with Matlab files (hist | edit) [5,862 bytes] Davrot (talk | contribs) (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 Dealing with the main diagonal / triangles of a matrix (hist | edit) [3,609 bytes] Davrot (talk | contribs) (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 Resize: Compensation for bad planning? Don't! (hist | edit) [2,928 bytes] Davrot (talk | contribs) (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 Numpy and JSON over Pandas (hist | edit) [3,643 bytes] Davrot (talk | contribs) (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 Manipulation of integers and their bits (hist | edit) [5,570 bytes] Davrot (talk | contribs) (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 Nested iters (hist | edit) [4,887 bytes] Davrot (talk | contribs) (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 Replacing an inner for loop with apply along axis (hist | edit) [4,260 bytes] Davrot (talk | contribs) (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 Nditer provides many ways to visit all the elements of one or more arrays (hist | edit) [18,410 bytes] Davrot (talk | contribs) (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 Trim Zeros of a 1d array (hist | edit) [716 bytes] Davrot (talk | contribs) (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 Beyond normal np.save (hist | edit) [5,075 bytes] Davrot (talk | contribs) (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 Stack and Split, Compress (hist | edit) [10,606 bytes] Davrot (talk | contribs) (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 Memory layout of Numpy matrices (hist | edit) [4,505 bytes] Davrot (talk | contribs) (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:3313:33, 17 October 2025 Numba: Numpy just in time compiler -- speeding Numpy up (hist | edit) [28,753 bytes] Davrot (talk | contribs) (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 Einstein summation (hist | edit) [8,431 bytes] Davrot (talk | contribs) (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 Flat (hist | edit) [1,359 bytes] Davrot (talk | contribs) (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 Ndindex (hist | edit) [739 bytes] Davrot (talk | contribs) (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 Ndenumerate (hist | edit) [754 bytes] Davrot (talk | contribs) (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 Flip, rot90, and roll a matrix (hist | edit) [3,671 bytes] Davrot (talk | contribs) (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 Meshgrid (hist | edit) [9,358 bytes] Davrot (talk | contribs) (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:1113:11, 17 October 2025 Spectral power and averaging over trials (hist | edit) [3,444 bytes] Davrot (talk | contribs) (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:0813:08, 17 October 2025 Rfft and spectral power (hist | edit) [3,316 bytes] Davrot (talk | contribs) (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:0413:04, 17 October 2025 FFT (hist | edit) [9,329 bytes] Davrot (talk | contribs) (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
  • 12:5812:58, 17 October 2025 Statistics (hist | edit) [5,846 bytes] Davrot (talk | contribs) (Created page with "== The goal == There are other (more extensive) statistics packages like​ * [https://docs.scipy.org/doc/scipy/reference/stats.html scipy.stats​] * [https://pingouin-stats.org/build/html/index.html pingouin] * [https://www.statsmodels.org/stable/index.html statsmodels] Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.fisher_exact.html#scipy.stats.fisher_exact Fisher Exact Test] == The [ht...") Tag: Visual edit
  • 12:5812:58, 17 October 2025 Random numbers the non-legacy way (hist | edit) [9,973 bytes] Davrot (talk | contribs) (Created page with "== Goal == If you don’t see something like '''np.random.default_rng()''' in your code then you are probably using the old [https://numpy.org/doc/stable/reference/random/legacy.html#legacy-random-generation Legacy Random Generation]. '''Don’t use the [https://numpy.org/doc/stable/reference/random/legacy.html legacy] methods''' for new source code!!! '''numpy.random.random() == old == bad == don’t use'''​ Do it like this:<syntaxhighlight lang="python">import num...") Tag: Visual edit
  • 12:5712:57, 17 October 2025 Linear algebra (hist | edit) [7,476 bytes] Davrot (talk | contribs) (Created page with "== The goal == Overview over the linear algebra functions of Numpy. Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''There more functions in the [https://docs.scipy.org/doc/scipy/reference/linalg.html scipy linalg package]!!!''' == The @ operator == @ => Matrix product * => outer product A[i] * B[i] The @ operator is preferable to other methods when computing the matrix product between 2d arrays. The numpy.matmul function implements the @ oper...") Tag: Visual edit
  • 12:5612:56, 17 October 2025 Math functions (hist | edit) [17,781 bytes] Davrot (talk | contribs) (Created page with "== The goal == Matrices alone are useless. We need some math functions to act upon them. Questions to [mailto:davrot@uni-bremen.de David Rotermund] '''I will focus on the important ones. Those will get a link.''' == [https://numpy.org/doc/stable/reference/routines.math.html#trigonometric-functions Trigonometric functions] == {| class="wikitable" |[https://numpy.org/doc/stable/reference/generated/numpy.sin.html#numpy.sin sin](x, /[, out, where, casting, order, …]) |T...") Tag: Visual edit
  • 12:5512:55, 17 October 2025 Constants (hist | edit) [641 bytes] Davrot (talk | contribs) (Created page with " == The goal == Numpy provides plenty of constants. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/constants.html The most important ones] == {| class="wikitable" |numpy.inf |IEEE 754 floating point representation of (positive) infinity. |- |numpy.nan |IEEE 754 floating point representation of Not a Number (NaN). |- |numpy.e |Euler’s constant, base of natural logarithms, Napier’s constant.​ e = 2.718281828459...") Tag: Visual edit
  • 12:5412:54, 17 October 2025 Available dtypes (hist | edit) [3,801 bytes] Davrot (talk | contribs) (Created page with "== The goal == A numpy matrix can have differnt dtype or – in other words – differnt types of numbers with different precisions. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/arrays.scalars.html#sized-aliases Signed integer types​​] == '''Please use numpy.int8, numpy.int16, numpy.int32, and numpy.int64 !!!''' * ''numpy.int8'': ** 8-bit signed integer (-128 to 127). Compatible with C char. ** ''numpy.byte'...") Tag: Visual edit
  • 12:5312:53, 17 October 2025 Ravel and UnRavel (hist | edit) [1,371 bytes] Davrot (talk | contribs) (Created page with " == Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.ravel_multi_index.html numpy.ravel_multi_index] == <syntaxhighlight lang="python">numpy.ravel_multi_index(multi_index, dims, mode='raise', order='C')</syntaxhighlight><blockquote>Converts a tuple of index arrays into an array of flat indices, applying boundary modes to the multi-index.</blockquote><syntaxhighlight lang="python">import numpy as...") Tag: Visual edit
  • 12:4612:46, 17 October 2025 Advanced Indexing (hist | edit) [6,781 bytes] Davrot (talk | contribs) (Created page with "== The goal == Beside slicing there is something called advanced indexing Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/user/basics.indexing.html#boolean-array-indexing Boolean Array​] == We can use Boolean arrays for more complicate indexing:<syntaxhighlight lang="python">import numpy as np a = np.arange(1,10).reshape(3,3) b = np.zeros_like(a) b[a.sum(axis=1) > 6, :] = 1 print(a) print() print(b)</syntaxhighlight>Outp...") Tag: Visual edit
  • 12:4512:45, 17 October 2025 Boolean matricies and logic functions (hist | edit) [8,619 bytes] Davrot (talk | contribs) (Created page with "== The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Boolean matrices == There are different ways to get a Boolean matrix. For example the result of a '''np.isfinite()''' (checks if the values in a matrix are infite values) is a Boolean matrix.<syntaxhighlight lang="python">import numpy as np a = 1.0 / np.arange(0, 6).reshape((2, 3)) print(a) print() print(np.isfinite(a))</syntaxhighlight>Output:<syntaxhighlight lang="python"> inf 1....") Tag: Visual edit
  • 12:4412:44, 17 October 2025 Extending an existing matrix: tile, repeat, pad (hist | edit) [6,382 bytes] Davrot (talk | contribs) (Created page with "== The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.tile.html numpy.tile] == <syntaxhighlight lang="python">numpy.tile(A, reps)</syntaxhighlight><blockquote>Construct an array by repeating A the number of times given by reps. If reps has length d, the result will have dimension of max(d, A.ndim). If A.ndim < d, A is promoted to be d-dimensional by prepending new axes. So a shape (3,)...") Tag: Visual edit
  • 12:4312:43, 17 October 2025 Piecewise (hist | edit) [1,721 bytes] Davrot (talk | contribs) (Created page with "== Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.piecewise.html numpy.piecewise] == <syntaxhighlight lang="python">numpy.piecewise(x, condlist, funclist, *args, **kw)</syntaxhighlight><blockquote>Evaluate a piecewise-defined function. Given a set of conditions and corresponding functions, evaluate each function on the input data wherever its condition is true.</blockquote><syntaxhighlight la...") Tag: Visual edit
  • 12:4312:43, 17 October 2025 Where (hist | edit) [3,776 bytes] Davrot (talk | contribs) (Created page with "== The goal == '''where''' allows to modifiy or combine matricies based on a given condition. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.where.html numpy.where] == <syntaxhighlight lang="python">numpy.where(condition, [x, y, ]/)</syntaxhighlight><blockquote>Return elements chosen from x or y depending on condition.</blockquote><blockquote>'''condition''': array_like, bool Where True, yield x, ot...") Tag: Visual edit
  • 12:4212:42, 17 October 2025 Unique (hist | edit) [1,732 bytes] Davrot (talk | contribs) (Created page with "== The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.unique.html numpy.unique] == <syntaxhighlight lang="python">numpy.unique(ar, return_index=False, return_inverse=False, return_counts=False, axis=None, *, equal_nan=True)</syntaxhighlight><blockquote>Find the unique elements of an array. Returns the sorted unique elements of an array. There are three optional outputs in addition to the uni...") Tag: Visual edit
  • 12:4112:41, 17 October 2025 Merging matrices (hist | edit) [8,740 bytes] Davrot (talk | contribs) (Created page with "== Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] Choose vs select:​ * Choose: One Matrix with integer values 0,…N-1​ * Select: N binary matrices == [https://numpy.org/doc/stable/reference/generated/numpy.choose.html#numpy-choose numpy.choose] == <syntaxhighlight lang="python">numpy.choose(a, choices, out=None, mode='raise')</syntaxhighlight><blockquote>Construct an array from an index array and a list of arrays to choose from. First of all,...") Tag: Visual edit
  • 12:3912:39, 17 October 2025 Concatenate Matrices and arrays (hist | edit) [5,606 bytes] Davrot (talk | contribs) (Created page with "== The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == numpy.concatenate == <syntaxhighlight lang="python">numpy.concatenate((a1, a2, ...), axis=0, out=None, dtype=None, casting="same_kind")</syntaxhighlight><blockquote>Join a sequence of arrays along an existing axis.</blockquote><syntaxhighlight lang="python">import numpy as np a = np.arange(0, 5) print(a) # -> [0 1 2 3 4] print(a.shape) # -> (5,) b = np.arange(0, 8) print(b) # -> [0 1 2 3 4...") Tag: Visual edit
  • 12:3712:37, 17 October 2025 Slices and Views (hist | edit) [6,974 bytes] Davrot (talk | contribs) (Created page with "== The goal == Sometimes we want to use or see only a part of the matrix. This can be done via slices and views Questions to [mailto:davrot@uni-bremen.de David Rotermund] == 1-d slices == We assume N as the number of elements and 1d: * A valid index starts at '''0''' and runs until N-1 * [start:stop:step] ​ start = 1, stop=N, step=1 ​-> this results in the sequence​ 1,2,3,…,(N-1) * [start:stop:1] can be shortened to [start:stop] * [0:stop] can be shortene...") Tag: Visual edit
  • 12:3612:36, 17 October 2025 Reshape and flatten (hist | edit) [4,608 bytes] Davrot (talk | contribs) (Created page with "== The goal == Sometimes you have to change the shape of a matrix. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.reshape.html Reshape] == <syntaxhighlight lang="python">numpy.reshape(a, newshape, order='C')</syntaxhighlight><blockquote>Gives a new shape to an array without changing its data.</blockquote><blockquote>'''a''': array_like Array to be reshaped.</blockquote><blockquote>'''newshape''': in...") Tag: Visual edit
  • 12:3412:34, 17 October 2025 Save and load (hist | edit) [5,749 bytes] Davrot (talk | contribs) (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] == [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">import numpy...") Tag: Visual edit
  • 12:3312:33, 17 October 2025 New matrix (hist | edit) [5,162 bytes] Davrot (talk | contribs) (Created page with "== The goal == Making a new matrix… Questions to [mailto:davrot@uni-bremen.de David Rotermund] Using '''import numpy as np''' is the standard. == Simple example – new [https://numpy.org/doc/stable/reference/generated/numpy.zeros.html np.zeros()] == Define the size of your new matrix with a tuple, e.g.<syntaxhighlight lang="python">M = numpy.zeros((DIM_0, DIM_1, DIM_2, …))​</syntaxhighlight> === 1d === <syntaxhighlight lang="python">import numpy as np M = np....") Tag: Visual edit
  • 12:2912:29, 17 October 2025 Convert other data into numpy arrays e.g. asarray (hist | edit) [2,145 bytes] Davrot (talk | contribs) (Created page with "== The goal == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.asarray.html numpy.asarray] == <syntaxhighlight lang="python">numpy.asarray(a, dtype=None, order=None, *, like=None)</syntaxhighlight>The importance of '''asarray''':<blockquote>Convert the input to an array.</blockquote><syntaxhighlight lang="python">import numpy as np a_list = [[1, 2], [3, 4]] a_np = np.asarray(a_list) w = np.asarray(...") Tag: Visual edit

16 October 2025

  • 17:5017:50, 16 October 2025 Making a matrix from numerical ranges (hist | edit) [3,846 bytes] Davrot (talk | contribs) (Created page with "== The goal == Making a new matrix… Questions to [mailto:davrot@uni-bremen.de David Rotermund] Using '''import numpy as np''' is the standard. == Simple example – new [https://numpy.org/doc/stable/reference/generated/numpy.zeros.html np.zeros()] == Define the size of your new matrix with a tuple, e.g.<syntaxhighlight lang="python">M = numpy.zeros((DIM_0, DIM_1, DIM_2, …))​</syntaxhighlight> === 1d === <syntaxhighlight lang="python">import numpy as np M = np....") Tag: Visual edit
  • 17:4817:48, 16 October 2025 Broadcasting: Automatic adaption of dimensions​ (hist | edit) [6,980 bytes] Davrot (talk | contribs) (Created page with "== The goal == Broadcasting: Automatic adaption of dimensions Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/devdocs/user/basics.broadcasting.html General broadcasting rules] == <blockquote>When operating on two arrays, NumPy compares their shapes element-wise. It starts with the trailing (i.e. '''''rightmost''''') dimension and works its way left. '''Two dimensions are compatible when''' * '''they are equal''', or * '''one of them is...") Tag: Visual edit
  • 16:0616:06, 16 October 2025 Dimensions and shape (hist | edit) [6,140 bytes] Davrot (talk | contribs) (Created page with "== The goal == Matrices have dimensions. But how to add and remove extra dimensions (i.e. dimensions with length 1)? Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.ndarray.shape.html numpy.ndarray.shape] == <syntaxhighlight lang="python">ndarray.shape</syntaxhighlight><blockquote>Tuple of array dimensions. The shape property is usually used to get the current shape of an array, but may also be used...") Tag: Visual edit
  • 16:0516:05, 16 October 2025 Set printoptions (hist | edit) [977 bytes] Davrot (talk | contribs) (Created page with " == Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.set_printoptions.html numpy.set_printoptions] == <syntaxhighlight lang="python">numpy.set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, suppress=None, nanstr=None, infstr=None, formatter=None, sign=None, floatmode=None, *, legacy=None)[source]</syntaxhighlight><blockquote>Set printing options.</blockquote><syntax...") Tag: Visual edit
  • 16:0416:04, 16 October 2025 The N-dimensional array (ndarray) (hist | edit) [35,281 bytes] Davrot (talk | contribs) (Created page with " == The goal == Class has a very important job as a core container type in Python. It is really hard to find a good overview how to use them in a good practice manner. Questions to [mailto:davrot@uni-bremen.de David Rotermund] == Chaining of (ndarray) methods == <syntaxhighlight lang="python">import numpy as np a = np.ones((3, 3)) b = a.mean(axis=1).max() print(b) # -> 1.0</syntaxhighlight> == [https://numpy.org/doc/stable/reference/generated/numpy.ndarray.fill.html n...") Tag: Visual edit
(newest | oldest) View ( | ) (20 | 50 | 100 | 250 | 500)