You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a sparse vector — the result of applying sklearn's TfidfVectorizer:
<Compressed Sparse Row sparse matrix of dtype 'float64'
with 4 stored elements and shape (1, 157541)>
Coords Values
(0, 5051) 0.35521903059198523
(0, 14956) 0.5566306658037382
(0, 45152) 0.7328483894186835
(0, 60738) 0.1640578566196061
which I want to copy into a table with a sparsevec column. As far as I understand from the documentation, the correct way to do this is the following:
with cur.copy(
"COPY my_table FROM STDIN WITH (FORMAT BINARY)"
) as copy:
copy.set_types(["sparsevec"])
copy.write_row((SparseVector(the_sparse_vector),))
but this produces an error:
psycopg.errors.DataException: sparsevec indices must not contain duplicates
I've investigated a bit and found this line which uses value.coords[0] (not value.coords[1] for two dimensional input). Is this a bug? What should I do?
I have a sparse vector — the result of applying
sklearn
's TfidfVectorizer:which I want to copy into a table with a
sparsevec
column. As far as I understand from the documentation, the correct way to do this is the following:but this produces an error:
I've investigated a bit and found this line which uses
value.coords[0]
(notvalue.coords[1]
for two dimensional input). Is this a bug? What should I do?Additional information about the example:
outputs:
The text was updated successfully, but these errors were encountered: