View Categories

10.6. الرياضيات

< 1 دقيقة

جدول المحتويات

10.6. الرياضيات #

تتيح وحدة الرياضيات الوصول إلى دوال مكتبة C الأساسية لعمليات حسابية ذات نقطة عائمة:

>>> import math
>>> math.cos(math.pi / 4)
0.70710678118654757
>>> math.log(1024, 2)
10.0

توفر وحدة العشوائية أدوات لإجراء اختيارات عشوائية:

>>> import random
>>> random.choice(['apple', 'pear', 'banana'])
'apple'
>>> random.sample(range(100), 10)   # sampling without replacement
[30, 83, 16, 4, 8, 81, 41, 50, 18, 33]
>>> random.random()    # random float
0.17970987693706186
>>> random.randrange(6)    # random integer chosen from range(6)
4

تحسب وحدة الإحصاء الخصائص الإحصائية الأساسية (المتوسط، الوسيط، التباين، إلخ) للبيانات الرقمية:

>>> import statistics
>>> data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5]
>>> statistics.mean(data)
1.6071428571428572
>>> statistics.median(data)
1.25
>>> statistics.variance(data)
1.3720238095238095

يحتوي مشروع SciPy <https://scipy.org> على العديد من الوحدات الأخرى للحسابات الرقمية.

error: Content is protected !!
Scroll to Top