I need to insert a matrix inside another one using numpy The matrix i need to insert is like this one: tetraminos = [[0, 1, 0], [1, 1, 1]] While the other matrix is like this: board = …
Tag: matrix
create a matrix from combinations with values
I have some combinations like (A,B) = 1 (A,C) = 0 (A,D) = 1 (B,C) = 1 (B,D) = 1 (C,D) = 0 Any idea on how I efficiently can create a four by four matrix with these 0,1 values from all these …
comparing a number of lists in pairs
I have problem with 4 list each one got 4 number: P1= [3,1,3,4] P2= [5,4,3,7] P3= [7,4,8,1] P4= [10,3,2,1] I need to get the biggest number in combinational way like: Pair of 2: p1p2, p1p3, p1p4, …
Python Numpy make a pattern with a square matrix of any dimension
I am having difficulties trying to generate a specific pattern that would work for any square matrix with any square dimension using NumPy For example: User input: n = 3 Output: [[1 2 0] [2 3 2] [0 …
Numpy insert matrix values with matrix index
I have the following code which creates a 4D grid matrix and I am looking to insert the rolled 2D vals matrix into this grid. import numpy as np k = 100 x = 20 y = 10 z = 3 grid = np.zeros((y, k, x, …
Compute sum of power of large sparse matrix
Given a query vector (one-hot-vector) q with size of 50000×1 and a large sparse matrix A with size of 50000 x 50000 and nnz of A is 0.3 billion, I want to compute r=(A + A^2 + … + A^S)q (usually 4 &…
how to convert lists of lists into array in python?
I am calculating the similarity scores for a pair of nodes in a graph, the result is a lists of lists as detailed below: example output [[[(0, 1), 0.3666666666666667], [(0, 13), 0.3333333333333333], [(…
Python Function is returning none although there is the original Value instead of copy
I have a code where I zero a column or row if it contains zero , I have my own function but when I use it it returns None , I made a copy of my matrix and performed changes on it and then I converted …
A robust way to keep the n-largest elements in rows or colums in the matrix
I would like to make a sparse matrix from the dense one, such that in each row or column only n-largest elements are preserved. I do the following: def sparsify(K, min_nnz = 5): ”’ This function …
Combination of rows in numpy.ndarray
I have the following numpy.ndarray I want to find all the possible combinations of sum of each row (sum of individual elements of a row except the last column) of S[0,:,:] with each row of S[1,:,:], i.e., my desired result is (order does not matter): which is a 9-by-2 array resulting from 9 possible combinations […]