Questions tagged [pad]

This tag is currently a synonym for [padding]. For other purposes, please consider [gamepad] or [ipad] or [pad-xml] instead.

Padding is the process of fitting a given data type (usually a number, image, array, or string) to a particular size by adding data to it without changing its overall meaning.

132 questions
4
votes
1 answer

In Perl, how can I pad an array with zeroes?

In Perl, how can I pad an array with zeroes? I know that I can get the length of the array, and then do a for loop with a push, but is there a more palatable way? For example: my @array = pad_with_zeroes("foo", "bar", "baz", 6); # @array now eq…
Cerian
  • 43
  • 3
4
votes
1 answer

Excel formula to pad array

Examples: Say I have several 1D arrays, such as A, B, and C: A B C --- --- --- 2 4 99 3 5 37 4 6 42 7 I want to use a formula to pad each of these arrays (which are named ranges) so they have the same number of…
dnlbrky
  • 9,396
  • 2
  • 51
  • 64
4
votes
5 answers

PHP integer part padding

I need to pad the integer part with 0, the integer part must be at least 2 characters str_pad( 2 ,2,"0",STR_PAD_LEFT);// 02 -> works str_pad( 22 ,2,"0",STR_PAD_LEFT);// 22 -> works str_pad( 222 ,2,"0",STR_PAD_LEFT);// 222-> works str_pad( 2. …
user1125394
3
votes
1 answer

How to produce a single column of a specific length?

This is not as simple as it may appear. I have struggled for hours and googled to no avail. I want to produce a single column that always has a length of 30 characters, so if the column only contains 2 characters, the other 28 characters should be…
Incompetent77
  • 71
  • 1
  • 7
3
votes
1 answer

How to pad a RGB image with RGB values using numpy.pad

I'm trying to pad a RGB image with magenta (255, 0, 255) color with np.pad. But I'm getting an error when using RGB values as constant_values. For example: import numpy as np from scipy.misc import face import matplotlib.pyplot as plt def…
trsvchn
  • 8,033
  • 3
  • 23
  • 30
3
votes
5 answers

Python Tkinter Entry pad text

How could I pad the entry widget so it does not start writing right at the border of the widget? Visually, having a little space from the entry widget border. My progress: entry_widget.bind('', lambda f: entry_widget.insert(0, ' ')) That…
Programer Beginner
  • 1,377
  • 6
  • 21
  • 47
3
votes
1 answer

How can I pad an image when I only know its physical bounds?

I am trying to apply a mask on an image but the masking image has different dimensions that the one to be masked. To apply the mask I must ensure that the images have the same dimensions, so I'm using the ITK PadImageFilter class, but to do so the…
avazula
  • 472
  • 1
  • 6
  • 23
3
votes
1 answer

How is numpy pad implemented (for constant value)

I'm trying to implement the numpy pad function in theano for the constant mode. How is it implemented in numpy? Assume that pad values are just 0. Given an array a = np.array([[1,2,3,4],[5,6,7,8]]) # pad values are just 0 as indicated by…
Aditya369
  • 834
  • 8
  • 20
3
votes
1 answer

Numpy padding 4D units with all zeros

I have a 4D numpy array, but each element is a variable size 3D volume. Essentially it is a numpy list of 3D volumes. So the numpy array has the shape... (Pdb) batch_x.shape (3,) And take element i in that list, and it looks like this... (Pdb)…
Kendall Weihe
  • 2,021
  • 4
  • 27
  • 53
3
votes
0 answers

how can I use padTo for padding to the left?

I have a number, I want to pad this number with zero's in the beginning if the digits are less that 9 digits. currently if I have a number lets say: val num = "123" if I use padTo(9,"0") I will get "123000000" but I want "000000123"... what is the…
Joe
  • 2,543
  • 3
  • 25
  • 49
3
votes
3 answers

Padding list elements with spaces givin' min length

For any name whose length is less than the minimum, replace that item of the list with a new string containing the name with space(s) added to the right-hand side to achieve the minimum length. For example, if the list contains the name "Sue" and…
2
votes
2 answers

How to pad a one hot array of length n with a 1 on either side of the 1

For example I have the following array: [0, 0, 0, 1, 0, 0, 0] what I want is [0, 0, 1, 1, 1, 0, 0] If the 1 is at the at the end, for example [1, 0, 0, 0] it should add only on one side [1, 1, 0, 0] How do I add a 1 on either side while keeping the…
2
votes
2 answers

Append Additional Information(data) to Dataframe Column Values

I have a dataframe that looks like this: Filename Label Mont_01_015_00 IDL Mont_01_016_00 NEG There are 18,000+ files and I am looking at append (.wav) to the filenames so that it will look like this: Filename …
Gee
  • 21
  • 1
2
votes
1 answer

How to mutate a variable using str_pad in R

I want obtain as result for df$y "01", "02", "03", "40h", but I can't understand my error: library(tidyverse) df <- tibble(x = c(1,2,3,4), y = c("1","2","03","40h")) df %>% mutate(y = if_else(length(y) < 2,…
sbac
  • 1,897
  • 1
  • 18
  • 31
2
votes
1 answer

How to pad an array non-symmetrically (e.g., only from one side)?

There is an example in Numpy's documentation for padding 2D arrays with constants: def pad_with(vector, pad_width, iaxis, kwargs): pad_value = kwargs.get('padder', 10) vector[:pad_width[0]] = pad_value vector[-pad_width[1]:] =…
Azim
  • 1,596
  • 18
  • 34
1
2
3
8 9