栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

numpy与普通python不同的地方是什么?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

numpy与普通python不同的地方是什么?

对我而言,最大的难题是几乎每个标准运算符都超载,无法在整个阵列中分布。

定义一个列表和一个数组

>>> l = range(10)>>> l[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> import numpy>>> a = numpy.array(l)>>> aarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

乘法复制python列表,但分布在numpy数组上

>>> l * 2[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> a * 2array([ 0,  2,  4,  6,  8, 10, 12, 14, 16, 18])

未在python列表上定义加法和除法

>>> l + 2Traceback (most recent call last):  File "<stdin>", line 1, in <module>TypeError: can only concatenate list (not "int") to list>>> a + 2array([ 2,  3,  4,  5,  6,  7,  8,  9, 10, 11])>>> l / 2.0Traceback (most recent call last):  File "<stdin>", line 1, in <module>TypeError: unsupported operand type(s) for /: 'list' and 'float'>>> a / 2.0array([ 0. ,  0.5,  1. ,  1.5,  2. ,  2.5,  3. ,  3.5,  4. ,  4.5])

numpy重载有时将列表视为数组

>>> a + aarray([ 0,  2,  4,  6,  8, 10, 12, 14, 16, 18])>>> a + larray([ 0,  2,  4,  6,  8, 10, 12, 14, 16, 18])


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/441141.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号