linear-algebra

Numeric calculation of nullspace with Sympy is slow

Numeric calculation of nullspace with Sympy is slow Question: I want to obtain the bases for kernel (nullspace) of a matrix using the Row Reduced Echelon Form (RREF). Although scipy has the function to calculate nullspace, it does not give me sparse vectors because it uses singular value decomposition (SVD). #make an example import random …

Total answers: 1

np.linalg.svd is giving me wrong results

np.linalg.svd is giving me wrong results Question: so I am trying to learn how SVD work to use it in PCA (principle component analysis), but the problem is that it seam I get wrong results, I tryied using np.linalg.svd and this is my code : A = np.array([[2, 2], [1, 1]]) u, s, v = …

Total answers: 1

I cant find the corret structure with this specific linear system code

I cant find the corret structure with this specific linear system code Question: I am trying to code an specific linear algebra code Trying to get the x,y,z solutions that’s the code import numpy as np # Exerciocio de fixação para solução de sistemas lineares # Given ”’ 1.5x -y = 0 3x+1-z=0 ”’ # …

Total answers: 1

Projection of a 3D circle onto a 2D camera image

Projection of a 3D circle onto a 2D camera image Question: Asked this on math.stackexchange, but no responses so trying here, hopefully the computer vision people are more able to help out. Assume that I have a 3D circle with a center at (c1, c2, c3) in the circle coordinate frame C. The radius of …

Total answers: 1

Drawing an ellipse at an angle between two points in Python

Drawing an ellipse at an angle between two points in Python Question: I’m trying to draw an ellipse between two points. So far, I have it mostly working: The issue comes with setting the ellipse height (ellipse_h below). x = center_x + radius*np.cos(theta+deg) y = center_y – ellipse_h * radius*np.sin(theta+deg) In this example, it’s set …

Total answers: 1

Compute correlations of several vectors

Compute correlations of several vectors Question: I have several pairs of vectors (arranged as two matrices) and I want to compute the vector of their pairwise correlation coefficients (or, better yet, angles between them – but since correlation coefficient is its cosine, I am using numpy.corrcoef): np.array([np.corrcoef(m1[:,i],m2[:,i])[0,1] for i in range(m1.shape[1])]) I wonder if there …

Total answers: 1

"Vectorized" Matrix-Vector multiplication in numpy

"Vectorized" Matrix-Vector multiplication in numpy Question: I have an $I$-indexed array $V = (V_i)_{i in I}$ of (column) vectors $V_i$, which I want to multiply pointwise (along $i in I$) by a matrix $M$. So I’m looking for a "vectorized" operation, wherein the individual operation is a multiplication of a matrix with a vector; that …

Total answers: 2

algorithem for Insertion Sort Advanced Analysis

algorithem for Insertion Sort Advanced Analysis Question: Insertion Sort is a simple sorting technique which was covered in previous challenges. Sometimes, arrays may be too large for us to wait around for insertion sort to finish. Is there some other way we can calculate the number of shifts an insertion sort performs when sorting an …

Total answers: 1

How to solve 3 equations in Python without matrix?

How to solve 3 equations in Python without matrix? Question: Hi I have 3 simple equation that I wanted to solve in python. 5x+9y=23 2x+3z=11 7x+5y+6z=35 first I wanted to solve with np.array but first two equation has 2 different unknowns. I can’t find similar problems in internet and I don’t know what should I …

Total answers: 1

Finding Permutation Matrix with NumPy

Finding Permutation Matrix with NumPy Question: I am looking for the correct permutation matrix that would take matrix a and turn it into matrix b given a = np.array([[1,4,7,-2],[3,0,-2,-1],[-4,2,1,0],[-8,-3,-1,2]]) b = np.array([[-4,2,1,0],[3,0,-2,-1],[-8,-3,-1,2],[1,4,7,-2]]) I tried x = np.linalg.solve(a,b) However, I know this is incorrect and it should be np.array([[0,0,1,0],[0,1,0,0],[0,0,0,1],[1,0,0,0]]) What numpy code would deliver this matrix …

Total answers: 2