Effacer les filtres
Effacer les filtres

Sparse for arrays with lots of NaN.

19 vues (au cours des 30 derniers jours)
Laurent
Laurent le 4 Sep 2013
Hi,
I am using very large arrays containing a lot fo NaNs. If they were zeros, I could use 'sparse' to save a lot of memory, but since they are NaNs this does not work. Does a sparse datatype exist for arrays with a lot of NaNs?

Réponse acceptée

Matt J
Matt J le 4 Sep 2013
No, but why do you insist on using NaNs instead of zeros?
  4 commentaires
Matt J
Matt J le 4 Déc 2017
Modifié(e) : Matt J le 4 Déc 2017
How often does sensor failure occur? Is it really often enough to benefit from a sparse representation? That would mean that at least half of your records are invalid.
But in any case, you could, for example, add +1 to all the valid wind speed values so that they are encoded into the interval [1,101]. Then reserve 0 for missing data. Since you clearly don't plan to do linear algebra with this matrix, I don't think this should interfere with anything.
Walter Roberson
Walter Roberson le 4 Déc 2017
Modifié(e) : Walter Roberson le 4 Déc 2017
Construct a sparse logical array of locations that are nan. Zero those locations out in the other array and sparse that (assuming that less than about 1/3 of the entries remain as non-zero, to make it worth while to construct the sparse array.)
If more than about 2/3 of your locations are nan, then it might instead make sense to create a logical array of locations which were originally 0 and not nan, and zero out the nan values and sparse the result of that; then the entries in the logical array would say where the "true" zeros are, and the rest of the zeros in the second array would be assumed to be nan.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Sparse Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by