[Numpy-discussion] append_fields behavior with a (sort of) empty array
Skipper Seabold
jsseabold at gmail.com
Tue Mar 8 20:19:25 EST 2011
First consider this example of column_stack
import numpy as np
x = np.random.random((5,1))
y = np.random.random((5,3))
arr = np.column_stack((x[[]], y))
# this fails which is expected
arr = np.column_stack((x[:,[]], y))
# this happily works I guess because
x[:,[]]
# array([], shape=(5, 0), dtype=float64)
Now if I want to something analogous with structured array I don't see
off the bat how. Is this desired behavior? At the very least it's a
partial bug I think.
import numpy.lib.recfunctions as nprf
xx = np.zeros(5, dtype=[('variable',float)])
xx['variable'] = np.random.random(5)
yy = np.random.random((5,2))
arr2 = nprf.append_fields((xx[[]][:], ['var1','var2'], yy.T, usemask=False)
arr2
array([(1e+20, 0.24277386045950911, 0.3801949115638894),
(1e+20, 0.81574702386474807, 0.95094000248766541),
(1e+20, 0.7901945469951196, 0.49315509384277167),
(1e+20, 0.84140435880491093, 0.37125966704723368),
(1e+20, 0.66595836283749366, 0.18154580574750145)],
dtype=[('variable', '<f8'), ('var1', '<f8'), ('var2', '<f8')])
I think it should either fail or return yy. Surely, it shouldn't fill
in with 1e20 (ignoring fill_value). I don't think it should do any
padding if usemask=False. Am I missing something? Bug
report/enhancement ticket?
Skipper
More information about the NumPy-Discussion
mailing list