numpy、pandas、matplotlib

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));

2、用点加线的方式画出x=(0,10)间sin的图像

plt.plot(x, np.sin(x), '-o');

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();

什么是图灵测试?

图灵测试(Turing Test)是一种测试人工智能是否具有智能的标准。这个测试的理论基础是由英国数学家艾伦·图灵(Alan Turing)于1950年提出的,被认为是人工智能领域的里程碑。

在图灵测试中,一名评判与一台机器进行对话,如果评判无法区分机器的回答与人类的回答,那么这台机器就被认为通过了图灵测试,具备了人类的智能。

图灵测试的目的是检验机器是否具备“智能”,而不是测试机器的功能或表现。图灵测试的实际应用比较有限,但它提出的问题在人工智能领域至今仍是一个热门话题,同时也是人们思考和探讨人工智能边界的重要参考。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值