kgraph icon indicating copy to clipboard operation
kgraph copied to clipboard

what about the ValueError: bad alignment

Open yang502 opened this issue 7 years ago • 5 comments

My input dataset has converted as numpy matrices by np.asmatrix() and it's dim is 1024; I use the python API

yang502 avatar Jul 28 '17 03:07 yang502

I have the same problem. This may be related to the shape of input matrix: the number of samples should be larger than the dimension of features to some extent. How to handle this problem?

zekizz avatar Dec 07 '17 06:12 zekizz

I need more details. A well-aligned piece of data should start with an address divisible by 4 or 8, and the size of each row should be divisible by 4 or 8 (4 for float and 8 for double).

aaalgo avatar Dec 07 '17 13:12 aaalgo

Hi, I'm running into a similar "valueError: bad alignment". I have a numpy array shape (100000,24) of dtype float32 but I get the 'bad alignment error'. I'm not sure what you mean by 'the data should start with an address divisible by 4 or 8'. How do I ensure my numpy-array has this kind of address? the numpy array is made from a subset of columns from a pandas dataframe. If i make a numpy array from random.rand(100000,24), then i dont get the valueError and the KNN graph is constructed.

cestas avatar Mar 22 '18 04:03 cestas

I found a 'hacky' way of solving this. just repopulating the random.rand matrix with the values from the dataframe matrix... i suppose the data is now at the correct memory address....

cestas avatar Mar 22 '18 05:03 cestas

The easiest way is to np.copy the matrix before feeding it in. Sometimes the matrix is a view of a bigger matrix. In such case, both the view and the original matrix share the underlying data and therefore the same row stride.

aaalgo avatar Mar 22 '18 13:03 aaalgo