2 ms·
You don’t have to make it so complicated! : user@debian:~; python Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 Type "he
by kragen 11y ago
You don’t have to make it so complicated!
: user@debian:~; python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> (10**(1+np.arange(24)/24.0)).reshape((2,3,4)).round()
array([[[ 10., 11., 12., 13.],
[ 15., 16., 18., 20.],
[ 22., 24., 26., 29.]],
[[ 32., 35., 38., 42.],
[ 46., 51., 56., 62.],
[ 68., 75., 83., 91.]]])
>>> (10**(2+np.arange(48)/48.0)).reshape((2,3,8)).round()
array([[[ 100., 105., 110., 115., 121., 127., 133., 140.],
[ 147., 154., 162., 169., 178., 187., 196., 205.],
[ 215., 226., 237., 249., 261., 274., 287., 301.]],
[[ 316., 332., 348., 365., 383., 402., 422., 442.],
[ 464., 487., 511., 536., 562., 590., 619., 649.],
[ 681., 715., 750., 787., 825., 866., 909., 953.]]])
>>>
Hmm, Ruby has a numpy-like thing too, no? NArray, it’s called? There
are a few minor differences, but you can do the same thing:
: user@debian:~; irb
irb(main):001:0> require 'narray'
=> true
irb(main):002:0> (10*10**(NArray.float(24).indgen!/24)).round.reshape(4,3,2)
=> NArray(ref).int(4,3,2):
[ [ [ 10, 11, 12, 13 ],
[ 15, 16, 18, 20 ],
[ 22, 24, 26, 29 ] ],
[ [ 32, 35, 38, 42 ],
[ 46, 51, 56, 62 ],
[ 68, 75, 83, 91 ] ] ]
irb(main):003:0> (100*10**(NArray.float(48).indgen!/48)).round.reshape(8,3,2)
=> NArray(ref).int(8,3,2):
[ [ [ 100, 105, 110, 115, 121, 127, 133, 140 ],
[ 147, 154, 162, 169, 178, 187, 196, 205 ],
[ 215, 226, 237, 249, 261, 274, 287, 301 ] ],
[ [ 316, 332, 348, 365, 383, 402, 422, 442 ],
[ 464, 487, 511, 536, 562, 590, 619, 649 ],
[ 681, 715, 750, 787, 825, 866, 909, 953 ] ] ]
irb(main):004:0>
Presumably 12, 24, and 48 were chosen because they are
https://en.wikipedia.org/wiki/Highly_composite_numbers https://en.wikipedia.org/wiki/Highly_composite_numbers, and 96 and 192
for compatibility with 48 (since the HCNs in that neighborhood — 60,
120, and 180 — aren’t divisible by 48.)
(Related joke: How do we know the Babylonians were idiots? Because
the day doesn’t have 83160 seconds.)