ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

流水账第四章

2021-07-19 21:59:06  阅读:162  来源: 互联网

标签:流水账 plt print score np array True 第四章


学习Numpy

import numpy as np
score = np.array([[80,80,76,56,56],
                 [53,65,54,78,97],
                 [76,44,24,97,56],
                 [21,64,34,74,34],
                 [12,42,12,42,35]])
a = score.shape  #形状:(5,5) 其中()代表元组 里面几个数字代表几维度
b = score.ndim  #维度
c = score.size  #几个元素
d = score.dtype #类型 创建ndarray的时候,如果没有指定类型,整数时默认"int64",小数为"float64"
f = score.itemsize  #每个元素占用字节
print(a,b,c,d,f)

array_1 = np.array([1,2,3,4])  #一维
array_2 = np.array([[[1,2,3],
                     [4,5,6]],

                    [[1,2,3],
                     [4,5,6]]])  #三维 (三个中括号) 维度表示方法(嵌套两个二维元素,二维数字几行,几列)即(2,2,3)
print(array_2.shape)

#均匀分布

import matplotlib.pyplot as plt
x1 = np.random.uniform(-1,1,1000000)
plt.figure(figsize = (20,8), dpi = 80)
plt.hist(x1,1000)
plt.show()

#正态分布 

#正态分布
x2 = np.random.normal(loc = 0, scale = 1, size = 1000000)
plt.figure(figsize = (20,8), dpi = 80)
plt.hist(x2,1000)
plt.show()

 

 

import numpy as np
x = np.random.normal(0,1,(8,10))
print(x)

#布尔索引 统一操作
x[x>0.5]=1
print(x>0) #返回True

#判断
a = x[0:2, 0:5]>0#返回True/False 判断前2组的前5哥
b = np.all(x[0:2, 0:5]>0)  #全True才返回True
c = np.any(x[0:2, 0:5]>0)  #有一个True返回True
print(a,b,c)

#np.where
temp = x[:4,:4]             #取前四组的前4天
print("temp=",temp)
d = np.where(temp>0, 1, 0)  #将 大于0的置1,否则为0
print("d=",d)

#逻辑关系 且and/或or
f = np.logical_and(temp>0,temp<1)  #选取temp>0且<1的数据
g = np.where(f,1,0)                #将temp>0且<1置1,否则为0
print("g=",g)
#同理 np.logical_or

#统计运算
max_temp = temp.max(axis=1)  #axis=1每组行中的元素 axis=0为列中的元素 建议测试便知
#等价max_temp = np.max(temp, axis=1) ,以下同理
loc_temp = temp.argmax(axis=1) #显示每行最大元素的位置 0为起始
print("max_temp=",max_temp)
print("loc_temp=",loc_temp)

标签:流水账,plt,print,score,np,array,True,第四章
来源: https://blog.csdn.net/slowly_climb/article/details/118895699

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有