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
739
votes
14 answers

How can I fill out a Python string with spaces?

I want to fill out a string with spaces. I know that the following works for zero's: >>> print "'%06d'"%4 '000004' But what should I do when I want this?: 'hi ' of course I can measure string length and do str+" "*leftover, but I'd like the…
taper
  • 9,236
  • 5
  • 28
  • 29
142
votes
7 answers

python how to pad numpy array with zeros

I want to know how I can pad a 2D numpy array with zeros using python 2.6.6 with numpy version 1.5.0. But these are my limitations. Therefore I cannot use np.pad. For example, I want to pad a with zeros such that its shape matches b. The reason why…
user2015487
  • 2,075
  • 3
  • 17
  • 20
44
votes
4 answers

Pad python floats

I want to pad some percentage values so that there are always 3 units before the decimal place. With ints I could use '%03d' - is there an equivalent for floats? '%.3f' works for after the decimal place but '%03f' does nothing.
hoju
  • 28,392
  • 37
  • 134
  • 178
27
votes
5 answers

Add leading zeroes to awk variable

I have the following awk command within a "for" loop in bash: awk -v pdb="$pdb" 'BEGIN {file = 1; filename = pdb"_" file ".pdb"} /ENDMDL/ {getline; file ++; filename = pdb"_" file ".pdb"} {print $0 > filename}' < ${pdb}.pdb This reads a series…
mirix
  • 511
  • 1
  • 5
  • 13
14
votes
4 answers

JavaScript: How to add x to an array x times?

I imagine this is similar to array padding, but I wonder if it can be simplified at all. var arr = [1,2,3], x = 5; for (var i=0; i [1, 2, 3, 5, 5, 5, 5, 5] Is there any way to do this…
Mulan
  • 129,518
  • 31
  • 228
  • 259
11
votes
5 answers

Sox : merge two audio files with a pad

I'm using the sox tool and I would like to merge two audio files, let's say long.ogg and short.ogg to output a file output.ogg. This is very easy using $ sox -m long.ogg short.ogg output.ogg. Thing is, I would like the short.ogg to be played after n…
zopieux
  • 2,854
  • 2
  • 25
  • 32
11
votes
1 answer

Filling date gaps in pandas dataframe

I have Pandas DataFrame (loaded from .csv) with Date-time as index.. where there is/have-to-be one entry per day. The problem is that I have gaps i.e. there is days for which I have no data at all. What is the easiest way to insert rows (days) in…
sten
  • 7,028
  • 9
  • 41
  • 63
10
votes
2 answers

jQuery lightbox with zoom

Is there a jQuery script or plugin that opens images in a lightbox and allows you to zoom in further within the lightbox? I have found PLENTY of scripts that do either, or some variant of it, but none seem to do both. The only option package I found…
NekaraNef
  • 197
  • 1
  • 1
  • 8
8
votes
3 answers

Padding an image in MATLAB

I have an image of size 61x56 and I want to pad the image to size 392x392. I am trying to use padarray but since I get a non-integer value I am unable to do this. Can anyone help me with this. Thanks a lot! I have attached what I want to do below. K…
Sista
  • 887
  • 2
  • 15
  • 19
7
votes
2 answers

c# pad left to string

i want to find a efficent way to do : i have a string like : '1,2,5,11,33' i want to pad zero only to the numbers that below 10 (have one digit) so i want to get '01,02,05,11,33' thanks
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
6
votes
1 answer

How to pad left in Rust?

I'm new to Rust and completely lost in the standard library. I do not want to add a crate just for padding. How do I pad left a number with zeroes up to a certain width? Lets say I have this code and I need the pad_left implementation. fn main() { …
ditoslav
  • 4,563
  • 10
  • 47
  • 79
5
votes
2 answers

xsd pattern acceptable for decimals?

We have a request to implement our webservice response so that xsd:decimal fraction digits will be zero-padded when it's not long enough when a pattern indicates so. I am wondering if this is a reasonable request and if xsd:decimal is supposed to be…
Sebastiaan van den Broek
  • 5,818
  • 7
  • 40
  • 73
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
4
votes
4 answers

Pad a packed struct in C for 32-bit alignment

I have a struct defined that is used for messages sent across two different interfaces. One of them requires 32-bit alignment, but I need to minimize the space they take. Essentially I'm trying to byte-pack the structs, i.e. #pragma pack(1) but…
Alex
  • 827
  • 8
  • 18
4
votes
2 answers

R transform data frame with start and end year into time series

I would like to transform a data frame that has both start-year and end-year variables into a complete time series that (1) includes all the years in between start-year and end-year and (2) fills in the values of all the variables for the years in…
1
2 3
8 9