In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article Xiaobian for you to introduce in detail "how to use the vector trinomial operator in numpy", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to use the vector trinomial operator in numpy" can help you solve your doubts.
The record is as follows:
In [76]: xarr = np.array ([1.1 1In 1.2) In [77]: yarr = xarr + 1In [78]: xarrOut [78]: array [79]: yarrOut [79]: array ([2.1,2.2,2.3,2.4,2.5]) In [80]: cond = np.array ([True,False,True,True]) False]) In [81]: condOut [81]: array ([True, False, True, True, False], dtype=bool) In [82]: result1 = [(x if c else y) for x journal c in zip (xarr,yarr,cond)] In [83]: result1Out [83]: [1.100000000001,2.200000000002,1.3,1.3999999999999999992.5] In [84]: result2 = np.where (cond,xarr,yarr) In [85]: result2Out [85]: array ([1.1,2.2]) 1.3, 1.4, 2.5])
From the floating point representation, there is a small difference between the two, multi-digits after the decimal point, usually can be ignored in the numerical representation. However, we still need to make a judgment on the consistency of the two results, because we have seen the differences in Python's floating-point expression due to machines before.
The test results are as follows:
In [87]: result1 = = result2Out [87]: array ([True, True], dtype=bool)
As can be seen from the above results, the two calculation results are consistent.
After reading this, the article "how to use the vector trinomial operator in numpy" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, welcome to follow the industry information channel.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.