def _index_fields(ary, fields): from multiarray import empty, dtype dt = ary.dtype new_dtype = [(name, dt[name]) for name in dt.names if name in fields] if ary.flags.f_contiguous: order = 'F' else: order = 'C' newarray = empty(ary.shape, dtype=new_dtype, order=order) for name in fields: newarray[name] = ary[name] return newarray
def _index_fields(ary, fields): from multiarray import empty, dtype dt = ary.dtype new_dtype = [(name, dt[name]) for name in dt.names if name in fields] future_dtype = [(name, dt[name]) for name in fields if name in dt.names] if not new_dtype == future_dtype: depdoc = "Out of order field selection on recarrays currently returns \ fields in order. This behavior is deprecated in numpy 1.5 and will change in \ 2.0. See ticket #1431." warnings.warn(depdoc, DeprecationWarning) if ary.flags.f_contiguous: order = 'F' else: order = 'C' newarray = empty(ary.shape, dtype=new_dtype, order=order) for name in fields: newarray[name] = ary[name] return newarray
except AttributeError: # Py3K ScalarType = [int, float, complex, int, bool, bytes, str, memoryview] ScalarType.extend(_sctype2char_dict.keys()) ScalarType = tuple(ScalarType) for key in _sctype2char_dict.keys(): cast[key] = lambda x, k=key: array(x, copy=False).astype(k) # Create the typestring lookup dictionary _typestr = _typedict() for key in _sctype2char_dict.keys(): if issubclass(key, allTypes['flexible']): _typestr[key] = _sctype2char_dict[key] else: _typestr[key] = empty((1, ), key).dtype.str[1:] # Make sure all typestrings are in sctypeDict for key, val in _typestr.items(): if val not in sctypeDict: sctypeDict[val] = key # Add additional strings to the sctypeDict if sys.version_info[0] >= 3: _toadd = [ 'int', 'float', 'complex', 'bool', 'object', 'str', 'bytes', 'object', ('a', allTypes['bytes_']) ] else: _toadd = [