I want to compute the sum product along one dimension of two multidimensional arrays, using Theano.
I'll describe precisely what I want to do using numpy first. numpy.tensordot and numpy.dot seem to always do a matrix product, whereas I'm in essenc... more
Let A be a matrix with [m x n] elements and B another matrix with [m x n x o] elements.
Is there any linear algebraic way to add both matrices such that C = A + B where C will be in [m x n x o] without any sort of looping along the o dimension?
I'm trying to solve an Ax=b by using LU decomposition, but somehow I can't get the A by multiplying L*U. Here's the code and the results;
A = array([2,3,5,4]).reshape(2,2)
b = array([4,3])
P,L, U = lu(A)
And the results for L and U
array([[ 1... more
Considering the following matrix equation:
matrix([[ 0.477, -0.277, -0.2 ],
[-0.277, 0.444, -0.167],
[-0.2 , -0.167, 0.367]])
Out: [0, 60, 40]
how come that when I use numpy.linalg() ... more
I'm trying to use ekmett's linear library, and I'm having some trouble with variable length vectors, in Linear.V. How do I use the dim function to get the size of a vector? How do I use trace on a large square matrix made of nested Vs ? I get errors ... more
I have an array A whose shape is (N, N, K) and I would like to compute another array B with the same shape where B[:, :, i] = np.linalg.inv(A[:, :, i]).
As solutions, I see map and for loops but I am wondering if numpy provides a function to do this... more
I friend and I executed this line of code in Python 2 and Python 3:
import numpy as np
mat = np.array([[1,0,0],[-1,3,3],[1,2,2]])
array([[ 1.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 1.5011998... more
I'm trying to figure out what is going on here, but I'm a little bit baffled. I am getting unexpected results working with a transposed NumPy identity matrix (which should have no effect). For example:
import numpy as np
N = 1000
# case 1:
A = np.... more
I have a graph that contains two types of nodes: Companies and Persons.
A Company node has a list of edges that represent Shareholders. A Shareholder has a percentage of shares and is either a Company or a Person. A Person node is always a leaf.
I am playing with a simple numpy example and having hard time to understand why associative property of matrix multiplication
ABC = (AB)C = A(BC)
does not exactly hold. I assume the problem is with numeric stability. But how to address it? What i... more
I transformed the following function
def quaternion_multiply(quaternion0, quaternion1):
"""Return multiplication of two quaternions.
>>> q = quaternion_multiply([1, -2, 3, 4], [-5, 6, 7, 8])
>>> numpy.allclose(q, [-44,... more
Using R package optR for solving linear equation gives incorrect results for gauss-seidel method.
I tried solving with different methods and it looks ok. For instance solve or using optR but with method gauss.
Example is here. Or am I doing something... more
I have to find the best solution for >10^7 equation systems with 5 equations in 2 variables each (5 measurements to find 2 parameters with the least amount of error in a long series).
The following code (normally used to do curve fitting) does what I... more
I have been dealing with linear algebra problems of the form A = Bx in Python and comparing this to a colleague's code in MATLAB and Mathematica. We have noticed differences between Python and the others when B is a singular matrix. When using numpy.... more
I was wondering what the correct approach to fitting datapoints to a non-linear function should be in python.
I am trying to fit a series of data-points
t = [0., 0.5, 1., 1.5, ...., 4.]
y = [6.3, 4.5,.................]
using the following model f... more
I have 350 document scores that, when I plot them, have this shape:
docScores = [(0, 68.62998962), (1, 60.21374512), (2, 54.72480392),
(3, 50.71389389), (4, 49.39723969), ...,
(345, 28.3756237), (346, 28.37126923),
I understand how to solve Ax=b, but what if b is dependent on x? See in the pictures E3 = function(E4). I guess this is done iteratively.. what is such a problem called? what methods do I use to solve it?
I am trying to solve the following system:
To demonstrate the effect of linear transformations in 3D, x -> A x, I want to draw a cube and show its transformation under A. For this, I need to color each face separately, and also show the vertex points and the lines that outline each face.