numpy例题
1、创建一个8x8 的矩阵,并且设置成棋盘样式
import numpy as np
Z = np.zeros((8,8),dtype=int)
Z[1::2,::2] = 1
Z[::2,1::2] = 1
Z
array([[0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0]])
2、将一维数组转换成2行的2D数组.
arr = np.arange(10)
res = np.reshape(arr,(2,5))
arr,res
(array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
array([[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9]]))
3、获取A和B之间的公共项
a = np.array([1,2,3,2,3,4,3,4,5,6])
b = np.array([7,2,10,2,7,4,9,4,9,8])
res = np.intersect1d(a,b)
res
array([2, 4])
pandas库例
1、创建一个DataFrame(df),用data做数据,labels做行索引
import numpy as np
data = {'animal': ['cat', 'cat', 'snake', 'dog', 'dog', 'cat', 'snake', 'cat', 'dog', 'dog'],
'age': [2.5, 3, 0.5, np.nan, 5, 2, 4.5, np.nan, 7, 3],
'visits': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'priority': ['yes', 'yes', 'no', 'yes', 'no', 'no', 'no', 'yes', 'no', 'no']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
df = pd.DataFrame(data=data, index=labels)
df
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
2、显示有关此df及其数据的基本信息的摘要
df.describe()
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
3、选择行为[3, 4, 8],且列为['animal', 'age']中的数据
df.iloc[[3, 4, 8]].loc[:, ['animal', 'age']]
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
matplotlib例题
1、用plot方法画出x=(0,10)间sin的图像
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 30)
plt.plot(x, np.sin(x));
![](https://img-blog.csdnimg.cn/img_convert/b3a60a8c3e4ccc91131f0059583b3a09.png)
2、用点加线的方式画出x=(0,10)间sin的图像
plt.plot(x, np.sin(x), '-o');
![](https://img-blog.csdnimg.cn/img_convert/e80ebbef2667235a5026d970d542694d.png)
3、用饼图的面积及颜色展示一组4维数据
rng = np.random.RandomState(0)
x = rng.randn(100)
y = rng.randn(100)
colors = rng.rand(100)
sizes = 1000 * rng.rand(100)
plt.scatter(x, y, c=colors, s=sizes, alpha=0.3,
cmap='viridis')
plt.colorbar();
![](https://img-blog.csdnimg.cn/img_convert/b9597c39836819b4fb3478770cb417db.png)
什么是图灵测试?
图灵测试(Turing Test)是一种测试人工智能是否具有智能的标准。这个测试的理论基础是由英国数学家艾伦·图灵(Alan Turing)于1950年提出的,被认为是人工智能领域的里程碑。
在图灵测试中,一名评判与一台机器进行对话,如果评判无法区分机器的回答与人类的回答,那么这台机器就被认为通过了图灵测试,具备了人类的智能。
图灵测试的目的是检验机器是否具备“智能”,而不是测试机器的功能或表现。图灵测试的实际应用比较有限,但它提出的问题在人工智能领域至今仍是一个热门话题,同时也是人们思考和探讨人工智能边界的重要参考。