当前位置:网站首页>Numpy finding the mean value of non-zero elements of matrix
Numpy finding the mean value of non-zero elements of matrix
2022-07-22 19:06:00 【yijun009】
If we have a matrix A, Want to require the mean value of non-zero elements , The way of calculation is :
Direct use mean If you ask , The denominator is the number of all elements , It doesn't meet our requirements .
stay matlab in , To do so :
mean(AA(AA~=0))
numpy:
import numpy as np
a = np.array([[0,1],[0,0]])
exist = (a != 0)
mean_value = a.sum()/exist.sum()
Use this method first , Succinct not found .
Reference resources :https://blog.csdn.net/iteapoy/article/details/85139485
边栏推荐
猜你喜欢
MySQL statement execution order
Leetcode 304. two dimensional area and retrieval - matrix immutable
Programmer interview golden code interview question 01.03. URL
leetCode笔记
PTA 6-11 find the median of self-determined type element sequence (25 points)
【YOLOv5实战4】基于YOLOv5的交通标志识别系统-模型测试与评估
Stm32+esp8266+mqtt protocol connects onenet IOT platform
PTA basic question 7-23 currency conversion (20 points) (true)
How to resolve errors in executing the yum makecache command
[QT source code reuse] simulate the pop-up mode of qcompleter
随机推荐
代码—
Go language learning: go language journey - exercise questions and reference answers
PCV、PIL、Pillow安装
Go concurrency mode: pipeline and cancellation
1. Where is the date for qdate (), 2. QT_ Usage Summary of version
Summary of all usage of join in SQL syntax (simple example)
[summary of linked list skills] 141. Circular linked list (simple)
Three ways to restrict IP access between micro services
Learning to Incorporate Structure Knowledge for Image Inpainting
用LaTeX写论文时如何加资助信息
Six dimensional space
Strncpy() copy string (limited by length)
Leetcode 116. fill in the next right node pointer of each node
Stm32+esp8266+mqtt protocol connects onenet IOT platform
C language static and extern knowledge points
Message Oriented Middleware
Tcpdump 简单用法
Flink learning notes (VII) processing function
Leetcode:196. delete duplicate email
Interrogation aléatoire de n données dans diverses bases de données