0

I have a base array of equally spaced values [0, 1, ..., 511]. I need to create a target array over [0 to 511] that consists of approximately 4096 values. It must also contain all the values 0, 1, 2, ... that are in base.

base = [0, 1, 2, 3, ..., 511]

target = [0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1, ..., 511]

I have:

base = np.linspace(0, 511, 512)

target = np.linspace(0, 511, 4096) 

Unfortunately, target seems to be incorrect:

[0;0.124786;0.249573;0.374359;0.499145;0.623932;0.748718;0.873504;0.998291;...]

I need it to contain the numbers from base.

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135

1 Answers1

0

To construct an equally spaced sequence (0, ..., b) containing all integers within that interval, where b is an integer, choose any integer k and then:

np.linspace(0, b, k * b + 1)

In your case,

np.linspace(0, 511, 8 * 511 + 1)
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
  • Thank your for the answer. This indeed does contain all the values, however, it's only 4089 values. I need it to be 4096 and seems to me that's not possible, is it? – Terranigmus May 20 '21 at 13:52
  • Unfortunately not, if you want to maintain the property of "evenly spaced". Is 4096 necessary for a reason? – Mateen Ulhaq May 20 '21 at 18:51
  • Yes. I do signal processing where I need to shift oversampled data and later I need to resample, again, down to 512 again. Now that alone is no reason, but certain sample positions within the 4096 space also contain important information so I need to stay in that count. Can you tell me why it's not possible? I jus can't figure out the math... – Terranigmus May 20 '21 at 19:09
  • "Proof": There is **exactly one** evenly spaced sequence between `[0, 511]` with 4096 elements. (Any other sequence is not evenly spaced.) This sequence can be generated by `np.linspace(0, 511, 4096)`. As you showed, the sequence that code generates is not desirable. By uniqueness, no other sequences exist, and thus the task is impossible. – Mateen Ulhaq May 21 '21 at 08:36
  • On what domain did you sample the 4096 samples? Can you use that domain? If you use any other domain, it will require resampling. – Mateen Ulhaq May 21 '21 at 08:37