Get the App
SLTechnology News&Howtos  ›  Development  › 

How to deal with Nan in Matrix in numpy

Shulou Source: shulou.com Published: 2022-06-01 02:27:50 10月03日 Update

In this article Xiaobian introduces in detail "how to deal with Nan in matrix in numpy", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to deal with Nan in matrix in numpy" can help you solve your doubts.

Let's replace the missing values with averages, which are based on those that are not NaN.

From numpy import * datMat = mat ([[1dje 2je 3], [4je Nanjue 6]]) numFeat = shape (datMat) [1] for i in range (numFeat): meanVal = mean (datMatt [nonzero (~ isnan (datMat [:, I] .A)) [0], I]) # values that are not NaN (a number) datMat [nonzero (datMat [:, I] .A)) [0], I] = meanVal # set NaN values to mean read here This article "how to deal with Nan in matrix in numpy" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about the article, please follow the industry information channel.

Tags: Matrix article content average appropriateness ideas new knowledge more steps knowledge knowledge points articles details missing industry information information channels follow channels processing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB MySQL macOS Linux