summaryrefslogtreecommitdiff
path: root/numpy/core/numeric.py
diff options
context:
space:
mode:
authorJoseph Fox-Rabinovitz <jfoxrabinovitz@gmail.com>2016-04-12 01:34:39 -0400
committerJoseph Fox-Rabinovitz <jfoxrabinovitz@gmail.com>2016-05-04 00:37:19 -0400
commit21d2fb78d4b6a094dcf81990b769a36e5d22e119 (patch)
tree08ac907d78d633a74393ff3ed49f045d1fee0f89 /numpy/core/numeric.py
parentf1b009112f07b57fde07b99129c1b118a6669f51 (diff)
downloadnumpy-21d2fb78d4b6a094dcf81990b769a36e5d22e119.tar.gz
MAINT: Cleanp of random stuff
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r--numpy/core/numeric.py121
1 files changed, 63 insertions, 58 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 11a95fa7b..b3eed9714 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -6,7 +6,20 @@ import operator
import sys
import warnings
-from numpy.core import multiarray
+from . import multiarray
+from .multiarray import (
+ _fastCopyAndTranspose as fastCopyAndTranspose, ALLOW_THREADS,
+ BUFSIZE, CLIP, MAXDIMS, MAY_SHARE_BOUNDS, MAY_SHARE_EXACT, RAISE,
+ WRAP, arange, array, broadcast, can_cast, compare_chararrays,
+ concatenate, copyto, count_nonzero, dot, dtype, einsum, empty,
+ empty_like, flatiter, frombuffer, fromfile, fromiter, fromstring,
+ inner, int_asbuffer, lexsort, matmul, may_share_memory,
+ min_scalar_type, ndarray, nditer, nested_iters, promote_types,
+ putmask, result_type, set_numeric_ops, shares_memory, vdot, where,
+ zeros)
+if sys.version_info[0] < 3:
+ from .multiarray import newbuffer, getbuffer
+
from . import umath
from .umath import (invert, sin, UFUNC_BUFSIZE_DEFAULT, ERR_IGNORE,
ERR_WARN, ERR_RAISE, ERR_CALL, ERR_PRINT, ERR_LOG,
@@ -15,6 +28,10 @@ from . import numerictypes
from .numerictypes import longlong, intc, int_, float_, complex_, bool_
from ._internal import TooHardError
+bitwise_not = invert
+ufunc = type(sin)
+newaxis = None
+
if sys.version_info[0] >= 3:
import pickle
basestring = str
@@ -50,6 +67,7 @@ __all__ = [
'TooHardError',
]
+
if sys.version_info[0] < 3:
__all__.extend(['getbuffer', 'newbuffer'])
@@ -64,26 +82,6 @@ class ComplexWarning(RuntimeWarning):
"""
pass
-bitwise_not = invert
-
-CLIP = multiarray.CLIP
-WRAP = multiarray.WRAP
-RAISE = multiarray.RAISE
-MAXDIMS = multiarray.MAXDIMS
-ALLOW_THREADS = multiarray.ALLOW_THREADS
-BUFSIZE = multiarray.BUFSIZE
-MAY_SHARE_BOUNDS = multiarray.MAY_SHARE_BOUNDS
-MAY_SHARE_EXACT = multiarray.MAY_SHARE_EXACT
-
-ndarray = multiarray.ndarray
-flatiter = multiarray.flatiter
-nditer = multiarray.nditer
-nested_iters = multiarray.nested_iters
-broadcast = multiarray.broadcast
-dtype = multiarray.dtype
-copyto = multiarray.copyto
-ufunc = type(sin)
-
def zeros_like(a, dtype=None, order='K', subok=True):
"""
@@ -147,6 +145,7 @@ def zeros_like(a, dtype=None, order='K', subok=True):
multiarray.copyto(res, z, casting='unsafe')
return res
+
def ones(shape, dtype=None, order='C'):
"""
Return a new array of given shape and type, filled with ones.
@@ -193,6 +192,7 @@ def ones(shape, dtype=None, order='C'):
multiarray.copyto(a, 1, casting='unsafe')
return a
+
def ones_like(a, dtype=None, order='K', subok=True):
"""
Return an array of ones with the same shape and type as a given array.
@@ -253,6 +253,7 @@ def ones_like(a, dtype=None, order='K', subok=True):
multiarray.copyto(res, 1, casting='unsafe')
return res
+
def full(shape, fill_value, dtype=None, order='C'):
"""
Return a new array of given shape and type, filled with `fill_value`.
@@ -301,6 +302,7 @@ def full(shape, fill_value, dtype=None, order='C'):
multiarray.copyto(a, fill_value, casting='unsafe')
return a
+
def full_like(a, fill_value, dtype=None, order='K', subok=True):
"""
Return a full array with the same shape and type as a given array.
@@ -373,42 +375,6 @@ def extend_all(module):
if a not in adict:
__all__.append(a)
-newaxis = None
-
-
-arange = multiarray.arange
-array = multiarray.array
-zeros = multiarray.zeros
-count_nonzero = multiarray.count_nonzero
-empty = multiarray.empty
-empty_like = multiarray.empty_like
-fromstring = multiarray.fromstring
-fromiter = multiarray.fromiter
-fromfile = multiarray.fromfile
-frombuffer = multiarray.frombuffer
-shares_memory = multiarray.shares_memory
-may_share_memory = multiarray.may_share_memory
-if sys.version_info[0] < 3:
- newbuffer = multiarray.newbuffer
- getbuffer = multiarray.getbuffer
-int_asbuffer = multiarray.int_asbuffer
-where = multiarray.where
-concatenate = multiarray.concatenate
-fastCopyAndTranspose = multiarray._fastCopyAndTranspose
-set_numeric_ops = multiarray.set_numeric_ops
-can_cast = multiarray.can_cast
-promote_types = multiarray.promote_types
-min_scalar_type = multiarray.min_scalar_type
-result_type = multiarray.result_type
-lexsort = multiarray.lexsort
-compare_chararrays = multiarray.compare_chararrays
-putmask = multiarray.putmask
-einsum = multiarray.einsum
-dot = multiarray.dot
-inner = multiarray.inner
-vdot = multiarray.vdot
-matmul = multiarray.matmul
-
def asarray(a, dtype=None, order=None):
"""Convert the input to an array.
@@ -480,6 +446,7 @@ def asarray(a, dtype=None, order=None):
"""
return array(a, dtype, copy=False, order=order)
+
def asanyarray(a, dtype=None, order=None):
"""Convert the input to an ndarray, but pass ndarray subclasses through.
@@ -531,6 +498,7 @@ def asanyarray(a, dtype=None, order=None):
"""
return array(a, dtype, copy=False, order=order, subok=True)
+
def ascontiguousarray(a, dtype=None):
"""
Return a contiguous array in memory (C order).
@@ -567,6 +535,7 @@ def ascontiguousarray(a, dtype=None):
"""
return array(a, dtype, copy=False, order='C', ndmin=1)
+
def asfortranarray(a, dtype=None):
"""
Return an array laid out in Fortran order in memory.
@@ -603,6 +572,7 @@ def asfortranarray(a, dtype=None):
"""
return array(a, dtype, copy=False, order='F', ndmin=1)
+
def require(a, dtype=None, requirements=None):
"""
Return an ndarray of the provided type that satisfies requirements.
@@ -698,6 +668,7 @@ def require(a, dtype=None, requirements=None):
break
return arr
+
def isfortran(a):
"""
Returns True if the array is Fortran contiguous but *not* C contiguous.
@@ -759,6 +730,7 @@ def isfortran(a):
"""
return a.flags.fnc
+
def argwhere(a):
"""
Find the indices of array elements that are non-zero, grouped by element.
@@ -799,6 +771,7 @@ def argwhere(a):
"""
return transpose(nonzero(a))
+
def flatnonzero(a):
"""
Return indices that are non-zero in the flattened version of a.
@@ -838,15 +811,18 @@ def flatnonzero(a):
"""
return a.ravel().nonzero()[0]
+
_mode_from_name_dict = {'v': 0,
's': 1,
'f': 2}
+
def _mode_from_name(mode):
if isinstance(mode, basestring):
return _mode_from_name_dict[mode.lower()[0]]
return mode
+
def correlate(a, v, mode='valid'):
"""
Cross-correlation of two 1-dimensional sequences.
@@ -914,6 +890,7 @@ def correlate(a, v, mode='valid'):
mode = _mode_from_name(mode)
return multiarray.correlate2(a, v, mode)
+
def convolve(a,v,mode='full'):
"""
Returns the discrete, linear convolution of two one-dimensional sequences.
@@ -1011,6 +988,7 @@ def convolve(a,v,mode='full'):
mode = _mode_from_name(mode)
return multiarray.correlate(a, v[::-1], mode)
+
def outer(a, b, out=None):
"""
Compute the outer product of two vectors.
@@ -1331,6 +1309,7 @@ def tensordot(a, b, axes=2):
res = dot(at, bt)
return res.reshape(olda + oldb)
+
def roll(a, shift, axis=None):
"""
Roll array elements along a given axis.
@@ -1571,6 +1550,7 @@ def moveaxis(a, source, destination):
def _move_axis_to_0(a, axis):
return rollaxis(a, axis, 0)
+
def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None):
"""
Return the cross product of two (arrays of) vectors.
@@ -1771,16 +1751,20 @@ def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None):
# This works because we are moving the last axis
return rollaxis(cp, -1, axisc)
+
#Use numarray's printing function
from .arrayprint import array2string, get_printoptions, set_printoptions
+
_typelessdata = [int_, float_, complex_]
if issubclass(intc, int):
_typelessdata.append(intc)
+
if issubclass(longlong, int):
_typelessdata.append(longlong)
+
def array_repr(arr, max_line_width=None, precision=None, suppress_small=None):
"""
Return the string representation of an array.
@@ -1853,6 +1837,7 @@ def array_repr(arr, max_line_width=None, precision=None, suppress_small=None):
lf = '\n'+' '*len("array(")
return cName + "(%s, %sdtype=%s)" % (lst, lf, typename)
+
def array_str(a, max_line_width=None, precision=None, suppress_small=None):
"""
Return a string representation of the data in an array.
@@ -1889,6 +1874,7 @@ def array_str(a, max_line_width=None, precision=None, suppress_small=None):
"""
return array2string(a, max_line_width, precision, suppress_small, ' ', "", str)
+
def set_string_function(f, repr=True):
"""
Set a Python function to be used when pretty printing arrays.
@@ -1948,6 +1934,7 @@ def set_string_function(f, repr=True):
else:
return multiarray.set_string_function(f, repr)
+
set_string_function(array_str, 0)
set_string_function(array_repr, 1)
@@ -2027,6 +2014,7 @@ def indices(dimensions, dtype=int):
add(tmp, val, res[i])
return res
+
def fromfunction(function, shape, **kwargs):
"""
Construct an array by executing a function over each coordinate.
@@ -2080,7 +2068,8 @@ def fromfunction(function, shape, **kwargs):
"""
dtype = kwargs.pop('dtype', float)
args = indices(shape, dtype=dtype)
- return function(*args,**kwargs)
+ return function(*args, **kwargs)
+
def isscalar(num):
"""
@@ -2111,6 +2100,7 @@ def isscalar(num):
else:
return type(num) in ScalarType
+
def binary_repr(num, width=None):
"""
Return the binary representation of the input number as a string.
@@ -2214,6 +2204,7 @@ def binary_repr(num, width=None):
warn_if_insufficient(width, binwidth)
return '1' * (outwidth - binwidth) + binary
+
def base_repr(number, base=2, padding=0):
"""
Return a string representation of a number in the given base system.
@@ -2288,6 +2279,7 @@ def load(file):
file = open(file, "rb")
return pickle.load(file)
+
# These are all essentially abbreviations
# These might wind up in a special abbreviations module
@@ -2301,6 +2293,7 @@ def _maketup(descr, val):
res = [_maketup(fields[name][0], val) for name in dt.names]
return tuple(res)
+
def identity(n, dtype=None):
"""
Return the identity array.
@@ -2332,6 +2325,7 @@ def identity(n, dtype=None):
from numpy import eye
return eye(n, dtype=dtype)
+
def allclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
"""
Returns True if two arrays are element-wise equal within a tolerance.
@@ -2397,6 +2391,7 @@ def allclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
return bool(res)
+
def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
"""
Returns a boolean array where two arrays are element-wise equal within a
@@ -2498,6 +2493,7 @@ def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
else:
return cond
+
def array_equal(a1, a2):
"""
True if two arrays have the same shape and elements, False otherwise.
@@ -2539,6 +2535,7 @@ def array_equal(a1, a2):
return False
return bool(asarray(a1 == a2).all())
+
def array_equiv(a1, a2):
"""
Returns True if input arrays are shape consistent and all elements equal.
@@ -2598,6 +2595,7 @@ for key in _errdict.keys():
_errdict_rev[_errdict[key]] = key
del key
+
def seterr(all=None, divide=None, over=None, under=None, invalid=None):
"""
Set how floating-point errors are handled.
@@ -2748,6 +2746,7 @@ def geterr():
res['invalid'] = _errdict_rev[val]
return res
+
def setbufsize(size):
"""
Set the size of the buffer used in ufuncs.
@@ -2771,6 +2770,7 @@ def setbufsize(size):
umath.seterrobj(pyvals)
return old
+
def getbufsize():
"""
Return the size of the buffer used in ufuncs.
@@ -2783,6 +2783,7 @@ def getbufsize():
"""
return umath.geterrobj()[0]
+
def seterrcall(func):
"""
Set the floating-point error callback function or log object.
@@ -2874,6 +2875,7 @@ def seterrcall(func):
umath.seterrobj(pyvals)
return old
+
def geterrcall():
"""
Return the current callback function used on floating-point errors.
@@ -2918,10 +2920,12 @@ def geterrcall():
"""
return umath.geterrobj()[2]
+
class _unspecified(object):
pass
_Unspecified = _unspecified()
+
class errstate(object):
"""
errstate(**kwargs)
@@ -3004,6 +3008,7 @@ def _setdef():
defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT, None]
umath.seterrobj(defval)
+
# set the default values
_setdef()