This is part of an algorithm to generate concentric rings of points on a hexagonal lattice that I'm in the process of rewriting.
I'd thought it's all integer math, but I discovered that in some cases arrays are unexpectedly created as floats!
In the sequence below p0 is a float64 for n=1 but int64 for n>1 and I simply can not figure out why this is happening.
I'm running numpy version 1.17.3, Anaconda installation of Python 3.7.3 on MacOS
import numpy as np
n_max = 3
for n in range(1, n_max+1):
seq = np.arange(n, -n-1, -1, dtype=int)
p0 = np.hstack((seq, (n-1)*[-n], seq[::-1], (n-1)*[n]))
print('n: ', n)
print('seq: ', seq)
print('p0: ', p0.dtype, p0)
print('')
returns
n: 1
seq: [ 1 0 -1]
p0: float64 [ 1. 0. -1. -1. 0. 1.]
n: 2
seq: [ 2 1 0 -1 -2]
p0: int64 [ 2 1 0 -1 -2 -2 -2 -1 0 1 2 2]
n: 3
seq: [ 3 2 1 0 -1 -2 -3]
p0: int64 [ 3 2 1 0 -1 -2 -3 -3 -3 -3 -2 -1 0 1 2 3 3 3]
Is that expected behavior?
update 1: okay np.hstack(([1, 0, -1], 1*[7])) returns int64 but np.hstack(([1, 0, -1], 0*[7])) returns float64 so it's the occurrence of the 0*[n] in the tuple on which np.hstack operates that's triggering the upcast to float64.
update 2: Just asked in Code Review: Is there a better, cleaner or otherwise “less tricky” way to get these hexagonal arrays of dots arranged in this spiral pattern?