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
4
votes
2 answers

Zero pad array based on other array's shape

I've got K feature vectors that all share dimension n but have a variable dimension m (n x m). They all live in a list together. to_be_padded = [] to_be_padded.append(np.reshape(np.arange(9),(3,3))) array([[0, 1, 2], [3, 4, 5], [6,…
NicolaiF
  • 1,283
  • 1
  • 20
  • 44
4
votes
1 answer

Even sized kernels with SAME padding in Tensorflow

In Tensorflow, SAME padding aims to produce a same sized output as the input, given a stride = 1, by padding the input with zeros as appropriate. For an odd sized kernel, for example like 5x5, it puts the center of the kernel (2,2) onto the first…
Ufuk Can Bicici
  • 3,589
  • 4
  • 28
  • 57
3
votes
1 answer

How to fit sequences in a dataframe to a multi-class problem? | Keras | Pandas | ValueError: setting an array element with a sequence

I am trying to build a neural network with a sequence to class use case. I have a dataframe with 7 columns: index ID timestamp x1 x2 x3 date_maturity_encoded …
Audiogott
  • 95
  • 2
  • 12
3
votes
2 answers

Python: How to pad with zeros?

Assuming we have a dataframe as below: df = pd.DataFrame({ 'Col1' : ['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c'], 'col2' : ['0.5', '0.78', '0.78', '0.4', '2', '9', '2', '7',] }) I counted the number of rows for all the unique values in…
some_programmer
  • 3,268
  • 4
  • 24
  • 59
2
votes
1 answer

Julia equivalent of pad_width in np.pad

Numpy has a padding function with a pad_width parameter that does the following: pad_width: Number of values padded to the edges of each axis. ((before_1, after_1), ... (before_N, after_N)) unique pad widths for each axis. (before, after) or…
Axion004
  • 943
  • 1
  • 11
  • 37
2
votes
2 answers

Appending zero rows to a 2D Tensor in PyTorch

Suppose I have a tensor 2D tensor x of shape (n,m). How can I extend the first dimension of the tensor by appending zero rows in x by specifying the indices of where the zero rows will be located in the resulting tensor? For a concrete example: x =…
ChrisNick92
  • 123
  • 4
2
votes
2 answers

Writting zeros in file segment

I'm using fwrite to write a file (it's an image). First, I'm writing a header that has a fixed size int num_meta_write_bytes = fwrite(headerBuffer, 1, headerSize, file); This works OK Then I have to write the pixels: num_write_bytes =…
Ivan
  • 1,352
  • 2
  • 13
  • 31
2
votes
0 answers

Visual Studio 2019 generate executable filesize always multiple of 512 bytes

I was wondering if there is a technical explanation of Visual Studio executables file size is always a multiple of 512 bytes. In order to reach the wanted size, Visual Studio adds zero padding to the tail of the executable. Is there an advantage to…
Zac
  • 4,510
  • 3
  • 36
  • 44
2
votes
1 answer

How to pad zeros on Batch, PyTorch

Is there a better way to do this? How to pad tensor with zeros, without creating new tensor object? I need inputs to be of the same batchsize all the time, so I want to pad inputs that are smaller than batchsize with zeros. Like padding zeros in NLP…
Jingles
  • 875
  • 1
  • 10
  • 31
2
votes
3 answers

Unexpected behavior of python datetime strptime with zero-padded formats

I have list of strings representing datetimes in different formats. I.e.: list_date_str = ['2021010112', '202101011210'] The first should translate to 2021-01-01 12:00, the second to 2021-01-01 12:10. Without giving much thought to it I wrote this…
Durtal
  • 1,063
  • 3
  • 11
2
votes
1 answer

PHP encrypted data needs to be decrypted in ReactNative

I am using following snippet to do AES encryption for CBC 256 mode in PHP. $iv_real = "ahc/2u6F0Yvww12fyQiZWA=="; $decoded_iv = base64_decode($iv_real); $plaintext_shared_secret =…
Ekayaa
  • 169
  • 16
2
votes
4 answers

Condition based array zero padding

I have two arrays: a = numpy.array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) label = numpy.array(['a', 'a', 'a', 'a', 'a', 'a', 'a', 'b', 'b', 'b']) What I am looking for, is padding the zeros according to the following condition: If the…
akkab
  • 401
  • 1
  • 6
  • 19
2
votes
1 answer

Format doesn't show

So I'm trying to get my month numbers to be zero padded from the left meaning {01, 02, 03, ..., 10, 11, 12}. I thought to do so with formatting but after searching the internet I wonder if formatting really adds a zero or if I'll only see a zero…
Pythn
  • 171
  • 2
  • 10
2
votes
0 answers

How does PyTorch conv1D handle the padding for variable length sequences?

I have a batch of variable length sequences padded with 0 (padding = post) and would like to perform conv1D to generate feature maps. How does PyTorch conv1D handle padded sequences? For example, the rnn (recurrent neural network) and crf…
PinkBanter
  • 1,686
  • 5
  • 17
  • 38
2
votes
0 answers

How to zero pad a PIL Image?

I want to add zeros on all sides of image. I try: from PIL import Image im = Image.open("/content/drive/My Drive/image31.png") def pad(im,layers): return [[0]*(len(im[0])+2*layers)]*layers + \ [[0]*layers+r+[0]*layers for r in im]…