金点网络-全网资源,一网打尽
  • 网站首页
    • 金点部落
    • 小游戏
    • OpenAPI
    • 设计资产导航
    • 升级会员
  • 技能学习
    • 体育运动
    • 办公教程
    • 口才演讲
    • 小吃技术
    • 建站教程
    • 摄影教程
    • 棋牌教程
    • 网赚教程
      • 爆粉引流
      • 自媒体
      • 贴吧引流
  • 网站源码
    • 商城/淘客/交易
    • 小说/漫画/阅读
    • 影视/音乐/视频
    • 微信/微商/微擎
    • 理财/金融/货币
    • 模板/主题/插件
  • 游戏源码
    • 精品网单
    • 端游源码
    • 手游源码
    • 页游源码
  • 素材资料
    • 电子文档
    • 综合资料
    • 考研资料
    • 设计素材
    • 音频讲座
      • 人文艺术
      • 名师讲座
      • 说书小说
  • 软件工具
    • Windows软件
    • MacOS软件
    • Android软件
  • 寄售资源
    • 游戏源码
    • 网站源码
    • 软件源码
  • 公益服
登录/注册
  • 专享大神特权
立即开通开通会员抄底价

Python数据分析(中英对照)·Slicing NumPy Arrays 切片 NumPy 数组

作者 : jamin 本文共4366个字,预计阅读时间需要11分钟 发布时间: 2020-10-18 共1498人阅读

2.2.2: Slicing NumPy Arrays 切片 NumPy 数组

