The numpy.random.randint() function generates random coordinate points

The numpy.random.randint() function can not only generate a one-dimensional random array, but also a multi-dimensional random array. Here, we take the coordinate points of a two-dimensional random array as an example.
Set np.random.seed(40)to maintain the repeatability of randomly generated arrays

# -*- coding:utf-8 -*-
"""
author: 15025
time: 2020/11/30 16:39
software: PyCharm

Description:
    numpy的randint与random中的randint的不同之处
"""
import random
import numpy as np


class Debug:
    @staticmethod
    def mainProgram():
        np.random.seed(40)
        array_size = (10, 2)
        array = np.random.randint(0, 5, size=array_size)
        print("array is:")
        print(array)


if __name__ == "__main__":
    main = Debug()
    main.mainProgram()
"""
array is:
[[3 0]
 [0 2]
 [1 4]
 [2 3]
 [2 3]
 [3 3]
 [1 0]
 [1 1]
 [0 4]
 [4 4]]
"""

We can see that we randomly generated a (10, 2)two-dimensional coordinate array of size .

If you find it useful, please raise your hand to give a like and let me recommend it for more people to see~

Guess you like

Origin blog.csdn.net/u011699626/article/details/110411814