# matrix

## Applying function to 2 vectors to obtain a 2D matrix

Applying function to 2 vectors to obtain a 2D matrix Question: My question is exactly the same as this one but in Python instead of R. I couldn’t find a similar question for python and so I’m asking this one. I have 2 vectors (lists actually) a = [1,2,3] b = [5,6,7] A defined function …

## Seaborn correlation matrix in Python: masking out based on p-values and correlation

Masking correlation matrix based on p-values and correlation Question: Based on this answer I have the following code to draw a correlation matrix which only plots data where p<0.05: import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt from scipy import stats # Simulate 3 correlated variables num_samples …

## Forming a symmetric matrix counting instances of being in same cluster

Forming a symmetric matrix counting instances of being in same cluster Question: I have a database that comprises cities divided into clusters for each year. In other words, I applied a community detection algorithm for different databases containing cities in different years base on modularity. The final database (a mock example) looks like this: v1 …

## How can I transform multiple columns in a table to list

How can I transform multiple columns in a table to list Question: How can I transform Tab 1 to Tab2 df = pd.DataFrame({‘A’: [3, 5], ‘B’: [4, 6], ‘Z’: [6, 8]}, index=[1, 100]) I suppose pandas df.melt might help, but I’m not sure Asked By: aeti || Source Answers: Use DataFrame.melt with add index values …

## How to test linear independence of binary array in python?

How to test linear independence of binary array in python? Question: The rows of this matrix are not linearly independent, as the first two rows can be added to produce the third: matrix = [ [ 1, 0, 0, 1 ], [ 0, 0, 1, 0 ], [ 1, 0, 1, 1 ], [ 1, …

## pandas – create customer movement matrix

pandas – create customer movement matrix Question: I have a dataframe that looks like below customer_id,month,Group,category,days_ago A1,Jan,Premium,saf,34 A1,Jan,Premium,ewf,342 A2,Jan,Lost,ds,643 A3,Jan,Lost,dfs,764 A4,Jan,Lost,sdfg,21 A5,Jan,Loyal,sa,87 A6,Jan,Need Attention,ewf,123 A17,Jan,Lost,tyr,128 A1,Mar,Premium,efWCC,7 A2,Mar,Need Attention,POI,9 A3,Mar,Lost,QWE,10 A4,Mar,Need Attention,QOEP,14 A4,Mar,Need Attention,POTU,32 A5,Mar,Loyal,FANC,54 A6,Mar,Lost,FAS,78 A7,Mar,New,qewr,98 A8,Mar,New,wqer,101 t1 = pd.read_clipboard(sep=’,’) I would like to do the below a) Create a matrix against Jan and Mar …

## create a matrix that shows similarity

create a matrix that shows similarity Question: I have a dataset like this: data Person Salary GPA IQ Alisson 1 1 1 Simon 1 2 2 Michael 2 3 2 Dani 2 1 2 Brian 1 2 2 David 1 1 2 Ilan 1 1 2 Juan 2 1 2 Julius 3 3 3 Philipp …

## Find all disjoint subsets of a binray matrix in Pyhton

Find all disjoint subsets of a binray matrix in Pyhton Question: I have a binary matrix, and I want to find all disjoint subsets that exist in this matrix. To clarify the problem, the matrix is a collection of image masks, masks of irregular shapes, and each disjoint subset of 1s representing a separate mask. …