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
3
votes
1 answer

Why is creating a temp array with Stride illegal in an Array extension

This code throws a compiler error: "Argument type 'StrideTo' expected to be an instance of a class or class-constrained type" extension Array { func chunks(_ chunkSize: Int) -> [[Element]] { let indexes = Array(stride(from: 0, to: count,…
Duncan C
  • 128,072
  • 22
  • 173
  • 272
3
votes
2 answers

How strides help in traversing an array in numpy?

arr = np.arange(16).reshape((2, 2, 4)) arr.strides (32, 16, 4) So, I believe from my knowledge that in memory it would be something like the image below. The strides are marked along with the axis (on the arrows). And this is what I think I have…
Ambush14
  • 33
  • 4
3
votes
1 answer

Inverse function of numpy as_strided

I have a 4-tensor x. The 6-tensor y is computed as follows: x = np.random.randn(64, 28, 28, 1) strided_shape = 64, 26, 26, 3, 3, 1 y = numpy.lib.stride_tricks.as_strided(x, strided_shape, strides=(x.strides[0], x.strides[1], x.strides[2],…
Nihar Karve
  • 230
  • 4
  • 15
3
votes
1 answer

swift breaks into infinite loop after conforming to Stridable

I have an enum like this: enum Rank: CaseIterable { case Ace, King, Queen, ... } and want to make it conform to Stridable. I tried to implement the func distance(to other: _) by getting the index of the card like so: func distance(to other: Rank)…
Schottky
  • 1,549
  • 1
  • 4
  • 19
3
votes
1 answer

When would I want to set a stride in the batch or channel dimension for TensorFlow convolution?

Tensor flow implements a basic convolution operation with tf.nn.conv2d. I am specifically interested in the "strides" parameter, which lets you set the stride of the convolution filter -- how far across the image you shift the filter each time. The…
snickers10m
  • 1,709
  • 12
  • 28
3
votes
1 answer

Can numpy strides stride only within subarrays?

I have a really big numpy array(145000 rows * 550 cols). And I wanted to create rolling slices within subarrays. I tried to implement it with a function. The function lagged_vals behaves as expected but np.lib.stride_tricks does not behave the way I…
Ic3fr0g
  • 1,199
  • 15
  • 26
3
votes
1 answer

Sliding windows along last axis of a 2D array to give a 3D array using NumPy strides

I am trying to use the function as_strided from numpy.lib.stride_tricks to extract sub series from a larger 2D array, but I struggled to find the right thing to write for the strides argument. Let's say I have a matrix m which contains 5 1D array of…
Nuageux
  • 1,668
  • 1
  • 17
  • 29
3
votes
1 answer

Creating overlapping subarrays using stride_tricks

I found the below code that creates overlapping subarrays of a given length. It does what I want except that it also reverses the order of the elements, which I do not want. I couldn't really find documentation on the 'shape' and 'strides' arguments…
3
votes
2 answers

Slanted bitmap, stride calculation for RGB565 C#

Some of my resulting images are slanted, some are not. Expected Result: (529x22) Actual Result: (529x22) Don't mind the different image sizes, these are screenshots. They are both 529x22. The code I am using, I just got this from an answer on a…
majidarif
  • 18,694
  • 16
  • 88
  • 133
3
votes
1 answer

Quick way to get strided reverse of NumPy array

I have an application where I need to reverse the elements along one axis of a NumPy array according to some stride. As an example, let's consider that I have the following array In [1]: import numpy as np In [2]: a =…
wbinventor
  • 345
  • 1
  • 4
  • 13
3
votes
1 answer

Correct stride formula for BITMAP

Calculating Surface Stride In an uncompressed bitmap, the stride is the number of bytes needed to go from the start of one row of pixels to the start of the next row. The above is from BITMAPINFOHEADER structure and makes absolute…
Thalia
  • 13,637
  • 22
  • 96
  • 190
3
votes
0 answers

Moving window with complete boundary in Python

I have been using rolling/moving windows lately and all implementations I have seen so far ignore values contained in the boundaries of the array if these values can not be placed in a complete window. For example, assume you have this array: import…
r_31415
  • 8,752
  • 17
  • 74
  • 121
3
votes
1 answer

Image stride for MSpaint image in C# is +1 byte, why?

I have a problem regarding some pixel-based operations in C#. I wrote a class that serves as an image shell around a Bitmap. It can give you the RGB values of a pixel at a certain (x,y) location in the image much faster than the Bitmap.GetRGB(x,y)…
2
votes
1 answer

SwiftUI - Attempted to scroll the collection view to an out-of-bounds item

My App is getting crashed immediately after navigating to the screen in iOS>16.0 devices by saying *** Assertion failure in -[_TtC7SwiftUIP33_8825076C2763A50452A210CBE1FA4AF020PagingCollectionView _validateScrollingTargetIndexPath:],…
Bhanuteja
  • 771
  • 2
  • 8
  • 18
2
votes
2 answers

Identify a minimum that occurs before a maximum within a rolling widow in python

I am trying to identify a minimum that occurs before a maximum that is found within a rolling window that starts on row after (yes that is convoluted but I don’t have the English to express it otherwise!) By way of an example: First I want to return…
sdp501
  • 55
  • 4
1 2
3
10 11