首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Python数据分析(中英对照)·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

02

索引优先队列-IndexedPrirotyQueue的原理及实现(源码)

1.索引优先队列的意义 索引优先队列是一个比较抽象的概念,它是一个优先队列,又带有索引,这个索引是用来干什么的呢? 在正常的队列中,我们只能访问队列头元素,整个队列中的元素我们都无法访问。那么对于这些队列中的元素,如果我们有一个映射,能够知道队列中的第m个元素到底对应我们把所有元素加入优先队列之前的哪一个,那要使用它岂不是方便许多? 我们知道,在优先队列中,一个元素加入队列之后的顺序不是固定的,有可能上浮或者下沉。那么,我们怎么知道我们加入队列的这个元素,到底在队列中的什么位置呢? 这就是索引优先队列的用途

09

tf.train.batch

在张量中创建多个张量。参数张量可以是张量的列表或字典。函数返回的值与张量的类型相同。这个函数是使用队列实现的。队列的QueueRunner被添加到当前图的QUEUE_RUNNER集合中。 如果enqueue_many为False,则假定张量表示单个示例。一个形状为[x, y, z]的输入张量将作为一个形状为[batch_size, x, y, z]的张量输出。如果enqueue_many为真,则假定张量表示一批实例,其中第一个维度由实例索引,并且张量的所有成员在第一个维度中的大小应该相同。如果一个输入张量是shape [*, x, y, z],那么输出就是shape [batch_size, x, y, z]。容量参数控制允许预取多长时间来增长队列。返回的操作是一个dequeue操作,将抛出tf.errors。如果输入队列已耗尽,则OutOfRangeError。如果该操作正在提供另一个输入队列,则其队列运行器将捕获此异常,但是,如果在主线程中使用该操作,则由您自己负责捕获此异常。

01
领券