Update shape attr of DOK/COO
jvail opened this issue · comments
Description
I'd like to resize/reshape a sparse array along one or more dimensions.
Example Code
s = sparse.COO(np.reshape(np.arange(9.), (3,3)), fill_value=np.nan)
s.todense()
array([[0., 1., 2.],
[3., 4., 5.],
[6., 7., 8.]])
s.shape = (4,4)
s.todense()
array([[ 0., 1., 2., nan],
[ 3., 4., 5., nan],
[ 6., 7., 8., nan],
[nan, nan, nan, nan]])
This is exactly the result I need but I was wondering if it is OK to just update the shape
attr of a sparse array. Is it? It is not mentioned in the docs so I am not sure if shape
is intended to be read-only or if this is the proper way to reshape a COO/DOK array. The result of s.resize((4,4)) is not what what I need. I my case it will just grow and never shrink.
Thank you
Jan
Hello, the short answer is it works for now, but it may or may not work in the future. I'll try to write a somewhat longer answer later today.