Skip to content
Advertisement

Tag: matrix

Pythonic way to “condense” a matrix

If I have the following matrix, which the input format is a list of lists: B T E 0 1 0 0 1 1 0 2 1 1 2 0 How can I construct the following python matrix: Where the elements of D, merge the pairs (B,E) with it’s respective T. Example: (0,1) in the above matrix, have T =

Putting serial values in a matrix with Python

I have a stream of elements that are coming serially: (x0, y0, val0), (x1, y2, val1), … (xN, yN, valN), etc. x and y are the coordinates directly pointing where the val should be put in a matrix. I tried the following but it does not work (I expected the interpreter will automatically expand the matrix but it does not):

create a matrix from combinations with values

I have some combinations like Any idea on how I efficiently can create a four by four matrix with these 0,1 values from all these combinations? So the result will be something like: Answer Imagine if the “combinations” are stored in a file in the following format (or similar): Then you can do: Example (using your sample data): Now df

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, p2p3, p2p4, p3p4 Pairs of 3: p1p2p3, p1p2p4, p1p3p4, p2p3p4 Pairs of 4: p1p2p3p4 The result for: p1p2= [5,4,3,7] p1p3= [7,4,8,4] p1p4= [10,3,3,4] ……

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. If vals would be a 1D array and I would use a 1D insert_map array as a reference it would work, however using it in multiple dimensions seems to be an issue and it raises

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 here I have each node pair similarity scores How can i put this in matrix form with each column having nodes and rows bare the similarity score? Any help will be much appreciated here

Advertisement