一枚老猿的Python学习随笔(2)
本想边学习,边笔记整理,学了一天发现简单跟随一个教程太单一,随学随记吧。
PS:发现发布文章,还有markdown模板还可以,嵌入HTML,看来离开程序界太久了~~ 目录
- 一枚老猿的Python学习随笔(2)
- 1、学习小结
- 2、安装NumPy
- 3、NumPy小试
- 4、贴段代码
- 5、研究Python的另一个原因
- 补充
1、学习小结
昨天在Windows10下安装了Python的开发环境,今天换了电脑,Windows7环境下安装,遇到了Server pack 1 一个升级包的问题:安装log 提示 缺少 KB2533625——ms 原有连接已经失效,着实找了一番(已上传)。
PS:Windows7 下可以选择python3.8版本
再认识Python
今天@2020.10.31
浏览了Python的简单教程,了解了:Python的数字、字符串、布尔、运算符、列表、集合、字典、数组概念、日期、Json、正则,测试了函数、Lambda,Python的分支、循环,类/对象、继承、迭代以及Python的错误处理机制,顺便试了试简单的文件读写。
总体感觉,Python语法简练,各种写法支持的很好。
接下来,研究下NumPy,NumPy就说是访问内存连续地址空间,同时硬件优化是Python内置数据处理速度的50倍,所以决定试一试。
2、安装NumPy
Python3.4开始,集成了pip(Python包管理工具)。
命令行,进入Python目录下:…\Python\Python38\ Scripts目录
C:\Users\Admin>d:
D:\>cd D:\Users\admin\AppData\Local\Programs\Python\Python38\Scripts
D:\Users\Admin\AppData\Local\Programs\Python\Python38\Scripts>pip install numpy
安装成功,测试是否OK:
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr)
Python 3.9版本有点高,改装了3.8.6!!!
3、NumPy小试
Numpy包封装了丰富的数据处理方法…
……好多好多细分功能函数...... 需要调用就好了
4、贴段代码
测试代码
import sys
import numpy as np
import matplotlib.pyplot as plt
import requests,pymongox = requests.get('https://w3school.com.cn/python/demopage.htm')rtext = x.text[::-1]print(rtext)exec('print("a"+str(100))')sys.exit(1)
x = [1,2,3,5,6,7,8,9,10,12,13,14,15,16,18,19,21,22]
y = [100,90,80,60,60,55,60,65,70,70,75,76,78,79,90,99,99,100]mymodel = np.poly1d(np.polyfit(x, y, 3))myline = np.linspace(1, 22, 100)plt.scatter(x, y)
plt.plot(myline, mymodel(myline))
plt.show()x = np.random.uniform(0.0, 5.0, 250)plt.hist(x, 5)
plt.show()"""
arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12])
newarr = arr.reshape(24,-1)
print("arrshap:"+str(arr.shape))
print(arr)
print("=====================================")
print("newarrshap:"+str(newarr.shape))
print(newarr)
print(newarr.reshape(-1))arr1 = np.array([1, 2, 3])arr2 = np.array([4, 5, 6])arr = np.dstack((arr1, arr2))print(arr)
"""x = np.random.uniform(0.0, 5.0, 50001088)
print("Count:"+str(len(x)))
print(x[3333])sys.exit(0)print("Hello, World! ——Python")
if 5-3 == 2:print("YES!")if 5 - 2== 3:print("NO!!")
print("也可单行后半部分注释")
"""
块注释"""
x = y = z = 10
print(x,y,z)
x,y,z = 1,2,3
print(x,y,z)
x,y,z = 1,10,"v_x"
x +=2
z += "_var"
print(x,y,z)
print("=================")
def funcA():x = 100print(x)
funcA()
print(x)x=3
print(x)
def funcB():global xx = 100print(x)
funcB()
print(x) x,y,z = 12.5,12.80,"string"
if type(x) == int:int("x:"+str(type(x)))
else:print(type(x))x = int(12.9)
print(x)
x = str(12.3)
print(x +"kg")x = list(("Python", "GoLang", "Java"))
print(x)x = 123.1
if type(x) == int:y = int(x)
print("sssss")print(y)
y = 0
x = 5
if x > 10:y = int(x)y += 3print("A" + str(y))if x > 10: y = int(x)
y += 3
print("B" + str(y))print(bool(-2))class myclass():def __len__(self):return 10myobj = myclass()
print(bool(myobj))print(isinstance("asdf",int))x = 1
y = 11
print(1 in [1,2])""" 奇怪的for循环
s = ("a,b,c,d").split(",")
print(s)
if len(s) > 0:for x1 in s:print(x1)s.remove(x1)
"""
s = """
"""
print("s:")
s = list(s)
print(s)thisset = {"apple", "banana", "cherry"}x = thisset.pop()print(x)print(thisset)thisdict = {"brand": "Porsche", "brand1": "Porsche","model": "911","year": 1963
}
thisdict["year"] = 2019
print(thisdict)
x =8
if int(x) > 1: print("x>1")
print("a") if x>1 else print("b")i = 0
while i<&#61;10:print(i)i &#43;&#61;1
else:print(i)print("else")for x in "banana":print(x)
for x in range(100,201,2):print(x)
else:print("for end")adj &#61; ["red", "big", "tasty"]
fruits &#61; ["apple", "banana", "cherry"]for x in adj:for y in fruits:print(x, y)
5、研究Python的另一个原因
——今日接到多个了推广Python培训的营销电话&#xff0c;小学生定向营销&#xff0c;真是为了挣钱没有底线&#xff0c;孩子们能理解程序吗——或许部分天才可以&#xff0c;个人认为学好基础文化科才是正道。
接下来系统研究 Go Lang 开发。
补充
2020-11-23
不能白学&#xff0c;用Python写了数据生成&#xff1a;区分大小写的序列数据&#xff0c;运行效率还可以&#xff0c;谁能看出这个有啥用&#xff1f;
import sys
import numpy as np
from numpy import random
"""
生成 Codes 数据&#xff0c;数据由
62个元素[0-9,a-z,A-Z]
n位无重复组合
"""ods &#61; (&#39;0&#39;, &#39;1&#39;, &#39;2&#39;, &#39;3&#39;, &#39;4&#39;, &#39;5&#39;, &#39;6&#39;, &#39;7&#39;, &#39;8&#39;, &#39;9&#39;, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;f&#39;, &#39;g&#39;, &#39;h&#39;, &#39;i&#39;, &#39;j&#39;, &#39;k&#39;, &#39;l&#39;, &#39;m&#39;, &#39;n&#39;, &#39;o&#39;, &#39;p&#39;, &#39;q&#39;, &#39;r&#39;, &#39;s&#39;, &#39;t&#39;, &#39;u&#39;, &#39;v&#39;, &#39;w&#39;, &#39;x&#39;, &#39;y&#39;, &#39;z&#39;, &#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;, &#39;F&#39;, &#39;G&#39;, &#39;H&#39;, &#39;I&#39;, &#39;J&#39;, &#39;K&#39;, &#39;L&#39;, &#39;M&#39;, &#39;N&#39;, &#39;O&#39;, &#39;P&#39;, &#39;Q&#39;, &#39;R&#39;, &#39;S&#39;, &#39;T&#39;, &#39;U&#39;, &#39;V&#39;, &#39;W&#39;, &#39;X&#39;, &#39;Y&#39;, &#39;Z&#39;)
"""
for i in range(ord("0"), ord("9")&#43;1):ods &#61; ods &#43; [chr(i)]for i in range(ord("a"), ord("z")&#43;1):ods &#61; ods &#43; [chr(i)]for i in range(ord("A"), ord("Z")&#43;1):ods &#61; ods &#43; [chr(i)]
"""
ods_len &#61; len(ods)print("ord_len:" &#43; str(ods_len))
print(ods)f &#61; open("f.dat","w")
c1&#61;c2&#61;c3&#61;c4 &#61; ""
for t1 in range(60,ods_len):c1 &#61; ods[t1]for t2 in range(60,ods_len):c2 &#61; ods[t2]for t3 in range(60,ods_len):c3 &#61; ods[t3]for t4 in range(60,ods_len):c4 &#61; ods[t4]c &#61; c1&#43;c2&#43;c3&#43;c4f.write(str(random.rand())&#43;","&#43;c&#43;"\n")f.close()