patternsqlMinor
Have several 128 elements lists, need to obtain distance between them
Viewed 0 times
128obtainelementsneeddistanceseveralbetweenliststhemhave
Problem
Is storing them in a
I can not save them as a list of floats, since i get: "can't adapt type numpyndarray"
Can not cast a type bytea to type cube, either.
Cube extension is installed, i can convert the list to type bytea using psycopg2, but nothing seems to work.
What am i missing?
I'm using postgresql 10.4, python 3, postgresapp 2.1.4 and postico
CUBE type field and then getting euclidean distance, (using ``) the only way?I can not save them as a list of floats, since i get: "can't adapt type numpyndarray"
Can not cast a type bytea to type cube, either.
Cube extension is installed, i can convert the list to type bytea using psycopg2, but nothing seems to work.
What am i missing?
I'm using postgresql 10.4, python 3, postgresapp 2.1.4 and postico
Solution
I can not save them as a list of floats, since i get: "can't adapt type numpyndarray"
Quick google search shows numpyndarray as being SciPy's "N-dimensional array". This can hold what PostgreSQL calls a cube and vise-versa.
You assume that there is a translation layer that takes
That means you'll be calling
Your job is to convert
Cubes can also be constructed as
Quick google search shows numpyndarray as being SciPy's "N-dimensional array". This can hold what PostgreSQL calls a cube and vise-versa.
You assume that there is a translation layer that takes
numpyndarray and converts the types to a cube for you. There likely isn't. You could provide such a layer, or extend your PostgreSQL connector/driver to provide that layer (see this for information on psycopg), but shy of that you'll have to go by way of text.That means you'll be calling
cube() or providing a text string and a cast to cube.SELECT '(0,1,2,3,4,5)'::cube;
SELECT CAST ( '(0,1,2,3,4,5)' AS cube );Your job is to convert
numpyndarray to a textual representation like the above, and then to convert it back again.Cubes can also be constructed as
float[] which you may find easier if your DB layer supports that,SELECT cube(ARRAY[0,1,2,3,4,5]::float[]); ## Array-constructor for float[]
SELECT cube('{1,2,3,4,5}'::float[]); ## Text-constructor for float[]Code Snippets
SELECT '(0,1,2,3,4,5)'::cube;
SELECT CAST ( '(0,1,2,3,4,5)' AS cube );SELECT cube(ARRAY[0,1,2,3,4,5]::float[]); ## Array-constructor for float[]
SELECT cube('{1,2,3,4,5}'::float[]); ## Text-constructor for float[]Context
StackExchange Database Administrators Q#207516, answer score: 2
Revisions (0)
No revisions yet.