1
2
3
4 # 这个data_matrix[:,dimen] <= thresh_val 内标会返回data_matrix当中的值符合条件的,返回为True
5 # ret_array 中就会返回 下标为True的值
6 ret_array[data_matrix[:,dimen] <= thresh_val] = -1.0
7
8
9 # https://www.cnblogs.com/prolifes/articles/5195528.html
10 # 亲测季度可用
11
12 #coding=utf-8
13 import datetime
14 from datetime import timedelta
15
16 now = datetime.datetime.now()
17
18 #今天
19 today = now
20
21 #昨天
22 yesterday = now - timedelta(days=1)
23
24 #明天
25 tomorrow = now + timedelta(days=1)<br><br>#当前季度
26
27 now_quarter = now.month / 3 if now.month % 3 == 0 else now.month / 3 + 1
28
29 #本周第一天和最后一天
30 this_week_start = now - timedelta(days=now.weekday())
31 this_week_end = now + timedelta(days=6-now.weekday())
32
33 #上周第一天和最后一天
34 last_week_start = now - timedelta(days=now.weekday()+7)
35 last_week_end = now - timedelta(days=now.weekday()+1)
36
37 #本月第一天和最后一天
38 this_month_start = datetime.datetime(now.year, now.month, 1)
39 this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1)
40
41 #上月第一天和最后一天
42 last_month_end = this_month_start - timedelta(days=1)
43 last_month_start = datetime.datetime(last_month_end.year, last_month_end.month, 1)
44
45 #本季第一天和最后一天
46 month = (now.month - 1) - (now.month - 1) % 3 + 1
47 this_quarter_start = datetime.datetime(now.year, month, 1)
48 this_quarter_end = datetime.datetime(now.year, month + 3, 1) - timedelta(days=1)
49
50 #上季第一天和最后一天
51 last_quarter_end = this_quarter_start - timedelta(days=1)
52 last_quarter_start = datetime.datetime(last_quarter_end.year, last_quarter_end.month - 2, 1)
53
54 #本年第一天和最后一天
55 this_year_start = datetime.datetime(now.year, 1, 1)
56 this_year_end = datetime.datetime(now.year + 1, 1, 1) - timedelta(days=1)
57
58 #去年第一天和最后一天
59 last_year_end = this_year_start - timedelta(days=1)
60 last_year_start = datetime.datetime(last_year_end.year, 1, 1)