It’s easy to index and slice NumPy arrays regardless of their dimension,meaning whether they are vectors or matrices.
索引和切片NumPy数组很容易,不管它们的维数如何,也就是说它们是向量还是矩阵。
With one-dimension arrays, we can index a given element by its position, keeping in mind that indices start at 0.
使用一维数组,我们可以根据给定元素的位置对其进行索引,记住索引从0开始。
With two-dimensional arrays, the first index specifies the row of the array and the second index
对于二维数组,第一个索引指定数组的行,第二个索引指定行
specifies the column of the array.
指定数组的列。
This is exactly the way we would index elements of a matrix in linear algebra.
这正是我们在线性代数中索引矩阵元素的方法。
We can also slice NumPy arrays.
我们还可以切片NumPy数组。
Remember the indexing logic.
记住索引逻辑。
Start index is included but stop index is not,meaning that Python stops before it hits the stop index.
包含开始索引,但不包含停止索引,这意味着Python在到达停止索引之前停止。
NumPy arrays can have more dimensions than one of two.
NumPy数组的维度可以多于两个数组中的一个。
For example, you could have three or four dimensional arrays.
例如,可以有三维或四维数组。
With multi-dimensional arrays, you can use the colon character in place of a fixed value for an index, which means that the array elements corresponding to all values of that particular index will be returned.
对于多维数组,可以使用冒号字符代替索引的固定值,这意味着将返回与该特定索引的所有值对应的数组元素。
For a two-dimensional array, using just one index returns the given row which is consistent with the construction of 2D arrays as lists of lists, where the inner lists correspond to the rows of the array.
对于二维数组,只使用一个索引返回给定的行,该行与二维数组作为列表的构造一致,其中内部列表对应于数组的行。
Let’s then do some practice.
然后让我们做一些练习。
I’m first going to define two one-dimensional arrays,called lower case x and lower case y.
我首先要定义两个一维数组,叫做小写x和小写y。
And I’m also going to define two two-dimensional arrays,and I’m going to denote them with capital X and capital Y. Let’s first see how we would access a single element of the array.
我还将定义两个二维数组,我将用大写字母X和大写字母Y表示它们。让我们先看看如何访问数组中的单个元素。
So just typing x square bracket 2 gives me the element located at position 2 of x.
所以只要输入x方括号2,就得到了位于x的位置2的元素。
I can also do slicing.
我也会做切片。
So I can specify the start index and the end index, in which case I get two elements here from the x array, the numbers 1 and 2.
所以我可以指定开始索引和结束索引,在这种情况下,我从x数组中得到两个元素,数字1和2。
If you look at the sizes of x and y, each of them has exactly three elements.
如果你看x和y的大小,它们都有三个元素。
That means that we can add those two arrays up.
这意味着我们可以将这两个数组相加。
So I can type x plus y, which gives me a new array called z.
所以我可以输入x加y,这给了我一个新的数组,称为z。
In this case, the elements of z will be element-wise additions from the vectors x and y.
在这种情况下,z的元素将是向量x和y的元素相加。
So the first element of x is added to the first element of y, and so on.
因此,x的第一个元素被添加到y的第一个元素,依此类推。
Now moving on to two-dimensional arrays,we can also investigate individual rows or columns of arrays.
现在转到二维数组,我们还可以研究数组的单个行或列。
Typing X square bracket colon comma 1 gives me access to the first column of the table X. I can do the same for Y,and now I have to first column of the two-dimensional array, Y.
键入X方括号冒号逗号1可以访问表X的第一列。我可以对Y执行相同的操作,现在我必须访问二维数组的第一列Y。
I can also add these two up.
我也可以把这两个加起来。
So I can type X plus Y, again colon comma 1.
所以我可以输入X加Y,再次输入冒号逗号1。
In this case, I have added together the first columns of these two arrays.
在本例中,我将这两个数组的前几列相加。
To extract the first row of X, I type, within square brackets,1 comma colon which gives me all of the elements in the first row.
要提取X的第一行,我在方括号内键入1个逗号冒号,它将给出第一行中的所有元素。
In this case, these are numbers 4, 5, and 6.
在本例中,这些是数字4、5和6。
I can take also the first row of Y, and I can then add these two arrays up.
我也可以取Y的第一行,然后我可以把这两个数组相加。
Because two-dimensional arrays are defined as nested rows,I can use a shorthand notation to access the first row of X, which in this case
因为二维数组被定义为嵌套行,所以我可以使用简写符号来访问X的第一行,在本例中是这样的
would be just X square brackets 1, and this gives me the same exact output as typing X square bracket 1 comma colon.
将是X方括号1,这给了我与键入X方括号1逗号冒号相同的精确输出。
One word of caution — what happens if we take two lists and put a plus sign between them?
警告一句——如果我们拿两个列表并在它们之间加一个加号,会发生什么?
Well, we can give it a try.
嗯,我们可以试一试。
I can define a list which consists of elements 2 and 4.
我可以定义一个由元素2和4组成的列表。
I have a plus sign followed by another list with elements 6 and 8.
我有一个加号,后面是另一个包含元素6和8的列表。
Remember, putting a plus sign between two lists concatenates those two lists, resulting in a new list which is longer than the two lists that were added together.
请记住,在两个列表之间放置加号将连接这两个列表,从而生成一个新列表,该列表比添加在一起的两个列表长。
Now let’s look at a different example.
现在让我们看一个不同的例子。
What happens if we first turn those lists into NumPy arrays,and then have a plus sign between them?
如果我们首先将这些列表转换为NumPy数组,然后在它们之间加上一个加号,会发生什么?
I’m going to take my previous line here.
我将在这里接受我的前一行。
I’ll just turn this into a NumPy array.
我会把它变成一个小数组。
So my first NumPy array has two elements, 2 and 4.
所以我的第一个NumPy数组有两个元素,2和4。
I’m going to add that to another NumPy array, which has elements 6 and 8.
我将把它添加到另一个NumPy数组中,它包含元素6和8。
In this case, what’s happening is we have two one-dimensional arrays.
在这种情况下,我们有两个一维数组。
And what we’ve accomplished here is an element-wise addition between these two arrays.
我们在这里完成的是这两个数组之间的元素加法。

