Python学习(包含:模块,推导式,数据库,矩阵的创建,索引和切片等)

#coding:utf-8
import datetime
class My_Util():

    @classmethod
    def toTime(cls):
        print(datetime.date(2018,7,27))


if __name__=="__main__":
    My_Util.toTime()

————————————————————————————————————————————————————————

#coding:utf-8
import  math
import datetime
# 模块名字.函数或者类
# math.sqrt()


from os import path as mypath
# from os import *

# 类名.函数
mypath.isfile("")
# listdir("目录")

import my__module

my__module.My_Util.toTime()

——————————————————————————————————————————————————————

#coding:utf-8
list1 = [1 for x in range(0,10)  ]

list1 = [ [x,y] for x in range(0,10) for y in range(1,4)]

list1 =[x for x in range(1,100) if x%2==1 ]

list1 =[ [x-2,x-1,x] for x in range(1,100) if x%3==0]
print(list1)

——————————————————————————————————————————————————————

#coding:utf-8
import pymysql

conn =pymysql.connect("127.0.0.1","root","123123","test",3306)
# pymysql.connect(host="localhost",port=3306)

c= conn.cursor()
# c.execute("select count(*) from emp")
c.execute("select * from emp where sal > %d"%2500)
print(c.fetchall())
conn.close()

——————————————————————————————————————————————————

#coding:utf-8
import numpy as np

# 第一种
# arr=[[1,2,3],[4,5,6]]
# a = np.array(arr)
# print(a.shape)
# print(a.ndim)
# print(a.dtype)

#第二种  向量== [1,2,3,4]
a =np.arange(1,17).reshape((2,2,2,2))
# a= np.random.randint(0,10,16).reshape((2,2,2,2))
# a =np.random.randn(9) # 随机生成一个正态分布的数列
# print(a)
# print(a)
print(a[1][0][0][1])
print(a[1,0,0,1])
# 第三种
a= np.zeros((3,3))
a= np.ones((3,3))
a=np.empty((3,3)) # None
# print(a)

————————————————————————————————————————————————————

#coding:utf-8
import numpy as np

a =np.random.randint(0,10,(4,5))
print(a)
print("-"*30)
#  第三行第三列
# print(a[2,2])
#第二行,前三列
print(a[1,:3])
# 第一,三,四行的前三列
print(a[[0,2,3],:3])
# 中间两行的后三列
print(a[1:3,-3:])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值