Questions tagged [zero-padding]

The practice of padding a number (or string) with zeros in order to match an expected number of characters or bytes.

The practice of padding a number (or string) with zeros in order to match an expected number of characters or bytes.

For example, if the expected length of a string is 6, the number '123' could be zero padded as '000123' in order to meet this expected length.

111 questions
2104
votes
19 answers

How do I pad a string with zeroes?

How do I pad a numeric string with zeroes to the left, so that the string has a specific length?
Faisal
172
votes
5 answers

Why do we "pack" the sequences in PyTorch?

I was trying to replicate How to use packing for variable-length sequence inputs for rnn but I guess I first need to understand why we need to "pack" the sequence. I understand why we "pad" them but why is "packing" (via pack_padded_sequence)…
aerin
  • 20,607
  • 28
  • 102
  • 140
71
votes
6 answers

Zero pad numpy array

What's the more pythonic way to pad an array with zeros at the end? def pad(A, length): ... A = np.array([1,2,3,4,5]) pad(A, 8) # expected : [1,2,3,4,5,0,0,0] In my real use case, in fact I want to pad an array to the closest multiple of…
Basj
  • 41,386
  • 99
  • 383
  • 673
14
votes
3 answers

How to avoid: read.table truncates numeric values beginning with 0

I want to import a table (.txt file) in R with read.table(). One column in my table is an ID with nine numerals - some ids begin with a 0, other with 1 or 2. R truncates the first 0 (012345678 becomes 12345678) which leads to problems when using…
Tim
  • 293
  • 3
  • 9
13
votes
1 answer

Zero Padding a 3d Numpy array

I have a 3d numpy array(data) with shape say (103, 37, 13). I want to resize this numpy array to (250,250,13) by zero padding almost equally in both directions along each axis. The code below works well for 2d array, but I am not able to make it…
ayush gupta
  • 607
  • 1
  • 6
  • 14
6
votes
1 answer

Using fmtlib, zero padded numerical value are shorter when the value is negative, can I adapt this behaviour?

I am using fmtlib to format strings and numeric values but I have problem with negative integers. When I pad the value with zeroes, I expect a consistent number of zero no matter the sign of the value. For instance, using a padding of 4, I would…
jeromes
  • 497
  • 5
  • 17
6
votes
1 answer

Keras Embedding Layer: keep zero-padded values as zeros

I've been thinking about 0-padding of word sequence and how that 0-padding is then converted to the Embedding layer. At first glance, one would think that you want to keep the embeddings = 0.0 as well. However, Embedding layer in keras generates…
6
votes
5 answers

Reflection padding Conv2D

I'm using keras to build a convolutional neural network for image segmentation and I want to use "reflection padding" instead of padding "same" but I cannot find a way to to do it in keras. inputs = Input((num_channels, img_rows,…
aferjani
  • 115
  • 1
  • 1
  • 10
5
votes
1 answer

How does SAME padding work in convolution neural networks, when stride is greater than 1?

I am trying to implement 2-D convolution in python. I have an input image set of dimensions (m, 64, 64, 3), where m is the number of images. I want to use a filter size f=8 and stride=8 for both height and width, and SAME padding so that input width…
5
votes
2 answers

Padding a tensor until reaching required size

I'm working with certian tensors with shape of (X,42) while X can be in a range between 50 to 70. I want to pad each tensor that I get until it reaches a size of 70. so all tensors will be (70,42). is there anyway to do this when I the begining size…
secret
  • 505
  • 4
  • 16
5
votes
2 answers

CSS Counter with a Number Padding

Is it possible to pad counter numbers depending on its value? div { counter-reset: ruler; } div > span { display: block; line-height: 1rem; } div > span::before { counter-increment: ruler; content: counter( ruler ) '…
5
votes
2 answers

What is the default kernel-size, Zero-padding and stride for keras.layers.Conv2D?

What are the default Kernel-Size, Zero-Padding, and Stride arguments in Conv2D (keras.layers.Conv2D)? What happens if these arguments are not specified?
5
votes
7 answers

How to pad single-digit numbers with a leading 0

I am looping an array of one-digit and two-digit numbers. When printing these values, I need to ensure that all values are shown as two-digit numbers. I need a solution to prepend zeros to the single-digit numbers but leave the two-digit numbers…
matthewb
  • 3,462
  • 8
  • 37
  • 53
4
votes
3 answers

How to pad numbers with JQ?

I'd like to add leading/trailing zeros to strings from numbers — resultant string needs to contain "01" or "001" and not "1". I noticed project https://github.com/joelpurra/jq-zeros but I have jq installed from package manager (dnf, fedora) so…
Martin Mucha
  • 2,385
  • 1
  • 29
  • 49
4
votes
1 answer

Tensorflow/Keras Conv2D layers with padding='SAME' behave strangely

My question: A straightforward experiment that I conducted showed that using padding='SAME' in a conv2d layer in Keras/TF is different from using padding='VALID' with a preceding zero-padding layer. How is that possible? Does Keras/TF pads zeros…
SomethingSomething
  • 11,491
  • 17
  • 68
  • 126
1
2 3 4 5 6 7 8