diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/add_newdocs.py | 17 | ||||
-rw-r--r-- | numpy/core/fromnumeric.py | 11 | ||||
-rw-r--r-- | numpy/core/numeric.py | 4 | ||||
-rw-r--r-- | numpy/core/src/arraymethods.c | 19 | ||||
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 18 | ||||
-rw-r--r-- | numpy/core/src/scalartypes.inc.src | 4 | ||||
-rw-r--r-- | numpy/lib/shape_base.py | 6 | ||||
-rw-r--r-- | numpy/oldnumeric/misc.py | 12 |
8 files changed, 42 insertions, 49 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index 9feed132b..a9346c74f 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -878,18 +878,17 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('ptp', add_newdoc('numpy.core.multiarray', 'ndarray', ('put', - """a.put(values, indices, mode) sets a.flat[n] = values[n] for - each n in indices. v can be scalar or shorter than indices, and - it will repeat. - + """a.put(indices, values, mode) sets a.flat[n] = values[n] for + each n in indices. If values is shorter than indices then it + will repeat. """)) -add_newdoc('numpy.core.multiarray', 'ndarray', ('putmask', - """a.putmask(values, mask) sets a.flat[n] = v[n] for each n where - mask.flat[n] is true. v can be scalar. - - """)) +add_newdoc('numpy.core.multiarray', 'putmask', + """putmask(a, mask, values) sets a.flat[n] = values[n] for each n where + mask.flat[n] is true. If values is not the same size of a and mask then + it will repeat. This gives different behavior than a[mask] = values. + """) add_newdoc('numpy.core.multiarray', 'ndarray', ('ravel', diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 533f4a468..061b8bd9f 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1,7 +1,7 @@ # Module containing non-deprecated functions borrowed from Numeric. # functions that are now methods -__all__ = ['take', 'reshape', 'choose', 'repeat', 'put', 'putmask', +__all__ = ['take', 'reshape', 'choose', 'repeat', 'put', 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin', 'searchsorted', 'alen', 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape', @@ -94,14 +94,7 @@ def put (a, ind, v, mode='raise'): for i in ind: a.flat[i] = v[i] a must be a contiguous numpy array. """ - return a.put(v,ind, mode) - -def putmask (a, mask, v): - """putmask(a, mask, v) results in a = v for all places mask is true. - If v is shorter than mask it will be repeated as necessary. - In particular v can be a scalar or length 1 array. - """ - return a.putmask(v, mask) + return a.put(ind, v, mode) def swapaxes(a, axis1, axis2): """swapaxes(a, axis1, axis2) returns array a with axis1 and axis2 diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index d9959a167..19f0c1fb5 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -14,7 +14,7 @@ __all__ = ['newaxis', 'ndarray', 'flatiter', 'ufunc', 'fromiter', 'array_equal', 'array_equiv', 'indices', 'fromfunction', 'load', 'loads', 'isscalar', 'binary_repr', 'base_repr', - 'ones', 'identity', 'allclose', 'compare_chararrays', + 'ones', 'identity', 'allclose', 'compare_chararrays', 'putmask', 'seterr', 'geterr', 'setbufsize', 'getbufsize', 'seterrcall', 'geterrcall', 'flatnonzero', 'Inf', 'inf', 'infty', 'Infinity', @@ -120,7 +120,7 @@ set_numeric_ops = multiarray.set_numeric_ops can_cast = multiarray.can_cast lexsort = multiarray.lexsort compare_chararrays = multiarray.compare_chararrays - +putmask = multiarray.putmask def asarray(a, dtype=None, order=None): """Returns a as an array. diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c index f2ba3dd87..b7411ea8e 100644 --- a/numpy/core/src/arraymethods.c +++ b/numpy/core/src/arraymethods.c @@ -40,10 +40,10 @@ array_put(PyArrayObject *self, PyObject *args, PyObject *kwds) { PyObject *indices, *values; NPY_CLIPMODE mode=NPY_RAISE; - static char *kwlist[] = {"values", "indices", "mode", NULL}; + static char *kwlist[] = {"indices", "values", "mode", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O&", kwlist, - &values, &indices, + &indices, &values, PyArray_ClipmodeConverter, &mode)) return NULL; @@ -51,19 +51,6 @@ array_put(PyArrayObject *self, PyObject *args, PyObject *kwds) } static PyObject * -array_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) -{ - PyObject *mask, *values; - - static char *kwlist[] = {"values", "mask", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, - &values, &mask)) - return NULL; - return PyArray_PutMask(self, values, mask); -} - -static PyObject * array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds) { PyArray_Dims newshape; @@ -1827,8 +1814,6 @@ static PyMethodDef array_methods[] = { METH_VARARGS | METH_KEYWORDS, NULL}, {"put", (PyCFunction)array_put, METH_VARARGS | METH_KEYWORDS, NULL}, - {"putmask", (PyCFunction)array_putmask, - METH_VARARGS | METH_KEYWORDS, NULL}, {"ravel", (PyCFunction)array_ravel, METH_VARARGS, NULL}, {"repeat", (PyCFunction)array_repeat, diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index f34996986..50c1220d6 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -3648,6 +3648,22 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0, return NULL; } +static PyObject * +array_putmask(PyObject *module, PyObject *args, PyObject *kwds) +{ + PyObject *mask, *values; + PyObject *array; + + static char *kwlist[] = {"arr", "mask", "values", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!OO:putmask", kwlist, + &PyArray_Type, + &array, &mask, &values)) + return NULL; + + return PyArray_PutMask(array, values, mask); +} + /*MULTIARRAY_API Put values into an array according to a mask. */ @@ -6687,6 +6703,8 @@ static struct PyMethodDef array_module_methods[] = { METH_VARARGS, NULL}, {"lexsort", (PyCFunction)array_lexsort, METH_VARARGS | METH_KEYWORDS, NULL}, + {"putmask", (PyCFunction)array_putmask, + METH_VARARGS | METH_KEYWORDS, NULL}, {"fromstring",(PyCFunction)array_fromString, METH_VARARGS|METH_KEYWORDS, NULL}, {"fromiter",(PyCFunction)array_fromIter, diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src index 056a887d6..05e40313c 100644 --- a/numpy/core/src/scalartypes.inc.src +++ b/numpy/core/src/scalartypes.inc.src @@ -1122,7 +1122,7 @@ gentype_byteswap(PyObject *self, PyObject *args) /**begin repeat -#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize, reshape, choose# +#name=take, getfield, put, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize, reshape, choose# */ static PyObject * @@ -1331,8 +1331,6 @@ static PyMethodDef gentype_methods[] = { METH_VARARGS|METH_KEYWORDS, NULL}, {"put", (PyCFunction)gentype_put, METH_VARARGS|METH_KEYWORDS, NULL}, - {"putmask", (PyCFunction)gentype_putmask, - METH_VARARGS|METH_KEYWORDS, NULL}, {"repeat", (PyCFunction)gentype_repeat, METH_VARARGS|METH_KEYWORDS, NULL}, {"choose", (PyCFunction)gentype_choose, diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index fa03a5127..42fbc6e99 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -26,7 +26,7 @@ def apply_along_axis(func1d,axis,arr,*args): indlist.remove(axis) i[axis] = slice(None,None) outshape = asarray(arr.shape).take(indlist) - i.put(ind, indlist) + i.put(indlist, ind) res = func1d(arr[tuple(i.tolist())],*args) # if res is a number, then we have a smaller output array if isscalar(res): @@ -42,7 +42,7 @@ def apply_along_axis(func1d,axis,arr,*args): ind[n-1] += 1 ind[n] = 0 n -= 1 - i.put(ind,indlist) + i.put(indlist,ind) res = func1d(arr[tuple(i.tolist())],*args) outarr[ind] = res k += 1 @@ -63,7 +63,7 @@ def apply_along_axis(func1d,axis,arr,*args): ind[n-1] += 1 ind[n] = 0 n -= 1 - i.put(ind, indlist) + i.put(indlist, ind) res = func1d(arr[tuple(i.tolist())],*args) outarr[tuple(i.tolist())] = res k += 1 diff --git a/numpy/oldnumeric/misc.py b/numpy/oldnumeric/misc.py index d7938fcac..eb66e5806 100644 --- a/numpy/oldnumeric/misc.py +++ b/numpy/oldnumeric/misc.py @@ -1,12 +1,12 @@ # Functions that already have the correct syntax or miscellaneous functions -__all__ = ['load', 'sort', 'copy_reg', 'clip', 'putmask', 'Unpickler', 'rank', +__all__ = ['load', 'sort', 'copy_reg', 'clip', 'Unpickler', 'rank', 'sign', 'shape', 'types', 'allclose', 'size', 'choose', 'swapaxes', 'array_str', - 'pi', 'math', 'concatenate', + 'pi', 'math', 'concatenate', 'putmask', 'put', 'around', 'vdot', 'transpose', 'array2string', 'diagonal', - 'searchsorted', 'put', 'fromfunction', 'copy', 'resize', + 'searchsorted', 'fromfunction', 'copy', 'resize', 'array_repr', 'e', 'StringIO', 'pickle', 'argsort', 'convolve', 'loads', 'cross_correlate', 'Pickler', 'dot', 'outerproduct', 'innerproduct', 'insert'] @@ -19,10 +19,10 @@ import copy import copy_reg from pickle import load, loads -from numpy import sort, clip, putmask, rank, sign, shape, allclose, size,\ - choose, swapaxes, array_str, array_repr, e, pi, \ +from numpy import sort, clip, rank, sign, shape, putmask, allclose, size,\ + choose, swapaxes, array_str, array_repr, e, pi, put, \ fromfunction, resize, around, concatenate, vdot, transpose, \ - diagonal, searchsorted, put, argsort, convolve, dot, \ + diagonal, searchsorted, argsort, convolve, dot, \ outer as outerproduct, inner as innerproduct, correlate as cross_correlate, \ place as insert |