You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 85f2f70
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: lectures/numpy.md
+27-41Lines changed: 27 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -238,8 +238,6 @@ z
238
238
239
239
برای خواندن دادههای آرایه از یک فایل متنی حاوی دادههای عددی، از `np.loadtxt` استفاده کنید --- برای جزئیات به [مستندات](https://numpy.org/doc/stable/reference/routines.io.html) مراجعه کنید.
240
240
241
-
242
-
243
241
### نمایهگذاری آرایه
244
242
245
243
```{index} single: NumPy; Arrays (Indexing)
@@ -400,7 +398,6 @@ z
400
398
z.searchsorted(2.2)
401
399
```
402
400
403
-
404
401
## عملیات حسابی
405
402
406
403
```{index} single: NumPy; Arithmetic Operations
@@ -449,7 +446,6 @@ A * B
449
446
(numpy_matrix_multiplication)=
450
447
به ویژه، `A * B` حاصلضرب ماتریسی *نیست*، بلکه یک حاصلضرب عنصر به عنصر است.
برای فهرست جامعی از آنچه در NumPy موجود است به [این مستندات](https://numpy.org/doc/stable/reference/routines.html) مراجعه کنید.
1104
1094
1105
-
1106
1095
### چندنخی ضمنی
1107
1096
1108
1097
[قبلاً](need_for_speed) مفهوم موازیسازی از طریق چندنخی را مورد بحث قرار دادیم.
@@ -1119,7 +1108,7 @@ NumPy سعی میکند چندنخی را در بسیاری از کد کام
1119
1108
n = 20
1120
1109
m = 1000
1121
1110
for i in range(n):
1122
-
X = np.random.randn(m, m)
1111
+
X = rng.standard_normal((m, m))
1123
1112
λ = np.linalg.eigvals(X)
1124
1113
```
1125
1114
@@ -1135,10 +1124,6 @@ for i in range(n):
1135
1124
این به این دلیل است که روتین `eigvals` NumPy به زیبایی وظایف را تقسیم میکند و
1136
1125
آنها را به نخهای مختلف توزیع میکند.
1137
1126
1138
-
1139
-
1140
-
1141
-
1142
1127
## تمرینها
1143
1128
1144
1129
@@ -1260,28 +1245,28 @@ def sample(q):
1260
1245
1261
1246
```{code-cell} python3
1262
1247
from numpy import cumsum
1263
-
from numpy.random import uniform
1264
1248
1265
1249
class DiscreteRV:
1266
1250
"""
1267
1251
یک آرایه از نمونهها را از یک متغیر تصادفی گسسته با بردار
1268
1252
احتمالات داده شده توسط q تولید میکند.
1269
1253
"""
1270
1254
1271
-
def __init__(self, q):
1255
+
def __init__(self, q, seed=None):
1272
1256
"""
1273
1257
آرگومان q یک آرایه NumPy است، یا شبیه آرایه، غیر منفی و جمع
1274
1258
به 1 میشود
1275
1259
"""
1276
1260
self.q = q
1277
1261
self.Q = cumsum(q)
1262
+
self.rng = np.random.default_rng(seed)
1278
1263
1279
1264
def draw(self, k=1):
1280
1265
"""
1281
1266
k نمونه از q برمیگرداند. برای هر چنین نمونهای، مقدار i با
0 commit comments