All Questions
3,588 questions
1
vote
1
answer
166
views
Create all possible outcomes from numpy matrices that show disjoints and subsets
Let's assume there is an event and within this event there are multiple outcomes that can co-exist.
An example would be a tennis game where A plays against B and B serves. A couple of possible ...
-1
votes
0
answers
78
views
How do I do Eigen decomposition of a generalized Fibonacci matrix to arbitrary precision?
This is a follow up to my previous question.
I want to efficiently compute Nth term of higher order generalized Fibonacci numbers, N is sufficiently large such that the Nth term is guaranteed to be ...
6
votes
2
answers
96
views
Printing numpy matrices horizontally on the console
Numpy has many nice features for formatted output, but something I miss is the ability to print more than one array/matrix on the same line. What I mean is easiest to explain with an example. Given ...
0
votes
1
answer
51
views
numpy.cov() Giving Incorrect Answer
I'm trying to use Python and NumPy to calculate a covariance matrix.
Here is the matrix:
[[0.69, 0.49],
[-1.31, -1.21],
[0.39, 0.99],
[0.09, 0.29],
[1.29, 1.09],
[0.49, 0.79],
[0.19, -0.31],
[-...
2
votes
1
answer
74
views
Python numpy how to split a matrix into 4 not equal matrixes?
from sympy import *
import numpy as np
# Python 3.13.2
u1 = Symbol("u1")
u2 = Symbol("u2")
q3 = Symbol("q3")
u4 = Symbol("u4")
q5 = Symbol("q5")
...
6
votes
2
answers
318
views
Is there a way to compute only the real part of a NumPy matmul?
Let's say I have two arrays a and b both with dtype np.complex128 and I want to compute C = np.matmul(a, b).real .
That is, I don't care about the imaginary part, only the real part. Is there a better ...
0
votes
1
answer
39
views
Matplotlib polygons: Polygons are skewed after rotation
I am trying to draw an object defined by several vertices and then rotate it by defining a face and a vector that I want that face to be normal to. It works fine if I choose a vector that is parallel ...
1
vote
2
answers
88
views
Representing tridiagonal matrix using numpy
I am trying to solve a mathematical problem related to matrices using numpy as shown below:
I am really finding it hard to represent this kind matrix structure using numpy. I really donot want to ...
1
vote
2
answers
121
views
Scipy Null Space Innacurate only for Complex Values
I've got a program that computes the null space of a matrix using scipy null_space. My code works absolutely perfectly when the matrix is real but seems to contradict results in MATLAB for complex ...
1
vote
1
answer
59
views
Apply operation to all elements in matrix skipping numpy.nan
I have an array filled with data only in lower triangle spaces, the rest is np.nan. I want to do some operations on this matrix, more precisely- with data elements, not nans, because I expect the ...
2
votes
2
answers
97
views
Apply function for lower triangle of 2-d array
I have an array:
U = np.array([3, 5, 7, 9, 11])
I want to get a result like:
result = np.array([
[ np.nan, np.nan, np.nan, np.nan, np.nan],
[U[0] - U[1], np.nan, np....
2
votes
3
answers
158
views
How to convert matrix to block matrix using Numpy
Say I have a matrix like
Matrix = [[A11, A12, A13, A14], [A21, A22, A23, A24], [A31, A32, A33, A34], [A41, A42, A43, A44]],
and suppose I want to convert it to a block matrix
[[A,B], [C,D]],
where
A = ...
0
votes
0
answers
29
views
I get negative matrix entries under the evolution by the GKSL equation
in this code I get negative entries in the density matrix. Is anyone aware of some method we can use? The modulus of the eigenvalues does not change the fact that I obtain negative quantum discord, ...
0
votes
1
answer
57
views
How do I shuffle a specific 2D cell along the z-axis in a numpy 3D matrix?
Let's say I have a 3D numpy matrix M with shape (c, b, a). I want to shuffle a specific cell (x, y) in M along the z-axis --- that is, I want to shuffle the array [M[z][y][x] for z in range(c)] and ...
0
votes
0
answers
42
views
Problem in the formatage of a doctest using numpy matrix
Let us assume that I have code in Python a function f taking one numpy matrix parameter.
I do not understand why the following doctest succeed
>>> f(U) - np.matrix([[ 2.31162781, 1.82477741, ...