Example of python generating multiple random arrays or lists with only 0,1 elements
As shown below:
>>> import numpy as np >>> myarray= (0,2,10)The output contains only0,1One-dimensional array of elements,lengths10 >>> myarray array([1, 1, 1, 0, 1, 0, 0, 1, 1, 0]) >>> myarray= (0,2,(3,10))The output contains only0,1elemental3classifier for objects in rows such as words10array of columns >>> myarray array([[0, 1, 0, 1, 1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 1, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 1, 0, 1, 1, 0]]) >>> myarray=(0,2)When the third parameter value is omitted,The output has only one value,randomization0,1 >>> myarray 0 >>> myarray=(0,2) >>> myarray 0 >>> myarray=(0,2) >>> myarray 0 >>> myarray=(0,2) >>> myarray 1 >>>
The above example of this python generating multiple random arrays or lists containing only 0,1 elements is all that I have shared with you.
Related articles
Python JWT authentication and pyjwt package details
JWT statement is generally used to pass between the identity provider and the service provider is authenticated user identity information , in order to obtain resources from the resource server , but also to add some additional other business logic must be declared information , the token can also be used directly for authentication , but also be encrypted , this article introduces the Python JWT authentication with the pyjwt package introduction , the need for the friends can refer to2023-05-05A method to sort a two-dimensional array by a column or row in numpy
Below I will share with you a numpy in the realization of a two-dimensional array in accordance with a certain column, a certain line sorting method, has a very good reference value, I hope to help you. Together follow the editor over to see it2018-04-04Python combined with Selenium simple implementation of Web automation testing
This article is an entry-level application of Python + Selenium for automation testing, including environment setup and simple examples, with certain reference value, interested partners can refer to it2021-09-09Python implementation to compare the difference between two images
This article mainly introduces the use of python to achieve the comparison of two pictures of different information, need friends can refer to the following2018-02-02python implement a simple chat room function can be private chat
This article is mainly for you to introduce in detail the realization of python simple chat room function, you can chat privately, with certain reference value, interested partners can refer to it!2019-07-07Dictionaries and nested traversals in python
This article introduces dictionary and nested traversal in python, with good reference value, I hope to help you. If there is any error or not fully considered, please do not hesitate to give advice!2023-05-05Example of pandas grouping by Series
This article introduces pandas in accordance with the Series grouping example, the text through the sample code is very detailed, with certain reference value, interested partners can refer to it!2021-08-08Springboo how t dynamically modify configuration file attributes
This article describes how Springboo t dynamically modify the configuration file attributes, with good reference value, I hope to help you, if there is any error or not fully consider the place, I hope you do not spare any advice!2023-09-09python object-oriented tutorials for beginners from the code reuse (I)
This article introduces you to the python object-oriented tutorials from the beginning of the code reuse related information, the text through the sample code is very detailed, for everyone to learn or use python has a certain reference learning value, the need for friends to take a look at it together!2018-12-12Understanding Processes, Threads, and Concurrency in Python in One Article
Concurrent programming is a way to achieve multi-tasking and improve system performance, Python concurrent programming relies on processes, threads and co-programming, this article will explain the differences between the three through examples, interested parties can learn about the2022-05-05