matrix

How to solve a system of linear equations in Python with an iterative method?

How to solve a system of linear equations in Python with an iterative method? Question: I have a system of linear equations represented as strings in Python, and I need to find integer values (positive or negative) for each of the variables that satisfy all equations simultaneously without contradictions. The number of variables and equations …

Total answers: 1

Python matrix input not working this way?

Python matrix input not working this way? Question: I have tried several ways that are working. But, this one is not. Please help me understand why ? row, col = 2, 3 mat1 = [[None]*col]*row print(mat1) for i in range(0, row): for j in range(0, col): mat1[i][j] = int(input()) print(mat1) Input: 1 2 3 4 …

Total answers: 2

Fastest way to add matrices of different shapes in Python/Numba

Fastest way to add matrices of different shapes in Python/Numba Question: I want to "add" two matrices, a matrix a with shape (K,T) and a matrix b of shape (K,N), to result in a matrix of shape (K,T,N) The following works ok: import numpy as np from numba import njit @njit def add_matrices(a, b): K, …

Total answers: 2

Confused about creating a result matrix for NxN matrix transposition in Python

Confused about creating a result matrix for NxN matrix transposition in Python Question: NxN Matrix transposing gives wrong answers upon making "result" matrix = input matrix Novice programmer here. I am trying to transpose a NxN matrix. Putting the code here to make the problem clear: def flippingMatrix(matrix): result=[[0 for i in range(len(matrix))] for j …

Total answers: 2

How to substitute values in matrix operation without solving?

How to substitute values in matrix operation without solving? Question: Literally what it says in the title. Let’s pretend the operation is addition of matrices. from sympy import Matrix, latex A = Matrix([[-7, 0], [4, 0]]) B = Matrix([[2, 0], [-3, -3]]) print( (A+B).a_method_that_evaluates_but_does_not_solve() ) I would like to get the following output. [[-7 + …

Total answers: 2

Get elements for the same values in numpy

Get elements for the same values in numpy Question: There is a numpy matrix: bins =array([[2076., -861.84471079], [2076., -858.23866597], [2076., -861.84471079], …, [9757., 1847.33889178], [9757., 1830.39082856], [9757., -932.14347751]]) I want to collect all the elements along the 1 axis for each unique value along the 0 axis: bins = array([[2076., [-861.84471079, -858.2386, -861.84471]], [9757., [1847.33889178, …

Total answers: 1

How can I create a multiindex matrix from a 4D xarray dataset?

How can I create a multiindex matrix from a 4D xarray dataset? Question: I currently have a 4D dataset ds in xarray that looks like this: <xarray.Dataset> Dimensions: (lat: 60, lon: 78, time: 216, pres: 395) Coordinates: * lat (lat) float32 0.5 1.5 2.5 3.5 4.5 5.5 … 55.5 56.5 57.5 58.5 59.5 * lon …

Total answers: 1

Transition Matrix from Pandas Dataframe That Has Two Periods in Python

Transition Matrix from Pandas Dataframe That Has Two Periods in Python Question: I have a dataset that shows the customer’s payment information for their dept. Each customer have two periods of data. CUST_ID PERIOD Delinquency Value 100729 1 1 100729 2 3 100888 1 2 100888 2 1 137300 1 0 137300 2 1 I …

Total answers: 1

Generate an m*n matrix with 1 and 0 (No identity)

Generate an m*n matrix with 1 and 0 (No identity) Question: I need to generate an m*n matrix with 1 and 0 where the sum of each row is 1 and each column is greater than or equal to 1. I’m trying this code but I don’t know how to limit my condition on the …

Total answers: 2

List of pairwise distances from full pairwise distance matrix

List of pairwise distances from full pairwise distance matrix Question: All the answers I have found already deal with the opposite problem of generating a pairwise distance matrix from a list of pairwise distances. Assuming I have a full pairwise distance matrix in the format: 1 2 3 4 5 1 0.000 1.154 1.235 1.297 …

Total answers: 2