Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use numpy's nonzero to find out non-zero elements

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to use numpy's nonzero to find out non-zero elements". The editor shows you the operation process through actual cases. The method of operation is simple and fast, and it is practical. I hope this article "how to use numpy's nonzero to find out non-zero elements" can help you solve the problem.

Let's go straight to the code ~ import numpy as npa = np.array ([[30Ling 40jing70], [80Ling 20jing10], [50jin90]]) print (a) print (np.nonzero (a)) [[304070] [802010] [509060]] (array ([0,0,0lle 1,1,2,2,2], dtype=int64), array ([0,20,10,10,10,1,2], dtype=int64)

The first array is the x-axis and the second array is the y-axis

Add: [Numpy Learning] python search matrix index (np.nonzero ()) that is not a zero element

When using the matrix decomposition method to make the model, it is necessary to verify the results of the model.

The mask training set, verification set, and test set are required during the verification process.

At this point, you need the index values of the non-zero element and the zero element in the original matrix S SS. This method is the find method in matlab, and np.nonzero () is required when implemented in python.

Look at the following code: import numpy as npa = np.arange (12) .reshape (3,4) print (a) [[0123] [4 567] [8 9 10 11]] print (np.nonzero (a)) (array ([0,0,0,1,1,1,1,2,2,2]), array ([1,2,3,0,1,2,3,0,1,2,3]))

It is worth noting that np.nonzero (a) outputs two array values in the first array that refer to rows and the second to columns.

For example, 0minute 1 indicates that the value of the first column in row 0 is not 0.

This is the end of the introduction to "how to use numpy's nonzero to find non-zero elements". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report