Python 数据分析
本站所提供的部分资源来自于网络,版权争议与本站无关,版权归原创者所有!仅限用于学习和研究目的,不得将上述内容资源用于商业或者非法用途,否则,一切后果请用户自负。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容资源。如果上述内容资对您的版权或者利益造成损害,请提供相应的资质证明,我们将于3个工作日内予以删除。本站不保证所提供下载的资源的准确性、安全性和完整性,源码仅供下载学习之用!如用于商业或者非法用途,与本站无关,一切后果请用户自负!本站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。如有侵权、不妥之处,请联系站长以便删除!
金点网络-全网资源,一网打尽 » Python数据分析(中英对照)·Slicing NumPy Arrays 切片 NumPy 数组

常见问题FAQ

免费下载或者VIP会员专享资源能否直接商用?
本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
是否提供免费更新服务?
持续更新,永久免费
是否经过安全检测?
安全无毒,放心食用
jamin

jamin 大神

下一篇
网络协议-组播介绍

相关推荐

Python数据分析(中英对照)·Using the NumPy Random Module 使用 NumPy 随机模块

Python数据分析(中英对照)·Using the NumPy Random Module 使用 NumPy 随机模块

Python数据分析(中英对照)·Sets 集合

Python数据分析(中英对照)·Sets 集合

Python数据分析(中英对照)·Indexing NumPy Arrays 索引 NumPy 数组

Python数据分析(中英对照)·Indexing NumPy Arrays 索引 NumPy 数组

Python数据分析(中英对照)·Introduction to Matplotlib and Pyplot-Matplotlib 和 Pyplot 介绍

Python数据分析(中英对照)·Introduction to Matplotlib and Pyplot-Matplotlib 和 Pyplot 介绍

Python数据分析(中英对照)·Strings 字符串

Python数据分析(中英对照)·Strings 字符串

标签云
Android Atom ExecutorService ForkJoin GM GM后台 GM授权后台 H5 Java Javascript Linux手工服务端 pipbestcom Python ReentrantLock synchronized ThreadLocal volatile Win一键即玩服务端 一键端 传奇 写作 创业 单机 后台 商业端 外网 安卓 安卓苹果双端 工具 手工端 手游 搭建教程 教程 数据分析 文案 游戏源码 端游 经典 网单 职场 自媒体 视频教程 详细搭建教程 运营后台 页游

近期文章

  • 回合手游【逍遥西游之繁华西游】最新整理单机一键既玩镜像服务端_Linux手工端_GM后台_教程
  • 最新整理精品回合制手游【天书奇谈3D混沌完整版】VM一键单机版_linux手工外网端_隐盟视频教程_授权GM后台_双端
  • 典藏修真页游【诸仙列传OL】最新整理Win系服务端_GM工具_详细外网搭建教程
  • MT3换皮MH【浮生若梦尊享挂机修复版】最新整理单机一键即玩镜像端_Linux手工服务端_安卓苹果双端_GM后台_详细搭建教程
  • 大话回合手游【最新引擎之缥缈西游渡劫版】最新整理Linux手工服务端_安卓苹果双端_管理后台_CDK后台_详细搭建教程_视频教程

