OLD | NEW |
1 __docformat__ = "restructuredtext en" | 1 __docformat__ = "restructuredtext en" |
2 __all__ = ['logspace', 'linspace', | 2 __all__ = ['logspace', 'linspace', |
3 'select', 'piecewise', 'trim_zeros', | 3 'select', 'piecewise', 'trim_zeros', |
4 'copy', 'iterable', | 4 'copy', 'iterable', |
5 'diff', 'gradient', 'angle', 'unwrap', 'sort_complex', 'disp', | 5 'diff', 'gradient', 'angle', 'unwrap', 'sort_complex', 'disp', |
6 'unique', 'extract', 'place', 'nansum', 'nanmax', 'nanargmax', | 6 'unique', 'extract', 'place', 'nansum', 'nanmax', 'nanargmax', |
7 'nanargmin', 'nanmin', 'vectorize', 'asarray_chkfinite', 'average', | 7 'nanargmin', 'nanmin', 'vectorize', 'asarray_chkfinite', 'average', |
8 'histogram', 'histogramdd', 'bincount', 'digitize', 'cov', | 8 'histogram', 'histogramdd', 'bincount', 'digitize', 'cov', |
9 'corrcoef', 'msort', 'median', 'sinc', 'hamming', 'hanning', | 9 'corrcoef', 'msort', 'median', 'sinc', 'hamming', 'hanning', |
10 'bartlett', 'blackman', 'kaiser', 'trapz', 'i0', 'add_newdoc', | 10 'bartlett', 'blackman', 'kaiser', 'trapz', 'i0', 'add_newdoc', |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 |-- | 556 |-- |
557 | f1(x) for condition1 | 557 | f1(x) for condition1 |
558 y = --| f2(x) for condition2 | 558 y = --| f2(x) for condition2 |
559 | ... | 559 | ... |
560 | fn(x) for conditionn | 560 | fn(x) for conditionn |
561 |-- | 561 |-- |
562 | 562 |
563 """ | 563 """ |
564 x = asanyarray(x) | 564 x = asanyarray(x) |
565 n2 = len(funclist) | 565 n2 = len(funclist) |
566 if not isinstance(condlist, type([])): | 566 if not (isinstance(condlist[0], list) or |
| 567 isinstance(condlist[0], ndarray)): |
567 condlist = [condlist] | 568 condlist = [condlist] |
| 569 condlist = [asarray(c, dtype=bool) for c in condlist] |
568 n = len(condlist) | 570 n = len(condlist) |
569 if n == n2-1: # compute the "otherwise" condition. | 571 if n == n2-1: # compute the "otherwise" condition. |
570 totlist = condlist[0] | 572 totlist = condlist[0] |
571 for k in range(1, n): | 573 for k in range(1, n): |
572 totlist |= condlist[k] | 574 totlist |= condlist[k] |
573 condlist.append(~totlist) | 575 condlist.append(~totlist) |
574 n += 1 | 576 n += 1 |
575 if (n != n2): | 577 if (n != n2): |
576 raise ValueError, "function list and condition list must be the same" | 578 raise ValueError, "function list and condition list " \ |
577 y = empty(x.shape, x.dtype) | 579 "must have the same lengths" |
| 580 y = zeros(x.shape, x.dtype) |
578 for k in range(n): | 581 for k in range(n): |
579 item = funclist[k] | 582 item = funclist[k] |
580 if not callable(item): | 583 if not callable(item): |
581 y[condlist[k]] = item | 584 y[condlist[k]] = item |
582 else: | 585 else: |
583 y[condlist[k]] = item(x[condlist[k]], *args, **kw) | 586 y[condlist[k]] = item(x[condlist[k]], *args, **kw) |
584 return y | 587 return y |
585 | 588 |
586 def select(condlist, choicelist, default=0): | 589 def select(condlist, choicelist, default=0): |
587 """Return an array composed of different elements in choicelist, | 590 """Return an array composed of different elements in choicelist, |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 self.nin = None | 1068 self.nin = None |
1066 self.nin_wo_defaults = None | 1069 self.nin_wo_defaults = None |
1067 else: | 1070 else: |
1068 self.nin = nin | 1071 self.nin = nin |
1069 self.nin_wo_defaults = nin - ndefault | 1072 self.nin_wo_defaults = nin - ndefault |
1070 self.nout = None | 1073 self.nout = None |
1071 if doc is None: | 1074 if doc is None: |
1072 self.__doc__ = pyfunc.__doc__ | 1075 self.__doc__ = pyfunc.__doc__ |
1073 else: | 1076 else: |
1074 self.__doc__ = doc | 1077 self.__doc__ = doc |
1075 if isinstance(otypes, types.StringType): | 1078 if isinstance(otypes, str): |
1076 self.otypes = otypes | 1079 self.otypes = otypes |
1077 for char in self.otypes: | 1080 for char in self.otypes: |
1078 if char not in typecodes['All']: | 1081 if char not in typecodes['All']: |
1079 raise ValueError, "invalid otype specified" | 1082 raise ValueError, "invalid otype specified" |
1080 elif iterable(otypes): | 1083 elif iterable(otypes): |
1081 self.otypes = ''.join([_nx.dtype(x).char for x in otypes]) | 1084 self.otypes = ''.join([_nx.dtype(x).char for x in otypes]) |
1082 else: | 1085 else: |
1083 raise ValueError, "output types must be a string of typecode charact
ers or a list of data-types" | 1086 raise ValueError, "output types must be a string of typecode charact
ers or a list of data-types" |
1084 self.lastcallargs = 0 | 1087 self.lastcallargs = 0 |
1085 | 1088 |
(...skipping 10 matching lines...) Expand all Loading... |
1096 if (self.lastcallargs != nargs): | 1099 if (self.lastcallargs != nargs): |
1097 self.lastcallargs = nargs | 1100 self.lastcallargs = nargs |
1098 self.ufunc = None | 1101 self.ufunc = None |
1099 self.nout = None | 1102 self.nout = None |
1100 | 1103 |
1101 if self.nout is None or self.otypes == '': | 1104 if self.nout is None or self.otypes == '': |
1102 newargs = [] | 1105 newargs = [] |
1103 for arg in args: | 1106 for arg in args: |
1104 newargs.append(asarray(arg).flat[0]) | 1107 newargs.append(asarray(arg).flat[0]) |
1105 theout = self.thefunc(*newargs) | 1108 theout = self.thefunc(*newargs) |
1106 if isinstance(theout, types.TupleType): | 1109 if isinstance(theout, tuple): |
1107 self.nout = len(theout) | 1110 self.nout = len(theout) |
1108 else: | 1111 else: |
1109 self.nout = 1 | 1112 self.nout = 1 |
1110 theout = (theout,) | 1113 theout = (theout,) |
1111 if self.otypes == '': | 1114 if self.otypes == '': |
1112 otypes = [] | 1115 otypes = [] |
1113 for k in range(self.nout): | 1116 for k in range(self.nout): |
1114 otypes.append(asarray(theout[k]).dtype.char) | 1117 otypes.append(asarray(theout[k]).dtype.char) |
1115 self.otypes = ''.join(otypes) | 1118 self.otypes = ''.join(otypes) |
1116 | 1119 |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1798 def append(arr, values, axis=None): | 1801 def append(arr, values, axis=None): |
1799 """Append to the end of an array along axis (ravel first if None) | 1802 """Append to the end of an array along axis (ravel first if None) |
1800 """ | 1803 """ |
1801 arr = asanyarray(arr) | 1804 arr = asanyarray(arr) |
1802 if axis is None: | 1805 if axis is None: |
1803 if arr.ndim != 1: | 1806 if arr.ndim != 1: |
1804 arr = arr.ravel() | 1807 arr = arr.ravel() |
1805 values = ravel(values) | 1808 values = ravel(values) |
1806 axis = arr.ndim-1 | 1809 axis = arr.ndim-1 |
1807 return concatenate((arr, values), axis=axis) | 1810 return concatenate((arr, values), axis=axis) |
OLD | NEW |