numpy
Posted chjh
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了numpy相关的知识,希望对你有一定的参考价值。
1、处理日期时间
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import datetime print (datetime.datetime.now()) print ( "--------------------------------" ) from datetime import datetime,timedelta now = datetime.now() print (now) print ( "--------------------------------" ) dt = datetime( 2019 , 10 , 22 , 8 , 59 ) print (dt) print ( "--------------------------------" ) cday = datetime.strptime( ‘2015-6-1 18:19:59‘ , ‘%Y-%m-%d %H:%M:%S‘ ) print (cday) print ( "--------------------------------" ) now1 = now.strftime( ‘%a, %b %d %H:%M‘ ) print (now1) print ( "--------------------------------" ) print ( ‘今天是{0:%y}年的第{0:%j}天。‘ . format (now)) print ( "--------------------------------" ) print (dt - now) print ( "--------------------------------" ) |
2.
数列:a = a1,a2,a3,·····,an ; b = b1,b2,b3,·····,bn
求:c = a12+b13,a22+b23,a32+b33,·····+an2+bn3
import
numpy as py
from
datetime
import
datetime
def
listSum(n):
a
=
list
(
range
(n))
b
=
list
(
range
(
0
,
5
*
n,
5
))
c
=
[]
for
i
in
range
(
len
(a)):
c.append(a[i]
*
*
2
+
b[i]
*
*
3
)
return
c
def
numpySum(n):
a
=
py.arange(n)
b
=
py.arange(
0
,
5
*
n,
5
)
c
=
a
*
*
2
+
b
*
*
3
return
c
now1
=
datetime.now()
print
(listSum(
1000000
))
now2
=
datetime.now()
print
(now2
-
now1)
now3
=
datetime.now()
print
(numpySum(
1000000
))
now4
=
datetime.now()
print
(now4
-
now3)
以上是关于numpy的主要内容,如果未能解决你的问题,请参考以下文章