Questions tagged [stride]

The stride of an array is the number of locations in memory between beginnings of successive array elements, measured in bytes or in units of the size of the array's elements. Arrays may have a stride larger than their elements' width in bytes, which are called a non-unit stride. One particular use of non-unit stride is for images, when creating subimages without copying the pixel data.

The stride of an array is the number of locations in memory between beginnings of successive array elements, measured in bytes or in units of the size of the array's elements. Arrays may have a stride larger than their elements' width in bytes, which are called a non-unit stride. One particular use of non-unit stride is for images, when creating subimages without copying the pixel data.

157 questions
2
votes
1 answer

python implementation of numpy.lib.stride_tricks.as_strided

I'm trying to translate the as_strided function of NumPy to a function in Python when I translate ahead the number of strides to the number of variables according to the type of the variable (for float32 I divide the stride by 4, etc). The code I…
2
votes
2 answers

NumPy template matching SQDIFF with `sliding window_view`

The SQDIFF is defined as openCV definition. (I believe they omit channels) Which in junior numpy Python should be A = np.arange(27, dtype=np.float32) A = A.reshape(3,3,3) # The "image" B = np.ones([2, 2, 3], dtype=np.float32) # window rw, rh =…
vahvero
  • 525
  • 11
  • 24
2
votes
1 answer

How does numpy reshaping of a slice works

I'm trying to reimplement numpy from scratch but I can't figure out how slicing works exactly. Take as an example this array: > a = np.array(list(range(0,20))) array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,…
alagris
  • 1,838
  • 16
  • 31
2
votes
1 answer

Un-interleave an iterator into two separate iterators

Similar to this question: How do I interleave two Rust vectors by chunks of threes into a new vector? Instead, I'd like to perform the opposite behavior. Separate an iterator into two different iterators without having to collect their contents…
Saxpy
  • 129
  • 1
  • 7
2
votes
1 answer

How can I get a view of input as a complex tensor? RuntimeError: Tensor must have a last dimension with stride 1

I have a tensor with 64 elements in pytorch and I want to convert it to a complex tensor with 32 elements. Order is important for me and everything should be in PyTorch so I can use it in my customized loss function: the first half in my primary…
DeepRazi
  • 259
  • 4
  • 13
2
votes
1 answer

Swifts stride with Doubles is unreliable

Using stride with Swift 4 sometimes results in wrong results, what is demonstrated by this piece of code: import UIKit import PlaygroundSupport struct Demo { let omegaMax = 10.0 let omegaC = 1.0 var omegaSignal:Double {get {return 0.1 *…
Heinz M.
  • 668
  • 3
  • 8
2
votes
1 answer

How to split array by indices where the splitted sub-arrays include the split point

I have a 2D array containing values and a 1D array with index values where I would like to split the 2D matrix, where the splitted sub-arrays include the 'split-point'. I know I can use the numpy.split function to split by indices and I know I can…
Mattijn
  • 12,975
  • 15
  • 45
  • 68
2
votes
2 answers

Extract random 2d windows of a 2d numpy array

import numpy as np arr = np.array(range(60)).reshape(6,10) arr > array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], > [20, 21, 22, 23, 24, 25, 26, 27, 28, 29], > [30, 31, 32, 33, 34,…
Mario Fajardo
  • 620
  • 4
  • 8
2
votes
1 answer

Why are non-positive strides disallowed in the blas gemm family of functions?

The netlib documentation of sgemm states that the array strides LDA and LDB must be >= 1, and large enough so that columns don't overlap. Indeed, the implementation in Apple's Accelerate/veclib framework checks these conditions and exists if they…
tglas
  • 949
  • 10
  • 19
2
votes
1 answer

How to set the arguments of tf.extract_image_patches

I want to extract image patches from the input image in my tensorflow model. Let's say the input image is [batch, in_width, in_height, channels], I want to output [no_patches, patch_width, patch_height, channels]. no_patches are the total number of…
shaaa
  • 503
  • 1
  • 4
  • 16
2
votes
2 answers

How do I get the strides from a dtype in numpy?

I think I can do: np.zeros((), dtype=dt).strides, but this doesn't seem efficient when the dtype is a large array type like: ('
Neil G
  • 32,138
  • 39
  • 156
  • 257
2
votes
2 answers

Force numpy array to physically match striding in memory

For a cross-correlation routine I want to take some 2-D matrices (greyscale images), rotate half of them by 90 degrees, and Fourier transform them all. I am cross-correlating a huge number of frames so I am trying to use pyFFTW with the FFTW object…
2
votes
1 answer

Do popular CPUs / CPU instruction sets support strided data access?

Suppose I have two array-of-structures (the structures have the same type, size, field offsets etc.), and I want to copy the first field of all structures in the first array onto the first field of the structures in the second array. Do modern…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
2
votes
2 answers

Get maximum element of std::vector with strides

I have a std::vector with the following layout of data x1 | y1 | z1 | x2 | y2 | z2 | .... | xn | yn | zn I'm trying to figure out an STL-ish way to get the maximum x element as well as y or z The obvious double xyzmax =…
linello
  • 8,451
  • 18
  • 63
  • 109
2
votes
1 answer

Stride on image using Opencv C++

I am on windows and use opencv 2.4.2 on C++. I read an image with imread and put it in a Mat object. After that, i get a pointer on the raw data using the function ptr of the Mat class. I would like to know how works imread when the image contains…
Seltymar
  • 337
  • 6
  • 21