How can I convert a two column array to a matrix with counts of occurences?

前端 未结 5 737
礼貌的吻别
礼貌的吻别 2021-02-02 08:21

I have the following numpy array:

import numpy as np

pair_array = np.array([(205, 254), (205, 382), (254, 382), (18, 69), (205, 382), 
                       (31         


        
5条回答
  •  旧时难觅i
    2021-02-02 09:19

    This is crosstab:

    pd.crosstab(pair_array[:,0], pair_array[:,1])
    

    Output:

    col_0  69   82   183  254  267  382
    row_0                              
    18       1    0    0    0    0    0
    31       0    1    1    0    1    0
    183      0    0    0    0    1    1
    205      0    0    0    1    0    2
    254      0    0    0    0    0    1
    

提交回复
热议问题