Convert an array from 0..1 to dtype, scaling up linearly
184492
def scale_dtype(arr, dtype):
    
    max_int = np.iinfo(dtype).max
    return (arr * max_int).astype(dtype)
1264739
def to_scaled_dtype(val):
    
    res = []
    for i in val:
        if i[1].startswith("S"):
            res.append((i[0], i[1]) + i[2:-1])
        else:
            try:
                res.append((i[0], i[-1].dtype) + i[2:-1])
            except AttributeError:
                res.append((i[0], type(i[-1])) + i[2:-1])

    return np.dtype(res)
770333
def annealing_linear(start:Number, end:Number, pct:float)->Number:
    ""
    return start + pct * (end-start)
973702
def to_np(v):
    ''''''
    if isinstance(v, float): return np.array(v)
    if isinstance(v, (np.ndarray, np.generic)): return v
    if isinstance(v, (list,tuple)): return [to_np(o) for o in v]
    if isinstance(v, Variable): v=v.data
    if torch.cuda.is_available():
        if is_half_tensor(v): v=v.float()
    if isinstance(v, torch.FloatTensor): v=v.float()
    return v.cpu().numpy()
774858
def fromNumpy(cls, data):
        
        assert np is not None
        if isinstance(data, np.ndarray):
            index = []
            if len(data.shape) == 1:
                columns = [('value', data.tolist())]
            elif len(data.shape) == 2:
                columns = [
                    ('c{}'.format(i), col)
                    for i, col in enumerate(zip(*data.tolist()))
                ]
            else:
                raise TypeError
        else:
            raise TypeError
        return cls(index=index, columns=columns)
798227
def _to_array(self, alpha, normalization='4pi', csphase=1):
        
        coeffs = _shtools.SHVectorToCilm(self.tapers[:, alpha])

        if normalization == 'schmidt':
            for l in range(self.lmax + 1):
                coeffs[:, l, :l+1] *= _np.sqrt(2.0 * l + 1.0)
        elif normalization == 'ortho':
            coeffs *= _np.sqrt(4.0 * _np.pi)

        if csphase == -1:
            for m in range(self.lmax + 1):
                if m % 2 == 1:
                    coeffs[:, :, m] = - coeffs[:, :, m]

        return coeffs
1124959
def _get_array(val, shape, default=None, dtype=np.float64):
    """"""
    assert val is not None or default is not None
    if hasattr(val, '__len__') and len(val) == 0:  # pragma: no cover
        val = None
    # Do nothing if the array is already correct.
    if (isinstance(val, np.ndarray) and
            val.shape == shape and
            val.dtype == dtype):
        return val
    out = np.zeros(shape, dtype=dtype)
    # This solves `ValueError: could not broadcast input array from shape (n)
    # into shape (n, 1)`.
    if val is not None and isinstance(val, np.ndarray):
        if val.size == out.size:
            val = val.reshape(out.shape)
    out.flat[:] = val if val is not None else default
    assert out.shape == shape
    return out
1335823
def normalize_to_unit_range(values):
    """"""
    if not isinstance(values, np.ndarray) or values.ndim != 1:
        raise ValueError('`values` must be a 1D NumPy array')

    if len(values) < 2:
        raise ValueError('`values` must contain at least two values')

    min_ = np.min(values)
    max_ = np.max(values)
    range_ = max_ - min_

    if range_ == 0:
        raise ValueError('range of `values` is 0 -- cannot normalize')

    return (values - min_) / range_
1069609
def one_hot(x, size, dtype=np.float32):
  """"""
  return np.array(x[..., np.newaxis] == np.arange(size), dtype)
1215655
def inflate_dtype(arr, names):
    """"""
    arr = np.asanyarray(arr)
    if has_structured_dt(arr):
        return arr.dtype
    s_dt = arr.dtype
    dt = [(n, s_dt) for n in names]
    dt = np.dtype(dt)
    return dt
1020092
def read_numpy(fd, byte_order, dtype, count):
    """"""
    return numpy.fromfile(fd, byte_order+dtype[-1], count)
9479
def is_float_array(l):
    

    """
    if isinstance(l, np.ndarray):
        if l.dtype.kind == 'f':
            return True
    return False
223588
def normalize_array(lst):
    
    np_arr = np.array(lst)
    x_normalized = np_arr / np_arr.max(axis=0)
    return list(x_normalized)
921114
def _convert_to_array(array_like, dtype):
        
        if isinstance(array_like, bytes):
            return np.frombuffer(array_like, dtype=dtype)
        return np.asarray(array_like, dtype=dtype)
1136783
def _rdump_value_to_numpy(s):
    
    if "structure" in s:
        vector_str, shape_str = re.findall(r'c\([^\)]+\)', s)
        shape = [int(d) for d in shape_str[2:-1].split(',')]
        if '.' in vector_str:
            arr = np.array([float(v) for v in vector_str[2:-1].split(',')])
        else:
            arr = np.array([int(v) for v in vector_str[2:-1].split(',')])
        # 'F' = Fortran, column-major
        arr = arr.reshape(shape, order='F')
    elif "c(" in s:
        if '.' in s:
            arr = np.array([float(v) for v in s[2:-1].split(',')], order='F')
        else:
            arr = np.array([int(v) for v in s[2:-1].split(',')], order='F')
    else:
        arr = np.array(float(s) if '.' in s else int(s))
    return arr
54627
def to_math_type(arr):
    
    max_int = np.iinfo(arr.dtype).max
    return arr.astype(math_type) / max_int
608723
def _convert_nptype(data_type, data):  # @NoSelf
        '''
        
        '''
        if data_type in (1, 41):
            return np.int8(data).tobytes()
        elif data_type == 2:
            return np.int16(data).tobytes()
        elif data_type == 4:
            return np.int32(data).tobytes()
        elif (data_type == 8) or (data_type == 33):
            return np.int64(data).tobytes()
        elif data_type == 11:
            return np.uint8(data).tobytes()
        elif data_type == 12:
            return np.uint16(data).tobytes()
        elif data_type == 14:
            return np.uint32(data).tobytes()
        elif (data_type == 21) or (data_type == 44):
            return np.float32(data).tobytes()
        elif (data_type == 22) or (data_type == 45) or (data_type == 31):
            return np.float64(data).tobytes()
        elif (data_type == 32):
            return np.complex128(data).tobytes()
        else:
            return data