python 向量取整数
Prerequisite:
先决条件:
Defining a Vector using list
使用列表定义向量
Defining Vector using Numpy
使用Numpy定义向量
Random Integer Vector is a type of vector having a random integer value at each entry. Such types of vectors have a huge importance in Simulation and Machine Learning. Random Integer Vector can be defined by its Upper Limit, Lower Limit, and Length of the Vector (i.e. number of entries).
随机整数向量是在每个条目处具有随机整数值的向量类型。 这种类型的向量在仿真和机器学习中具有极其重要的意义。 随机整数向量可以通过其上限 , 下限和向量的长度(即条目数)来定义。
In this article, we are going to create a random integer vector using inbuilt function numpy.random.randint().
在本文中,我们将使用内置函数numpy.random.randint()创建一个随机整数向量。
Syntax:
句法:
numpy.random.randint(low, up, length)
low - lower limit for choosing random integer value
up - upper limit for choosing random integer value
length - Length of the desired vector
Application:
应用:
Machine Learning
机器学习
Probability
可能性
Constraint Based Programming
基于约束的编程
Monte Carlo Simulation
蒙特卡罗模拟
随机整数向量的Python程序 (Python program for random integer vector)
# Linear Algebra Learning Sequence
# Random Integer Vector
import numpy as np
# Example 1, length 20
t1 = np.random.randint(0,30,20)
print('Example : ', t1)
# Example 2, length 20
t2 = np.random.randint(0,100,20)
print('\n\nExample : ', t2)
# Example 3, length 20
t3 = np.random.randint(0,300,20)
print('\n\nExample : ', t3)
# Example 4, length 30
t4 = np.random.randint(40,45,30)
print('\n\nExample : ', t4)
Output:
输出:
Example : [ 6 2 14 27 23 12 15 7 23 18 17 16 13 12 19 7 27 21 28 23]
Example : [65 41 80 12 12 91 10 77 31 66 29 98 11 40 41 52 7 18 80 26]
Example : [126 14 190 21 259 268 168 88 252 270 243 112 237 2
38 112 229 106 85 48]
Example : [44 40 42 40 42 42 44 43 43 42 41 42 42 44 42 41 41 40
40 42 43 40 42 40 44 44 40 43 40 40]
翻译自: https://www.includehelp.com/python/random-integer-vector.aspx
python 向量取整数