Лабораторные_Python / тема4
.pdfConvert a time in seconds since the Epoch to a string in local time.
This is equivalent to asctime(localtime(seconds)). When the time tuple is not present, current time as returned by localtime() is used.
>>> time.ctime(c1)
'Tue Oct 13 19:39:25 2020'
# time.ctime(n) преобразует n секунд, прошедших с начала эпохи, в строку, характеризующую время.
>>> help(time.sleep)
Help on built-in function sleep in module time:
sleep(...) sleep(seconds)
Delay execution for a given number of seconds. The argument may be a floating point number for subsecond precision.
>>> time.sleep(5)
# time.sleep(n) прерывает работу программы на n секунд.
>>> help(time.mktime)
Help on built-in function mktime in module time:
mktime(...)
mktime(tuple) -> floating point number
Convert a time tuple in local time to seconds since the Epoch.
Note that mktime(gmtime(0)) will not generally return zero for most time zones; instead the returned value will either be equal to that
of the timezone or altzone attributes on the time module.
>>>time.mktime(dat2)
1602607549.0
# time.mktime(a) преобразует объект a, характеризующий время, класса "кортеж" или struct_time в число секунд с начала эпохи.
>>>time.localtime(c1)
time.struct_time(tm_year=2020, tm_mon=10, tm_mday=13, tm_hour=19, tm_min=39, tm_sec=25, tm_wday=1, tm_yday=287, tm_isdst=0)
#Пункт 7
>>>import pylab
>>>x=list(range(-3,55,4))
>>>t=list(range(15))
>>>pylab.plot(t,x)
[<matplotlib.lines.Line2D object at 0x0000018CCE194A08>]
>>>pylab.title('Первый график') Text(0.5, 1.0, 'Первый график')
>>>pylab.xlabel('время') Text(0.5, 0, 'время')
>>>pylab.ylabel('сигнал') Text(0, 0.5, 'сигнал')
>>>pylab.show()
#На изображении представлен линейный график с заголовком "Первый график" и подписями осей: горизонтальная - "время", вертикальная - "сигнал".
>>>region=['Центр','Урал','Сибирь','Юг']
>>>naselen=[65,12,23,17]
>>>pylab.pie(naselen,labels=region)
11
([<matplotlib.patches.Wedge object at 0x0000018CCDF1BD08>, <matplotlib.patches.Wedge object at 0x0000018CD05E1648>, <matplotlib.patches.Wedge object at 0x0000018CD05E70C8>, <matplotlib.patches.Wedge object at 0x0000018CD05E7AC8>], [Text(-0.1910130855889933, 1.083288512416601, 'Центр'), Text(-0.8613283319035216, -0.6841882085072037, 'Урал'), Text(0.04429273729355889, -1.0991078898011077, 'Сибирь'), Text(0.9873752043868569, - 0.4848610169543564, 'Юг')])
>>> pylab.show()
#На изображении представлена круговая диаграмма с 4 областями: 'Центр','Урал','Сибирь','Юг'.
#Пункт 8
>>>import statistics
>>>dir(statistics)
['Decimal', 'Fraction', 'StatisticsError', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_coerce', '_convert', '_counts', '_exact_ratio', '_fail_neg', '_find_lteq', '_find_rteq', '_isfinite', '_ss', '_sum', 'bisect_left', 'bisect_right', 'collections', 'groupby', 'harmonic_mean', 'math', 'mean', 'median', 'median_grouped', 'median_high', 'median_low', 'mode', 'numbers', 'pstdev', 'pvariance', 'stdev', 'variance']
>>> help(statistics.mean)
Help on function mean in module statistics:
mean(data)
Return the sample arithmetic mean of data.
>>>mean([1, 2, 3, 4, 4])
2.8
>>>from fractions import Fraction as F
>>>mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)]) Fraction(13, 21)
>>>from decimal import Decimal as D
>>>mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")]) Decimal('0.5625')
If ``data`` is empty, StatisticsError will be raised.
>>>statistics.mean([-3,0,2,3])
0.5
# statistics.mean(a) возвращает среднее значение, рассчитанное по элементам последовательности a.
>>>help(statistics.median)
Help on function median in module statistics:
median(data)
Return the median (middle value) of numeric data.
When the number of data points is odd, return the middle data point. When the number of data points is even, the median is interpolated by taking the average of the two middle values:
>>>median([1, 3, 5])
3
>>>median([1, 3, 5, 7])
4.0
>>>statistics.median([-4,2,2,1])
1.5
12
# statistics.median(a) возвращает значение медианы, рассчитанное по последовательности a.
>>> help(statistics.stdev)
Help on function stdev in module statistics:
stdev(data, xbar=None)
Return the square root of the sample variance.
See ``variance`` for arguments and other details.
>>> stdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75]) 1.0810874155219827
>>>statistics.stdev([1,2,3])
1.0
# statistics.stdev(a) возвращает значение стандартного отклонения, рассчитанного по последовательности a.
>>>help(statistics.mode)
Help on function mode in module statistics:
mode(data)
Return the most common data point from discrete or nominal data.
``mode`` assumes discrete data, and returns a single value. This is the standard treatment of the mode as commonly taught in schools:
>>> mode([1, 1, 2, 3, 3, 3, 3, 4]) 3
This also works with nominal (non-numeric) data:
>>> mode(["red", "blue", "blue", "red", "green", "red", "red"]) 'red'
If there is not exactly one most common value, ``mode`` will raise
StatisticsError.
>>>statistics.mode([1,1,1,2,3,3])
1
# statistics.mode(a) возвращает наиболее распространенную точку данных, определенную по последовательности a.
>>>help(statistics.variance)
Help on function variance in module statistics:
variance(data, xbar=None)
Return the sample variance of data.
data should be an iterable of Real-valued numbers, with at least two values. The optional argument xbar, if given, should be the mean of the data. If it is missing or None, the mean is automatically calculated.
Use this function when your data is a sample from a population. To calculate the variance from the entire population, see ``pvariance``.
Examples:
13
>>>data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5]
>>>variance(data)
1.3720238095238095
If you have already calculated the mean of your data, you can pass it as the optional second argument ``xbar`` to avoid recalculating it:
>>>m = mean(data)
>>>variance(data, m) 1.3720238095238095
This function does not check that ``xbar`` is actually the mean of ``data``. Giving arbitrary values for ``xbar`` may lead to invalid or impossible results.
Decimals and Fractions are supported:
>>>from decimal import Decimal as D
>>>variance([D("27.5"), D("30.25"), D("30.25"), D("34.5"), D("41.75")]) Decimal('31.01875')
>>>from fractions import Fraction as F
>>>variance([F(1, 6), F(1, 2), F(5, 3)])
Fraction(67, 108)
>>> statistics.variance([1,2,3]) 1
# statistics.variance(a) возвращает значение дисперсии, рассчитанное по последовательности a.
14
