SoFunction
Updated on 2024-11-14

Example of python generating multiple random arrays or lists with only 0,1 elements

Example of python generating multiple random arrays or lists with only 0,1 elements

Updated November 12, 2018 10:23:57 by manjhOK
Today I'm going to share an example of python generating multiple random arrays or lists containing only 0,1 elements, which has a good reference value and I hope it will help you. Together follow the editor over to see it

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.

  • python
  • arrays
  • listings

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 to
    2023-05-05
  • A 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 it
    2018-04-04
  • Python 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 it
    2021-09-09
  • Python 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 following
    2018-02-02
  • python 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-07
  • Dictionaries 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-05
  • Example 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-08
  • Springboo 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-09
  • python 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-12
  • Understanding 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 the
    2022-05-05

Latest Comments