分类

  • | wordpress插件 |
  • | wordpress模板 |
  • | 其它模板 |
  • | 帝国模板 |
  • | 织梦插件 |
  • | 织梦模板 |
  • A5源码
  • Android软件
  • APP引流
  • E语言
  • H5
  • LUA
  • QQ营销
  • SEO推广
  • Windows软件
  • 体育运动
  • 信息数据
  • 创业专题
  • 办公教程
  • 口才演讲
  • 名师讲座
  • 商城/淘客/交易
  • 小吃技术
  • 小说/漫画/阅读
  • 建站教程
  • 引流脚本
  • 影视/音乐/视频
  • 影视资源
  • 微信/微商/微擎
  • 微信小程序
  • 微信营销
  • 微擎模块
  • 手游源码
  • 技能学习
  • 抖音课程
  • 摄影教程
  • 棋牌教程
  • 模板/主题/插件
  • 游戏源码
  • 爆粉引流
  • 理财/金融/货币
  • 生活老师
  • 电商客
  • 电子文档
  • 电脑教程
  • 社群营销
  • 站长工具
  • 精品网单
  • 系统工具
  • 素材资料
  • 综合资料
  • 编程经验
  • 网站源码
  • 网络安全
  • 网赚教程
  • 网赚源码
  • 考研资料
  • 脚本/AI/智能
  • 自媒体
  • 英语学习
  • 营销软件
  • 设计素材
  • 说书小说
  • 贴吧引流
  • 软件工具
  • 软文营销
  • 逆向软件
  • 音频讲座
  • 页游源码

提供最优质的资源集合

立即加入 友好社区
金点网络-全网资源,一网打尽

新一代全网资源综合门户网(www.pipbest.com-金点网络)专注服务于互联网,提供各类最新最全的免费源码下载(PHP、ASP、JSP、.NET),更提供免费工具,免费源码下载,软件下载,素材下载,赚钱教程下载,交流论坛等网站运营相关的一切内容,为网友搜罗最有价值的网站源码下载与技术教程等服务!

服务目录
  • 金点OpenAPI
  • 金点云
  • 金点支付
友情链接
  • 数媒派
  • 国家电网
快速搜索

本站由Nice强力驱动

声明: 本站部分内容属于原创转载请注明出处 如有侵权行为请严格参照本站【版权声明】与我们联系,我们将在48小时内容进行处理!

本站部分内容属于原创转载请注明出处 如有侵权行为请严格参照本站【版权声明】与我们联系,我们将在48小时内容进行处理!
© 2016-2023 PipBest.Com - 金点网络 & 金点部落. All rights reserved 京ICP备2022005359号-1
  • 关注有礼
  • 签到
  • 客服
    官方QQ群 常见问题 FAQ

    在线客服

    点我联系

    直接说出您的需求!
    切记!带上资源连接与问题!

    工作时间: 9:30-21:30

  • 暗黑
    模式
  • 全屏
  • 投稿
    赚钱
  • 首页

  • 签到

  • 切换

  • 客服

金点网络-全网资源,一网打尽
  • 登录
  • 注册
or
or
忘记密码?
金点网络-全网资源,一网打尽
  • 网站首页 ►
    • 金点部落
    • 小游戏
    • OpenAPI
    • 设计资产导航
    • 升级会员
  • 技能学习 ►
    • 体育运动
    • 办公教程
    • 口才演讲
    • 小吃技术
    • 建站教程
    • 摄影教程
    • 棋牌教程
    • 网赚教程 ►
      • 爆粉引流
      • 自媒体
      • 贴吧引流
  • 网站源码 ►
    • 商城/淘客/交易
    • 小说/漫画/阅读
    • 影视/音乐/视频
    • 微信/微商/微擎
    • 理财/金融/货币
    • 模板/主题/插件
  • 游戏源码 ►
    • 精品网单
    • 端游源码
    • 手游源码
    • 页游源码
  • 素材资料 ►
    • 电子文档
    • 综合资料
    • 考研资料
    • 设计素材
    • 音频讲座 ►
      • 人文艺术
      • 名师讲座
      • 说书小说
  • 软件工具 ►
    • Windows软件
    • MacOS软件
    • Android软件
  • 寄售资源
    ►
    • 游戏源码
    • 网站源码
    • 软件源码
  • 公益服
×
u3** 刚刚下载了 爆款吸金文案训练

    全网资源·一网打尽

  • 金点出品,必属精品!
  • 发布原创内容,获取高额提成!
  • 我们与你共创美好数字生态!
  • 无特殊说明密码默认:pipbest.com