当前位置:网站首页>6.23星期四库作业
6.23星期四库作业
2022-07-03 05:16:00 【隹隹隹隹隹】
6.23星期四库作业
文章目录
Numpy实践
练习一:创建从0到9的一维数字数组
import numpy as np
arr = np.arange(10)
print(arr)
练习二:创建一个元素全为True
的 3×3 数组
import numpy as np
arr = np.full([3, 3], True, dtype=np.bool)
print(arr)
练习三:创建一个二维数组,其中边界值为1,其余值为0
import numpy as np
Z = np.ones((10,10))
Z[1:-1,1:-1] = 0
print(Z)
Pandas实践
练习一:利用列表推导式写矩阵乘法
一般的矩阵乘法根据公式,可以由三重循环写出,请将其改写为列表推导式的形式。
M1 = np.random.rand(2,3)
M2 = np.random.rand(3,4)
res = np.empty((M1.shape[0],M2.shape[1]))
for i in range(M1.shape[0]):
for j in range(M2.shape[1]):
item = 0
for k in range(M1.shape[1]):
item += M1[i][k] * M2[k][j]
res[i][j] = item
(np.abs(([email protected] - res) < 1e-15)).all() # 排除数值误差
列表推导式的形式
import numpy as np
M1 = np.random.rand(2,3)
M2 = np.random.rand(3,4)
res = [[sum([M1[i][k] * M2[k][j] for k in range(M1.shape[1])]) for j in range(M2.shape[1])] for i in range(M1.shape[0])]
(np.abs(([email protected] - res) < 1e-15)).all()
Matplotlib实践
练习一: 两种绘图接口
matplotlib提供了两种最常用的绘图接口
- 显式创建figure和axes,在上面调用绘图方法,也被称为OO模式(object-oriented style)
- 依赖pyplot自动创建figure和axes,并绘图
使用第一种绘图接口,是这样的:
x = np.linspace(0, 2, 100)
fig, ax = plt.subplots()
ax.plot(x, x, label='linear')
ax.plot(x, x**2, label='quadratic')
ax.plot(x, x**3, label='cubic')
ax.set_xlabel('x label')
ax.set_ylabel('y label')
ax.set_title("Simple Plot")
ax.legend()
第二种绘图接口
x = np.linspace(0, 2, 100)
plt.plot(x, x, label='linear')
plt.plot(x, x**2, label='quadratic')
plt.plot(x, x**3, label='cubic')
plt.xlabel('x label')
plt.ylabel('y label')
plt.title("Simple Plot")
plt.legend()
边栏推荐
- [research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached
- Celebrate the new year together
- Yolov5 input (II) | CSDN creative punch in
- Web APIs exclusivity
- [set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)
- [develop wechat applet local storage with uni app]
- 编译GCC遇到的“pthread.h” not found问题
- Interview question -- output the same characters in two character arrays
- XML Configuration File
- [batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)
猜你喜欢
[research materials] 2021 China's game industry brand report - Download attached
How to connect the network: Chapter 1 CSDN creation punch in
Detailed explanation of yolov5 training own data set
Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
Oracle SQL table data loss
The consumption of Internet of things users is only 76 cents, and the price has become the biggest obstacle to the promotion of 5g industrial interconnection
Shallow and first code
leetcode860. Lemonade change
(subplots用法)matplotlib如何绘制多个子图(轴域)
Principles of BTC cryptography
随机推荐
112 stucked keyboard (20 points)
[backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
Oracle SQL table data loss
appium1.22.x 版本后的 appium inspector 需单独安装
1103 integer factorization (30 points)
【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)
Redis 过期淘汰机制
study hard and make progress every day
聊聊如何利用p6spy进行sql监控
Pessimistic lock and optimistic lock of multithreading
Introduction to webrtc protocol -- an article to understand dtls, SRTP, srtcp
Yolov5 input (II) | CSDN creative punch in
Why is go language particularly popular in China
谷歌 | 蛋白序列的深度嵌入和比对
Shuttle + alluxio accelerated memory shuffle take-off
穀歌 | 蛋白序列的深度嵌入和比對
leetcode435. Non overlapping interval
[develop wechat applet local storage with uni app]
Congratulations to musk and NADELLA on their election as academicians of the American Academy of engineering, and Zhang Hongjiang and Fang daining on their election as foreign academicians
Source insight garbled code solution