Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit23bc7b9

Browse files
committed
update random data generation tutorial
1 parentc8928c2 commit23bc7b9

File tree

1 file changed

+10
-0
lines changed
  • python-standard-library/generating-random-data

1 file changed

+10
-0
lines changed

‎python-standard-library/generating-random-data/generate.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
importstring
44
importsecrets
55

6+
importnumpyasnp
7+
68
# generate random integer between a and b (including a and b)
79
randint=random.randint(1,500)
810
print("randint:",randint)
@@ -19,6 +21,14 @@
1921
choices=random.choices(range(1000),k=5)
2022
print("choices:",choices)
2123

24+
# get a random vector of size 20
25+
vector=np.random.random((30,))
26+
print("vector:\n",vector)
27+
28+
# get a random matrix of size (3, 3) in the range [0, 100]
29+
matrix=np.random.random((3,3))*100
30+
print("matrix:\n",matrix)
31+
2232
# generate a random floating point number from 0.0 <= x <= 1.0
2333
randfloat=random.random()
2434
print("randfloat between 0.0 and 1.0:",randfloat)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp