numpy的不规则跨进阵列 [英] numpy irregularly strided array

查看:520
本文介绍了numpy的不规则跨进阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引述<一个href=\"http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html#internal-memory-layout-of-an-ndarray\"相对=nofollow>文件上numpy的阵列结构在内存:

在numpy的几种算法对随意跨进阵列。
  然而,一些算法需要单段阵列。当
  不规​​则跨入阵中这样的算法过去了,副本
  自动进行。

Several algorithms in NumPy work on arbitrarily strided arrays. However, some algorithms require single-segment arrays. When an irregularly strided array is passed in to such algorithms, a copy is automatically made.

什么是不规则跨入阵列?

What is an irregularly strided array?

这是一个--- numpy.array([1],[1,2]])?如果不是,请提供的一个例子。

Is this one --- numpy.array([[1], [1,2]])? If it's not, please provide an example of one.

推荐答案

例如:

>>> import numpy as np
>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> b = a[::2]
>>> b
array([0, 2, 4, 6, 8])

A 是一个单段阵列,具有密切在一个单一的连续的存储器块彼此相邻包装的所有数据。 B ,另一方面是认为成相同的内存,一个箭步是两倍的元素大小,跳过的奇数的存储位置。

a is a single-segment array, with all the data closely packed next to each other in a single contiguous memory block. b on the other hand is a view into that same memory, with a stride that is twice the element size, skipping over the memory locations of the odd integers.

停留那些需要单段阵列,如果你这样做 np.sort(B),它首先必须对那些块复制到一个连续的功能之一内存块之前,实际上得到与实际排序下去。

Being one of those functions that require a single-segment array, if you do np.sort(b), it will first have to copy those chunks to a contiguous block of memory before actually get going with the actual sorting.

这篇关于numpy的不规则跨进阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