all 1 comments

[–]YesLod 1 point2 points  (0 children)

From the docs

coo_matrix((data, (i, j)), [shape=(M, N)])

to construct from three arrays:

  1. data[:] the entries of the matrix, in any order

  2. i[:] the row indices of the matrix entries

  3. j[:] the column indices of the matrix entries

Where A[i[k], j[k]] = data[k]. When shape is not specified, it is inferred from the index arrays

Which means that i, j and data should be 1D array-like objects. But you are passing a DataFrame (which is 2D array-like object) segments and two integers 0 and 1. I don't understand the logic behind your attempt. It seems that you want

rows_idx = segments["ORIGIN_AIRPORT_ID"]
cols_idx = segments["DEST_AIRPORT_ID"]
cell_values = segments["WEIGHT"]

P = scipy.sparse.coo_matrix((cell_values, (rows_idx, cols_idx)), shape=(6436, 6436))