File indexing completed on 2024-04-28 15:53:59
0001 class getset_descriptor: pass 0002 class dictproxy: pass 0003 class member_descriptor: pass 0004 ALLOW_THREADS = int() 0005 BUFSIZE = int() 0006 CLIP = int() 0007 class ComplexWarning: 0008 __dict__ = dictproxy() 0009 __doc__ = str() 0010 __module__ = str() 0011 __weakref__ = getset_descriptor() 0012 args = getset_descriptor() 0013 message = getset_descriptor() 0014 class DataSource: 0015 __dict__ = dictproxy() 0016 __doc__ = str() 0017 __module__ = str() 0018 __weakref__ = getset_descriptor() 0019 def _cache(self, _): 0020 """Cache the file specified by path. 0021 0022 Creates a copy of the file in the datasource cache. 0023 0024 """ 0025 return None 0026 def _findfile(self, _): 0027 """Searches for ``path`` and returns full path if found. 0028 0029 If path is an URL, _findfile will cache a local copy and return 0030 the path to the cached file. 0031 If path is a local file, _findfile will return a path to that local 0032 file. 0033 0034 The search will include possible compressed versions of the file and 0035 return the first occurrence found. 0036 0037 """ 0038 return None 0039 def _isurl(self, _): 0040 """Test if path is a net location. Tests the scheme and netloc.""" 0041 return None 0042 def _iswritemode(self, _): 0043 """Test if the given mode will open a file for writing.""" 0044 return None 0045 def _iszip(self, _): 0046 """Test if the filename is a zip file by looking at the file extension. 0047 """ 0048 return None 0049 def _possible_names(self, _): 0050 """Return a tuple containing compressed filename variations.""" 0051 return None 0052 def _sanitize_relative_path(self, _): 0053 """Return a sanitised relative path for which 0054 os.path.abspath(os.path.join(base, path)).startswith(base) 0055 """ 0056 return None 0057 def _splitzipext(self, _): 0058 """Split zip extension from filename and return filename. 0059 0060 *Returns*: 0061 base, zip_ext : {tuple} 0062 0063 """ 0064 return None 0065 def abspath(self, path): 0066 """ 0067 Return absolute path of file in the DataSource directory. 0068 0069 If `path` is an URL, then `abspath` will return either the location 0070 the file exists locally or the location it would exist when opened 0071 using the `open` method. 0072 0073 Parameters 0074 ---------- 0075 path : str 0076 Can be a local file or a remote URL. 0077 0078 Returns 0079 ------- 0080 out : str 0081 Complete path, including the `DataSource` destination directory. 0082 0083 Notes 0084 ----- 0085 The functionality is based on `os.path.abspath`. 0086 0087 """ 0088 return str() 0089 def exists(self, path): 0090 """ 0091 Test if path exists. 0092 0093 Test if `path` exists as (and in this order): 0094 0095 - a local file. 0096 - a remote URL that has been downloaded and stored locally in the 0097 `DataSource` directory. 0098 - a remote URL that has not been downloaded, but is valid and accessible. 0099 0100 Parameters 0101 ---------- 0102 path : str 0103 Can be a local file or a remote URL. 0104 0105 Returns 0106 ------- 0107 out : bool 0108 True if `path` exists. 0109 0110 Notes 0111 ----- 0112 When `path` is an URL, `exists` will return True if it's either stored 0113 locally in the `DataSource` directory, or is a valid remote URL. 0114 `DataSource` does not discriminate between the two, the file is accessible 0115 if it exists in either location. 0116 0117 """ 0118 return bool() 0119 def open(self, path="r", mode="r"): 0120 """ 0121 Open and return file-like object. 0122 0123 If `path` is an URL, it will be downloaded, stored in the `DataSource` 0124 directory and opened from there. 0125 0126 Parameters 0127 ---------- 0128 path : str 0129 Local file path or URL to open. 0130 mode : {'r', 'w', 'a'}, optional 0131 Mode to open `path`. Mode 'r' for reading, 'w' for writing, 'a' to 0132 append. Available modes depend on the type of object specified by 0133 `path`. Default is 'r'. 0134 0135 Returns 0136 ------- 0137 out : file object 0138 File object. 0139 0140 """ 0141 return file() 0142 ERR_CALL = int() 0143 ERR_DEFAULT = int() 0144 ERR_DEFAULT2 = int() 0145 ERR_IGNORE = int() 0146 ERR_LOG = int() 0147 ERR_PRINT = int() 0148 ERR_RAISE = int() 0149 ERR_WARN = int() 0150 FLOATING_POINT_SUPPORT = int() 0151 FPE_DIVIDEBYZERO = int() 0152 FPE_INVALID = int() 0153 FPE_OVERFLOW = int() 0154 FPE_UNDERFLOW = int() 0155 False_ = bool_() 0156 Inf = float() 0157 Infinity = float() 0158 MAXDIMS = int() 0159 class MachAr: 0160 __dict__ = dictproxy() 0161 __doc__ = str() 0162 __module__ = str() 0163 __weakref__ = getset_descriptor() 0164 def _do_init(self, _): 0165 """None""" 0166 return None 0167 class ModuleDeprecationWarning: 0168 __dict__ = dictproxy() 0169 __doc__ = str() 0170 __module__ = str() 0171 __weakref__ = getset_descriptor() 0172 args = getset_descriptor() 0173 message = getset_descriptor() 0174 NAN = float() 0175 NINF = float() 0176 NZERO = float() 0177 NaN = float() 0178 PINF = float() 0179 PZERO = float() 0180 class PackageLoader: 0181 __dict__ = dictproxy() 0182 __doc__ = None 0183 __module__ = str() 0184 __weakref__ = getset_descriptor() 0185 def _execcmd(self, _): 0186 """ Execute command in parent_frame.""" 0187 return None 0188 def _format_titles(self, titles="---", colsep="---"): 0189 """None""" 0190 return None 0191 def _get_doc_title(self, _): 0192 """ Get the title from a package info.py file. 0193 """ 0194 return None 0195 def _get_info_files(self, package_dir, parent_path=None, parent_package=None): 0196 """ Return list of (package name,info.py file) from parent_path subdirectories. 0197 """ 0198 return None 0199 def _get_sorted_names(self, _): 0200 """ Return package names sorted in the order as they should be 0201 imported due to dependence relations between packages. 0202 """ 0203 return None 0204 def _init_info_modules(self=None, packages=None): 0205 """Initialize info_modules = {<package_name>: <package info.py module>}. 0206 """ 0207 return None 0208 def _obj2repr(self, obj): 0209 """ Return repr(obj) with""" 0210 return None 0211 def error(self, _): 0212 """None""" 0213 return None 0214 def get_pkgdocs(self, _): 0215 """ Return documentation summary of subpackages. 0216 """ 0217 return None 0218 def log(self, _): 0219 """None""" 0220 return None 0221 def warn(self, _): 0222 """None""" 0223 return None 0224 RAISE = int() 0225 class RankWarning: 0226 __dict__ = dictproxy() 0227 __doc__ = str() 0228 __module__ = str() 0229 __weakref__ = getset_descriptor() 0230 args = getset_descriptor() 0231 message = getset_descriptor() 0232 SHIFT_DIVIDEBYZERO = int() 0233 SHIFT_INVALID = int() 0234 SHIFT_OVERFLOW = int() 0235 SHIFT_UNDERFLOW = int() 0236 ScalarType = tuple() 0237 class NoseTester: 0238 __dict__ = dictproxy() 0239 __doc__ = str() 0240 __module__ = str() 0241 __weakref__ = getset_descriptor() 0242 def _get_custom_doctester(self, _): 0243 """ Return instantiated plugin for doctests 0244 0245 Allows subclassing of this class to override doctester 0246 0247 A return value of None means use the nose builtin doctest plugin 0248 """ 0249 return None 0250 def _show_system_info(self, _): 0251 """None""" 0252 return None 0253 def _test_argv(self, label, verbose, extra_argv): 0254 """ Generate argv for nosetest command 0255 0256 Parameters 0257 ---------- 0258 label : {'fast', 'full', '', attribute identifier}, optional 0259 see ``test`` docstring 0260 verbose : int, optional 0261 Verbosity value for test outputs, in the range 1-10. Default is 1. 0262 extra_argv : list, optional 0263 List with any extra arguments to pass to nosetests. 0264 0265 Returns 0266 ------- 0267 argv : list 0268 command line arguments that will be passed to nose 0269 """ 0270 return list() 0271 def bench(self=None, label="fast", verbose=1, extra_argv=None): 0272 """ 0273 Run benchmarks for module using nose. 0274 0275 Parameters 0276 ---------- 0277 label : {'fast', 'full', '', attribute identifier}, optional 0278 Identifies the benchmarks to run. This can be a string to pass to 0279 the nosetests executable with the '-A' option, or one of several 0280 special values. Special values are: 0281 * 'fast' - the default - which corresponds to the ``nosetests -A`` 0282 option of 'not slow'. 0283 * 'full' - fast (as above) and slow benchmarks as in the 0284 'no -A' option to nosetests - this is the same as ''. 0285 * None or '' - run all tests. 0286 attribute_identifier - string passed directly to nosetests as '-A'. 0287 verbose : int, optional 0288 Verbosity value for benchmark outputs, in the range 1-10. Default is 1. 0289 extra_argv : list, optional 0290 List with any extra arguments to pass to nosetests. 0291 0292 Returns 0293 ------- 0294 success : bool 0295 Returns True if running the benchmarks works, False if an error 0296 occurred. 0297 0298 Notes 0299 ----- 0300 Benchmarks are like tests, but have names starting with "bench" instead 0301 of "test", and can be found under the "benchmarks" sub-directory of the 0302 module. 0303 0304 Each NumPy module exposes `bench` in its namespace to run all benchmarks 0305 for it. 0306 0307 Examples 0308 -------- 0309 >>> success = np.lib.bench() #doctest: +SKIP 0310 Running benchmarks for numpy.lib 0311 ... 0312 using 562341 items: 0313 unique: 0314 0.11 0315 unique1d: 0316 0.11 0317 ratio: 1.0 0318 nUnique: 56230 == 56230 0319 ... 0320 OK 0321 0322 >>> success #doctest: +SKIP 0323 True 0324 0325 """ 0326 return bool() 0327 excludes = list() 0328 def prepare_test_args(self=False, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False): 0329 """ 0330 Run tests for module using nose. 0331 0332 This method does the heavy lifting for the `test` method. It takes all 0333 the same arguments, for details see `test`. 0334 0335 See Also 0336 -------- 0337 test 0338 0339 """ 0340 return None 0341 def test(self=None, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None): 0342 """ 0343 Run tests for module using nose. 0344 0345 Parameters 0346 ---------- 0347 label : {'fast', 'full', '', attribute identifier}, optional 0348 Identifies the tests to run. This can be a string to pass to 0349 the nosetests executable with the '-A' option, or one of several 0350 special values. Special values are: 0351 * 'fast' - the default - which corresponds to the ``nosetests -A`` 0352 option of 'not slow'. 0353 * 'full' - fast (as above) and slow tests as in the 0354 'no -A' option to nosetests - this is the same as ''. 0355 * None or '' - run all tests. 0356 attribute_identifier - string passed directly to nosetests as '-A'. 0357 verbose : int, optional 0358 Verbosity value for test outputs, in the range 1-10. Default is 1. 0359 extra_argv : list, optional 0360 List with any extra arguments to pass to nosetests. 0361 doctests : bool, optional 0362 If True, run doctests in module. Default is False. 0363 coverage : bool, optional 0364 If True, report coverage of NumPy code. Default is False. 0365 (This requires the `coverage module: 0366 <http://nedbatchelder.com/code/modules/coverage.html>`_). 0367 raise_warnings : str or sequence of warnings, optional 0368 This specifies which warnings to configure as 'raise' instead 0369 of 'warn' during the test execution. Valid strings are: 0370 0371 - "develop" : equals ``(DeprecationWarning, RuntimeWarning)`` 0372 - "release" : equals ``()``, don't raise on any warnings. 0373 0374 Returns 0375 ------- 0376 result : object 0377 Returns the result of running the tests as a 0378 ``nose.result.TextTestResult`` object. 0379 0380 Notes 0381 ----- 0382 Each NumPy module exposes `test` in its namespace to run all tests for it. 0383 For example, to run all tests for numpy.lib: 0384 0385 >>> np.lib.test() #doctest: +SKIP 0386 0387 Examples 0388 -------- 0389 >>> result = np.lib.test() #doctest: +SKIP 0390 Running unit tests for numpy.lib 0391 ... 0392 Ran 976 tests in 3.933s 0393 0394 OK 0395 0396 >>> result.errors #doctest: +SKIP 0397 [] 0398 >>> result.knownfail #doctest: +SKIP 0399 [] 0400 """ 0401 return object() 0402 True_ = bool_() 0403 UFUNC_BUFSIZE_DEFAULT = int() 0404 UFUNC_PYVALS_NAME = str() 0405 WRAP = int() 0406 __NUMPY_SETUP__ = bool() 0407 __all__ = list() 0408 __builtins__ = dict() 0409 __doc__ = str() 0410 __file__ = str() 0411 __git_revision__ = str() 0412 __name__ = str() 0413 __package__ = str() 0414 __path__ = list() 0415 __version__ = str() 0416 def absolute(x, out=None): 0417 """absolute(x[, out]) 0418 0419 Calculate the absolute value element-wise. 0420 0421 Parameters 0422 ---------- 0423 x : array_like 0424 Input array. 0425 0426 Returns 0427 ------- 0428 absolute : ndarray 0429 An ndarray containing the absolute value of 0430 each element in `x`. For complex input, ``a + ib``, the 0431 absolute value is :math:`\sqrt{ a^2 + b^2 }`. 0432 0433 Examples 0434 -------- 0435 >>> x = np.array([-1.2, 1.2]) 0436 >>> np.absolute(x) 0437 array([ 1.2, 1.2]) 0438 >>> np.absolute(1.2 + 1j) 0439 1.5620499351813308 0440 0441 Plot the function over ``[-10, 10]``: 0442 0443 >>> import matplotlib.pyplot as plt 0444 0445 >>> x = np.linspace(start=-10, stop=10, num=101) 0446 >>> plt.plot(x, np.absolute(x)) 0447 >>> plt.show() 0448 0449 Plot the function over the complex plane: 0450 0451 >>> xx = x + 1j * x[:, np.newaxis] 0452 >>> plt.imshow(np.abs(xx), extent=[-10, 10, -10, 10]) 0453 >>> plt.show()""" 0454 return ndarray() 0455 def absolute(x, out=None): 0456 """absolute(x[, out]) 0457 0458 Calculate the absolute value element-wise. 0459 0460 Parameters 0461 ---------- 0462 x : array_like 0463 Input array. 0464 0465 Returns 0466 ------- 0467 absolute : ndarray 0468 An ndarray containing the absolute value of 0469 each element in `x`. For complex input, ``a + ib``, the 0470 absolute value is :math:`\sqrt{ a^2 + b^2 }`. 0471 0472 Examples 0473 -------- 0474 >>> x = np.array([-1.2, 1.2]) 0475 >>> np.absolute(x) 0476 array([ 1.2, 1.2]) 0477 >>> np.absolute(1.2 + 1j) 0478 1.5620499351813308 0479 0480 Plot the function over ``[-10, 10]``: 0481 0482 >>> import matplotlib.pyplot as plt 0483 0484 >>> x = np.linspace(start=-10, stop=10, num=101) 0485 >>> plt.plot(x, np.absolute(x)) 0486 >>> plt.show() 0487 0488 Plot the function over the complex plane: 0489 0490 >>> xx = x + 1j * x[:, np.newaxis] 0491 >>> plt.imshow(np.abs(xx), extent=[-10, 10, -10, 10]) 0492 >>> plt.show()""" 0493 return ndarray() 0494 absolute_import = instance() 0495 def add(x1, x2, out=None): 0496 """add(x1, x2[, out]) 0497 0498 Add arguments element-wise. 0499 0500 Parameters 0501 ---------- 0502 x1, x2 : array_like 0503 The arrays to be added. If ``x1.shape != x2.shape``, they must be 0504 broadcastable to a common shape (which may be the shape of one or 0505 the other). 0506 0507 Returns 0508 ------- 0509 add : ndarray or scalar 0510 The sum of `x1` and `x2`, element-wise. Returns a scalar if 0511 both `x1` and `x2` are scalars. 0512 0513 Notes 0514 ----- 0515 Equivalent to `x1` + `x2` in terms of array broadcasting. 0516 0517 Examples 0518 -------- 0519 >>> np.add(1.0, 4.0) 0520 5.0 0521 >>> x1 = np.arange(9.0).reshape((3, 3)) 0522 >>> x2 = np.arange(3.0) 0523 >>> np.add(x1, x2) 0524 array([[ 0., 2., 4.], 0525 [ 3., 5., 7.], 0526 [ 6., 8., 10.]])""" 0527 return ndarray() if False else float() 0528 def add_docstring(obj, docstring): 0529 """add_docstring(obj, docstring) 0530 0531 Add a docstring to a built-in obj if possible. 0532 If the obj already has a docstring raise a RuntimeError 0533 If this routine does not know how to add a docstring to the object 0534 raise a TypeError""" 0535 return None 0536 def add_newdoc(): 0537 """Adds documentation to obj which is in module place. 0538 0539 If doc is a string add it to obj as a docstring 0540 0541 If doc is a tuple, then the first element is interpreted as 0542 an attribute of obj and the second as the docstring 0543 (method, docstring) 0544 0545 If doc is a list, then each element of the list should be a 0546 sequence of length two --> [(method1, docstring1), 0547 (method2, docstring2), ...] 0548 0549 This routine never raises an error. 0550 0551 This routine cannot modify read-only docstrings, as appear 0552 in new-style classes or built-in functions. Because this 0553 routine never raises an error the caller must check manually 0554 that the docstrings were changed. 0555 """ 0556 return None 0557 def add_newdoc_ufunc(ufunc, new_docstring): 0558 """add_ufunc_docstring(ufunc, new_docstring) 0559 0560 Replace the docstring for a ufunc with new_docstring. 0561 This method will only work if the current docstring for 0562 the ufunc is NULL. (At the C level, i.e. when ufunc->doc is NULL.) 0563 0564 Parameters 0565 ---------- 0566 ufunc : numpy.ufunc 0567 A ufunc whose current doc is NULL. 0568 new_docstring : string 0569 The new docstring for the ufunc. 0570 0571 Notes 0572 ----- 0573 This method allocates memory for new_docstring on 0574 the heap. Technically this creates a mempory leak, since this 0575 memory will not be reclaimed until the end of the program 0576 even if the ufunc itself is removed. However this will only 0577 be a problem if the user is repeatedly creating ufuncs with 0578 no documentation, adding documentation via add_newdoc_ufunc, 0579 and then throwing away the ufunc.""" 0580 return None 0581 def alen(a): 0582 """ 0583 Return the length of the first dimension of the input array. 0584 0585 Parameters 0586 ---------- 0587 a : array_like 0588 Input array. 0589 0590 Returns 0591 ------- 0592 alen : int 0593 Length of the first dimension of `a`. 0594 0595 See Also 0596 -------- 0597 shape, size 0598 0599 Examples 0600 -------- 0601 >>> a = np.zeros((7,4,5)) 0602 >>> a.shape[0] 0603 7 0604 >>> np.alen(a) 0605 7 0606 0607 """ 0608 return int() 0609 def all(a=False, axis=None, out=None, keepdims=False): 0610 """ 0611 Test whether all array elements along a given axis evaluate to True. 0612 0613 Parameters 0614 ---------- 0615 a : array_like 0616 Input array or object that can be converted to an array. 0617 axis : None or int or tuple of ints, optional 0618 Axis or axes along which a logical AND reduction is performed. 0619 The default (`axis` = `None`) is perform a logical OR over all 0620 the dimensions of the input array. `axis` may be negative, in 0621 which case it counts from the last to the first axis. 0622 0623 .. versionadded:: 1.7.0 0624 0625 If this is a tuple of ints, a reduction is performed on multiple 0626 axes, instead of a single axis or all the axes as before. 0627 out : ndarray, optional 0628 Alternate output array in which to place the result. 0629 It must have the same shape as the expected output and its 0630 type is preserved (e.g., if ``dtype(out)`` is float, the result 0631 will consist of 0.0's and 1.0's). See `doc.ufuncs` (Section 0632 "Output arguments") for more details. 0633 keepdims : bool, optional 0634 If this is set to True, the axes which are reduced are left 0635 in the result as dimensions with size one. With this option, 0636 the result will broadcast correctly against the original `arr`. 0637 0638 Returns 0639 ------- 0640 all : ndarray, bool 0641 A new boolean or array is returned unless `out` is specified, 0642 in which case a reference to `out` is returned. 0643 0644 See Also 0645 -------- 0646 ndarray.all : equivalent method 0647 0648 any : Test whether any element along a given axis evaluates to True. 0649 0650 Notes 0651 ----- 0652 Not a Number (NaN), positive infinity and negative infinity 0653 evaluate to `True` because these are not equal to zero. 0654 0655 Examples 0656 -------- 0657 >>> np.all([[True,False],[True,True]]) 0658 False 0659 0660 >>> np.all([[True,False],[True,True]], axis=0) 0661 array([ True, False], dtype=bool) 0662 0663 >>> np.all([-1, 4, 5]) 0664 True 0665 0666 >>> np.all([1.0, np.nan]) 0667 True 0668 0669 >>> o=np.array([False]) 0670 >>> z=np.all([-1, 4, 5], out=o) 0671 >>> id(z), id(o), z # doctest: +SKIP 0672 (28293632, 28293632, array([ True], dtype=bool)) 0673 0674 """ 0675 return ndarray() 0676 def allclose(a, b=1e-08, rtol=1e-05, atol=1e-08): 0677 """ 0678 Returns True if two arrays are element-wise equal within a tolerance. 0679 0680 The tolerance values are positive, typically very small numbers. The 0681 relative difference (`rtol` * abs(`b`)) and the absolute difference 0682 `atol` are added together to compare against the absolute difference 0683 between `a` and `b`. 0684 0685 If either array contains one or more NaNs, False is returned. 0686 Infs are treated as equal if they are in the same place and of the same 0687 sign in both arrays. 0688 0689 Parameters 0690 ---------- 0691 a, b : array_like 0692 Input arrays to compare. 0693 rtol : float 0694 The relative tolerance parameter (see Notes). 0695 atol : float 0696 The absolute tolerance parameter (see Notes). 0697 0698 Returns 0699 ------- 0700 allclose : bool 0701 Returns True if the two arrays are equal within the given 0702 tolerance; False otherwise. 0703 0704 See Also 0705 -------- 0706 isclose, all, any 0707 0708 Notes 0709 ----- 0710 If the following equation is element-wise True, then allclose returns 0711 True. 0712 0713 absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`)) 0714 0715 The above equation is not symmetric in `a` and `b`, so that 0716 `allclose(a, b)` might be different from `allclose(b, a)` in 0717 some rare cases. 0718 0719 Examples 0720 -------- 0721 >>> np.allclose([1e10,1e-7], [1.00001e10,1e-8]) 0722 False 0723 >>> np.allclose([1e10,1e-8], [1.00001e10,1e-9]) 0724 True 0725 >>> np.allclose([1e10,1e-8], [1.0001e10,1e-9]) 0726 False 0727 >>> np.allclose([1.0, np.nan], [1.0, np.nan]) 0728 False 0729 0730 """ 0731 return bool() 0732 def alltrue(a=False, axis=None, out=None, keepdims=False): 0733 """ 0734 Check if all elements of input array are true. 0735 0736 See Also 0737 -------- 0738 numpy.all : Equivalent function; see for details. 0739 0740 """ 0741 return None 0742 def alterdot(): 0743 """Change `dot`, `vdot`, and `inner` to use accelerated BLAS functions. 0744 0745 Typically, as a user of Numpy, you do not explicitly call this function. If 0746 Numpy is built with an accelerated BLAS, this function is automatically 0747 called when Numpy is imported. 0748 0749 When Numpy is built with an accelerated BLAS like ATLAS, these functions 0750 are replaced to make use of the faster implementations. The faster 0751 implementations only affect float32, float64, complex64, and complex128 0752 arrays. Furthermore, the BLAS API only includes matrix-matrix, 0753 matrix-vector, and vector-vector products. Products of arrays with larger 0754 dimensionalities use the built in functions and are not accelerated. 0755 0756 See Also 0757 -------- 0758 restoredot : `restoredot` undoes the effects of `alterdot`.""" 0759 return None 0760 def amax(a=False, axis=None, out=None, keepdims=False): 0761 """ 0762 Return the maximum of an array or maximum along an axis. 0763 0764 Parameters 0765 ---------- 0766 a : array_like 0767 Input data. 0768 axis : int, optional 0769 Axis along which to operate. By default, flattened input is used. 0770 out : ndarray, optional 0771 Alternative output array in which to place the result. Must 0772 be of the same shape and buffer length as the expected output. 0773 See `doc.ufuncs` (Section "Output arguments") for more details. 0774 keepdims : bool, optional 0775 If this is set to True, the axes which are reduced are left 0776 in the result as dimensions with size one. With this option, 0777 the result will broadcast correctly against the original `arr`. 0778 0779 Returns 0780 ------- 0781 amax : ndarray or scalar 0782 Maximum of `a`. If `axis` is None, the result is a scalar value. 0783 If `axis` is given, the result is an array of dimension 0784 ``a.ndim - 1``. 0785 0786 See Also 0787 -------- 0788 amin : 0789 The minimum value of an array along a given axis, propagating any NaNs. 0790 nanmax : 0791 The maximum value of an array along a given axis, ignoring any NaNs. 0792 maximum : 0793 Element-wise maximum of two arrays, propagating any NaNs. 0794 fmax : 0795 Element-wise maximum of two arrays, ignoring any NaNs. 0796 argmax : 0797 Return the indices of the maximum values. 0798 0799 nanmin, minimum, fmin 0800 0801 Notes 0802 ----- 0803 NaN values are propagated, that is if at least one item is NaN, the 0804 corresponding max value will be NaN as well. To ignore NaN values 0805 (MATLAB behavior), please use nanmax. 0806 0807 Don't use `amax` for element-wise comparison of 2 arrays; when 0808 ``a.shape[0]`` is 2, ``maximum(a[0], a[1])`` is faster than 0809 ``amax(a, axis=0)``. 0810 0811 Examples 0812 -------- 0813 >>> a = np.arange(4).reshape((2,2)) 0814 >>> a 0815 array([[0, 1], 0816 [2, 3]]) 0817 >>> np.amax(a) # Maximum of the flattened array 0818 3 0819 >>> np.amax(a, axis=0) # Maxima along the first axis 0820 array([2, 3]) 0821 >>> np.amax(a, axis=1) # Maxima along the second axis 0822 array([1, 3]) 0823 0824 >>> b = np.arange(5, dtype=np.float) 0825 >>> b[2] = np.NaN 0826 >>> np.amax(b) 0827 nan 0828 >>> np.nanmax(b) 0829 4.0 0830 0831 """ 0832 return ndarray() if False else float() 0833 def amin(a=False, axis=None, out=None, keepdims=False): 0834 """ 0835 Return the minimum of an array or minimum along an axis. 0836 0837 Parameters 0838 ---------- 0839 a : array_like 0840 Input data. 0841 axis : int, optional 0842 Axis along which to operate. By default, flattened input is used. 0843 out : ndarray, optional 0844 Alternative output array in which to place the result. Must 0845 be of the same shape and buffer length as the expected output. 0846 See `doc.ufuncs` (Section "Output arguments") for more details. 0847 keepdims : bool, optional 0848 If this is set to True, the axes which are reduced are left 0849 in the result as dimensions with size one. With this option, 0850 the result will broadcast correctly against the original `arr`. 0851 0852 Returns 0853 ------- 0854 amin : ndarray or scalar 0855 Minimum of `a`. If `axis` is None, the result is a scalar value. 0856 If `axis` is given, the result is an array of dimension 0857 ``a.ndim - 1``. 0858 0859 See Also 0860 -------- 0861 amax : 0862 The maximum value of an array along a given axis, propagating any NaNs. 0863 nanmin : 0864 The minimum value of an array along a given axis, ignoring any NaNs. 0865 minimum : 0866 Element-wise minimum of two arrays, propagating any NaNs. 0867 fmin : 0868 Element-wise minimum of two arrays, ignoring any NaNs. 0869 argmin : 0870 Return the indices of the minimum values. 0871 0872 nanmax, maximum, fmax 0873 0874 Notes 0875 ----- 0876 NaN values are propagated, that is if at least one item is NaN, the 0877 corresponding min value will be NaN as well. To ignore NaN values 0878 (MATLAB behavior), please use nanmin. 0879 0880 Don't use `amin` for element-wise comparison of 2 arrays; when 0881 ``a.shape[0]`` is 2, ``minimum(a[0], a[1])`` is faster than 0882 ``amin(a, axis=0)``. 0883 0884 Examples 0885 -------- 0886 >>> a = np.arange(4).reshape((2,2)) 0887 >>> a 0888 array([[0, 1], 0889 [2, 3]]) 0890 >>> np.amin(a) # Minimum of the flattened array 0891 0 0892 >>> np.amin(a, axis=0) # Minima along the first axis 0893 array([0, 1]) 0894 >>> np.amin(a, axis=1) # Minima along the second axis 0895 array([0, 2]) 0896 0897 >>> b = np.arange(5, dtype=np.float) 0898 >>> b[2] = np.NaN 0899 >>> np.amin(b) 0900 nan 0901 >>> np.nanmin(b) 0902 0.0 0903 0904 """ 0905 return ndarray() if False else float() 0906 def angle(z=0, deg=0): 0907 """ 0908 Return the angle of the complex argument. 0909 0910 Parameters 0911 ---------- 0912 z : array_like 0913 A complex number or sequence of complex numbers. 0914 deg : bool, optional 0915 Return angle in degrees if True, radians if False (default). 0916 0917 Returns 0918 ------- 0919 angle : {ndarray, scalar} 0920 The counterclockwise angle from the positive real axis on 0921 the complex plane, with dtype as numpy.float64. 0922 0923 See Also 0924 -------- 0925 arctan2 0926 absolute 0927 0928 0929 0930 Examples 0931 -------- 0932 >>> np.angle([1.0, 1.0j, 1+1j]) # in radians 0933 array([ 0. , 1.57079633, 0.78539816]) 0934 >>> np.angle(1+1j, deg=True) # in degrees 0935 45.0 0936 0937 """ 0938 return ndarray() 0939 def any(a=False, axis=None, out=None, keepdims=False): 0940 """ 0941 Test whether any array element along a given axis evaluates to True. 0942 0943 Returns single boolean unless `axis` is not ``None`` 0944 0945 Parameters 0946 ---------- 0947 a : array_like 0948 Input array or object that can be converted to an array. 0949 axis : None or int or tuple of ints, optional 0950 Axis or axes along which a logical OR reduction is performed. 0951 The default (`axis` = `None`) is perform a logical OR over all 0952 the dimensions of the input array. `axis` may be negative, in 0953 which case it counts from the last to the first axis. 0954 0955 .. versionadded:: 1.7.0 0956 0957 If this is a tuple of ints, a reduction is performed on multiple 0958 axes, instead of a single axis or all the axes as before. 0959 out : ndarray, optional 0960 Alternate output array in which to place the result. It must have 0961 the same shape as the expected output and its type is preserved 0962 (e.g., if it is of type float, then it will remain so, returning 0963 1.0 for True and 0.0 for False, regardless of the type of `a`). 0964 See `doc.ufuncs` (Section "Output arguments") for details. 0965 keepdims : bool, optional 0966 If this is set to True, the axes which are reduced are left 0967 in the result as dimensions with size one. With this option, 0968 the result will broadcast correctly against the original `arr`. 0969 0970 Returns 0971 ------- 0972 any : bool or ndarray 0973 A new boolean or `ndarray` is returned unless `out` is specified, 0974 in which case a reference to `out` is returned. 0975 0976 See Also 0977 -------- 0978 ndarray.any : equivalent method 0979 0980 all : Test whether all elements along a given axis evaluate to True. 0981 0982 Notes 0983 ----- 0984 Not a Number (NaN), positive infinity and negative infinity evaluate 0985 to `True` because these are not equal to zero. 0986 0987 Examples 0988 -------- 0989 >>> np.any([[True, False], [True, True]]) 0990 True 0991 0992 >>> np.any([[True, False], [False, False]], axis=0) 0993 array([ True, False], dtype=bool) 0994 0995 >>> np.any([-1, 0, 5]) 0996 True 0997 0998 >>> np.any(np.nan) 0999 True 1000 1001 >>> o=np.array([False]) 1002 >>> z=np.any([-1, 4, 5], out=o) 1003 >>> z, o 1004 (array([ True], dtype=bool), array([ True], dtype=bool)) 1005 >>> # Check now that z is a reference to o 1006 >>> z is o 1007 True 1008 >>> id(z), id(o) # identity of z and o # doctest: +SKIP 1009 (191614240, 191614240) 1010 1011 """ 1012 return bool() if False else ndarray() 1013 def append(arr, values=None, axis=None): 1014 """ 1015 Append values to the end of an array. 1016 1017 Parameters 1018 ---------- 1019 arr : array_like 1020 Values are appended to a copy of this array. 1021 values : array_like 1022 These values are appended to a copy of `arr`. It must be of the 1023 correct shape (the same shape as `arr`, excluding `axis`). If `axis` 1024 is not specified, `values` can be any shape and will be flattened 1025 before use. 1026 axis : int, optional 1027 The axis along which `values` are appended. If `axis` is not given, 1028 both `arr` and `values` are flattened before use. 1029 1030 Returns 1031 ------- 1032 append : ndarray 1033 A copy of `arr` with `values` appended to `axis`. Note that `append` 1034 does not occur in-place: a new array is allocated and filled. If 1035 `axis` is None, `out` is a flattened array. 1036 1037 See Also 1038 -------- 1039 insert : Insert elements into an array. 1040 delete : Delete elements from an array. 1041 1042 Examples 1043 -------- 1044 >>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]]) 1045 array([1, 2, 3, 4, 5, 6, 7, 8, 9]) 1046 1047 When `axis` is specified, `values` must have the correct shape. 1048 1049 >>> np.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0) 1050 array([[1, 2, 3], 1051 [4, 5, 6], 1052 [7, 8, 9]]) 1053 >>> np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0) 1054 Traceback (most recent call last): 1055 ... 1056 ValueError: arrays must have same number of dimensions 1057 1058 """ 1059 return ndarray() 1060 def apply_along_axis(func1d, axis, arr, args): 1061 """ 1062 Apply a function to 1-D slices along the given axis. 1063 1064 Execute `func1d(a, *args)` where `func1d` operates on 1-D arrays and `a` 1065 is a 1-D slice of `arr` along `axis`. 1066 1067 Parameters 1068 ---------- 1069 func1d : function 1070 This function should accept 1-D arrays. It is applied to 1-D 1071 slices of `arr` along the specified axis. 1072 axis : integer 1073 Axis along which `arr` is sliced. 1074 arr : ndarray 1075 Input array. 1076 args : any 1077 Additional arguments to `func1d`. 1078 1079 Returns 1080 ------- 1081 apply_along_axis : ndarray 1082 The output array. The shape of `outarr` is identical to the shape of 1083 `arr`, except along the `axis` dimension, where the length of `outarr` 1084 is equal to the size of the return value of `func1d`. If `func1d` 1085 returns a scalar `outarr` will have one fewer dimensions than `arr`. 1086 1087 See Also 1088 -------- 1089 apply_over_axes : Apply a function repeatedly over multiple axes. 1090 1091 Examples 1092 -------- 1093 >>> def my_func(a): 1094 ... ___Average first and last element of a 1-D array___ 1095 ... return (a[0] + a[-1]) * 0.5 1096 >>> b = np.array([[1,2,3], [4,5,6], [7,8,9]]) 1097 >>> np.apply_along_axis(my_func, 0, b) 1098 array([ 4., 5., 6.]) 1099 >>> np.apply_along_axis(my_func, 1, b) 1100 array([ 2., 5., 8.]) 1101 1102 For a function that doesn't return a scalar, the number of dimensions in 1103 `outarr` is the same as `arr`. 1104 1105 >>> b = np.array([[8,1,7], [4,3,9], [5,2,6]]) 1106 >>> np.apply_along_axis(sorted, 1, b) 1107 array([[1, 7, 8], 1108 [3, 4, 9], 1109 [2, 5, 6]]) 1110 1111 """ 1112 return ndarray() 1113 def apply_over_axes(func, a, axes): 1114 """ 1115 Apply a function repeatedly over multiple axes. 1116 1117 `func` is called as `res = func(a, axis)`, where `axis` is the first 1118 element of `axes`. The result `res` of the function call must have 1119 either the same dimensions as `a` or one less dimension. If `res` 1120 has one less dimension than `a`, a dimension is inserted before 1121 `axis`. The call to `func` is then repeated for each axis in `axes`, 1122 with `res` as the first argument. 1123 1124 Parameters 1125 ---------- 1126 func : function 1127 This function must take two arguments, `func(a, axis)`. 1128 a : array_like 1129 Input array. 1130 axes : array_like 1131 Axes over which `func` is applied; the elements must be integers. 1132 1133 Returns 1134 ------- 1135 apply_over_axis : ndarray 1136 The output array. The number of dimensions is the same as `a`, 1137 but the shape can be different. This depends on whether `func` 1138 changes the shape of its output with respect to its input. 1139 1140 See Also 1141 -------- 1142 apply_along_axis : 1143 Apply a function to 1-D slices of an array along the given axis. 1144 1145 Examples 1146 -------- 1147 >>> a = np.arange(24).reshape(2,3,4) 1148 >>> a 1149 array([[[ 0, 1, 2, 3], 1150 [ 4, 5, 6, 7], 1151 [ 8, 9, 10, 11]], 1152 [[12, 13, 14, 15], 1153 [16, 17, 18, 19], 1154 [20, 21, 22, 23]]]) 1155 1156 Sum over axes 0 and 2. The result has same number of dimensions 1157 as the original array: 1158 1159 >>> np.apply_over_axes(np.sum, a, [0,2]) 1160 array([[[ 60], 1161 [ 92], 1162 [124]]]) 1163 1164 """ 1165 return ndarray() 1166 def arange(start=None, stop=None, step=None, _=None, dtype=None): 1167 """arange([start,] stop[, step,], dtype=None) 1168 1169 Return evenly spaced values within a given interval. 1170 1171 Values are generated within the half-open interval ``[start, stop)`` 1172 (in other words, the interval including `start` but excluding `stop`). 1173 For integer arguments the function is equivalent to the Python built-in 1174 `range <http://docs.python.org/lib/built-in-funcs.html>`_ function, 1175 but returns an ndarray rather than a list. 1176 1177 When using a non-integer step, such as 0.1, the results will often not 1178 be consistent. It is better to use ``linspace`` for these cases. 1179 1180 Parameters 1181 ---------- 1182 start : number, optional 1183 Start of interval. The interval includes this value. The default 1184 start value is 0. 1185 stop : number 1186 End of interval. The interval does not include this value, except 1187 in some cases where `step` is not an integer and floating point 1188 round-off affects the length of `out`. 1189 step : number, optional 1190 Spacing between values. For any output `out`, this is the distance 1191 between two adjacent values, ``out[i+1] - out[i]``. The default 1192 step size is 1. If `step` is specified, `start` must also be given. 1193 dtype : dtype 1194 The type of the output array. If `dtype` is not given, infer the data 1195 type from the other input arguments. 1196 1197 Returns 1198 ------- 1199 arange : ndarray 1200 Array of evenly spaced values. 1201 1202 For floating point arguments, the length of the result is 1203 ``ceil((stop - start)/step)``. Because of floating point overflow, 1204 this rule may result in the last element of `out` being greater 1205 than `stop`. 1206 1207 See Also 1208 -------- 1209 linspace : Evenly spaced numbers with careful handling of endpoints. 1210 ogrid: Arrays of evenly spaced numbers in N-dimensions. 1211 mgrid: Grid-shaped arrays of evenly spaced numbers in N-dimensions. 1212 1213 Examples 1214 -------- 1215 >>> np.arange(3) 1216 array([0, 1, 2]) 1217 >>> np.arange(3.0) 1218 array([ 0., 1., 2.]) 1219 >>> np.arange(3,7) 1220 array([3, 4, 5, 6]) 1221 >>> np.arange(3,7,2) 1222 array([3, 5])""" 1223 return ndarray() 1224 def arccos(x, out): 1225 """arccos(x[, out]) 1226 1227 Trigonometric inverse cosine, element-wise. 1228 1229 The inverse of `cos` so that, if ``y = cos(x)``, then ``x = arccos(y)``. 1230 1231 Parameters 1232 ---------- 1233 x : array_like 1234 `x`-coordinate on the unit circle. 1235 For real arguments, the domain is [-1, 1]. 1236 1237 out : ndarray, optional 1238 Array of the same shape as `a`, to store results in. See 1239 `doc.ufuncs` (Section "Output arguments") for more details. 1240 1241 Returns 1242 ------- 1243 angle : ndarray 1244 The angle of the ray intersecting the unit circle at the given 1245 `x`-coordinate in radians [0, pi]. If `x` is a scalar then a 1246 scalar is returned, otherwise an array of the same shape as `x` 1247 is returned. 1248 1249 See Also 1250 -------- 1251 cos, arctan, arcsin, emath.arccos 1252 1253 Notes 1254 ----- 1255 `arccos` is a multivalued function: for each `x` there are infinitely 1256 many numbers `z` such that `cos(z) = x`. The convention is to return 1257 the angle `z` whose real part lies in `[0, pi]`. 1258 1259 For real-valued input data types, `arccos` always returns real output. 1260 For each value that cannot be expressed as a real number or infinity, 1261 it yields ``nan`` and sets the `invalid` floating point error flag. 1262 1263 For complex-valued input, `arccos` is a complex analytic function that 1264 has branch cuts `[-inf, -1]` and `[1, inf]` and is continuous from 1265 above on the former and from below on the latter. 1266 1267 The inverse `cos` is also known as `acos` or cos^-1. 1268 1269 References 1270 ---------- 1271 M. Abramowitz and I.A. Stegun, "Handbook of Mathematical Functions", 1272 10th printing, 1964, pp. 79. http://www.math.sfu.ca/~cbm/aands/ 1273 1274 Examples 1275 -------- 1276 We expect the arccos of 1 to be 0, and of -1 to be pi: 1277 1278 >>> np.arccos([1, -1]) 1279 array([ 0. , 3.14159265]) 1280 1281 Plot arccos: 1282 1283 >>> import matplotlib.pyplot as plt 1284 >>> x = np.linspace(-1, 1, num=100) 1285 >>> plt.plot(x, np.arccos(x)) 1286 >>> plt.axis('tight') 1287 >>> plt.show()""" 1288 return ndarray() 1289 def arccosh(x, out): 1290 """arccosh(x[, out]) 1291 1292 Inverse hyperbolic cosine, elementwise. 1293 1294 Parameters 1295 ---------- 1296 x : array_like 1297 Input array. 1298 out : ndarray, optional 1299 Array of the same shape as `x`, to store results in. 1300 See `doc.ufuncs` (Section "Output arguments") for details. 1301 1302 1303 Returns 1304 ------- 1305 arccosh : ndarray 1306 Array of the same shape as `x`. 1307 1308 See Also 1309 -------- 1310 1311 cosh, arcsinh, sinh, arctanh, tanh 1312 1313 Notes 1314 ----- 1315 `arccosh` is a multivalued function: for each `x` there are infinitely 1316 many numbers `z` such that `cosh(z) = x`. The convention is to return the 1317 `z` whose imaginary part lies in `[-pi, pi]` and the real part in 1318 ``[0, inf]``. 1319 1320 For real-valued input data types, `arccosh` always returns real output. 1321 For each value that cannot be expressed as a real number or infinity, it 1322 yields ``nan`` and sets the `invalid` floating point error flag. 1323 1324 For complex-valued input, `arccosh` is a complex analytical function that 1325 has a branch cut `[-inf, 1]` and is continuous from above on it. 1326 1327 References 1328 ---------- 1329 .. [1] M. Abramowitz and I.A. Stegun, "Handbook of Mathematical Functions", 1330 10th printing, 1964, pp. 86. http://www.math.sfu.ca/~cbm/aands/ 1331 .. [2] Wikipedia, "Inverse hyperbolic function", 1332 http://en.wikipedia.org/wiki/Arccosh 1333 1334 Examples 1335 -------- 1336 >>> np.arccosh([np.e, 10.0]) 1337 array([ 1.65745445, 2.99322285]) 1338 >>> np.arccosh(1) 1339 0.0""" 1340 return ndarray() 1341 def arcsin(x, out): 1342 """arcsin(x[, out]) 1343 1344 Inverse sine, element-wise. 1345 1346 Parameters 1347 ---------- 1348 x : array_like 1349 `y`-coordinate on the unit circle. 1350 1351 out : ndarray, optional 1352 Array of the same shape as `x`, in which to store the results. 1353 See `doc.ufuncs` (Section "Output arguments") for more details. 1354 1355 Returns 1356 ------- 1357 angle : ndarray 1358 The inverse sine of each element in `x`, in radians and in the 1359 closed interval ``[-pi/2, pi/2]``. If `x` is a scalar, a scalar 1360 is returned, otherwise an array. 1361 1362 See Also 1363 -------- 1364 sin, cos, arccos, tan, arctan, arctan2, emath.arcsin 1365 1366 Notes 1367 ----- 1368 `arcsin` is a multivalued function: for each `x` there are infinitely 1369 many numbers `z` such that :math:`sin(z) = x`. The convention is to 1370 return the angle `z` whose real part lies in [-pi/2, pi/2]. 1371 1372 For real-valued input data types, *arcsin* always returns real output. 1373 For each value that cannot be expressed as a real number or infinity, 1374 it yields ``nan`` and sets the `invalid` floating point error flag. 1375 1376 For complex-valued input, `arcsin` is a complex analytic function that 1377 has, by convention, the branch cuts [-inf, -1] and [1, inf] and is 1378 continuous from above on the former and from below on the latter. 1379 1380 The inverse sine is also known as `asin` or sin^{-1}. 1381 1382 References 1383 ---------- 1384 Abramowitz, M. and Stegun, I. A., *Handbook of Mathematical Functions*, 1385 10th printing, New York: Dover, 1964, pp. 79ff. 1386 http://www.math.sfu.ca/~cbm/aands/ 1387 1388 Examples 1389 -------- 1390 >>> np.arcsin(1) # pi/2 1391 1.5707963267948966 1392 >>> np.arcsin(-1) # -pi/2 1393 -1.5707963267948966 1394 >>> np.arcsin(0) 1395 0.0""" 1396 return ndarray() 1397 def arcsinh(x, out): 1398 """arcsinh(x[, out]) 1399 1400 Inverse hyperbolic sine elementwise. 1401 1402 Parameters 1403 ---------- 1404 x : array_like 1405 Input array. 1406 out : ndarray, optional 1407 Array into which the output is placed. Its type is preserved and it 1408 must be of the right shape to hold the output. See `doc.ufuncs`. 1409 1410 Returns 1411 ------- 1412 out : ndarray 1413 Array of of the same shape as `x`. 1414 1415 Notes 1416 ----- 1417 `arcsinh` is a multivalued function: for each `x` there are infinitely 1418 many numbers `z` such that `sinh(z) = x`. The convention is to return the 1419 `z` whose imaginary part lies in `[-pi/2, pi/2]`. 1420 1421 For real-valued input data types, `arcsinh` always returns real output. 1422 For each value that cannot be expressed as a real number or infinity, it 1423 returns ``nan`` and sets the `invalid` floating point error flag. 1424 1425 For complex-valued input, `arccos` is a complex analytical function that 1426 has branch cuts `[1j, infj]` and `[-1j, -infj]` and is continuous from 1427 the right on the former and from the left on the latter. 1428 1429 The inverse hyperbolic sine is also known as `asinh` or ``sinh^-1``. 1430 1431 References 1432 ---------- 1433 .. [1] M. Abramowitz and I.A. Stegun, "Handbook of Mathematical Functions", 1434 10th printing, 1964, pp. 86. http://www.math.sfu.ca/~cbm/aands/ 1435 .. [2] Wikipedia, "Inverse hyperbolic function", 1436 http://en.wikipedia.org/wiki/Arcsinh 1437 1438 Examples 1439 -------- 1440 >>> np.arcsinh(np.array([np.e, 10.0])) 1441 array([ 1.72538256, 2.99822295])""" 1442 return ndarray() 1443 def arctan(x, out=None): 1444 """arctan(x[, out]) 1445 1446 Trigonometric inverse tangent, element-wise. 1447 1448 The inverse of tan, so that if ``y = tan(x)`` then ``x = arctan(y)``. 1449 1450 Parameters 1451 ---------- 1452 x : array_like 1453 Input values. `arctan` is applied to each element of `x`. 1454 1455 Returns 1456 ------- 1457 out : ndarray 1458 Out has the same shape as `x`. Its real part is in 1459 ``[-pi/2, pi/2]`` (``arctan(+/-inf)`` returns ``+/-pi/2``). 1460 It is a scalar if `x` is a scalar. 1461 1462 See Also 1463 -------- 1464 arctan2 : The "four quadrant" arctan of the angle formed by (`x`, `y`) 1465 and the positive `x`-axis. 1466 angle : Argument of complex values. 1467 1468 Notes 1469 ----- 1470 `arctan` is a multi-valued function: for each `x` there are infinitely 1471 many numbers `z` such that tan(`z`) = `x`. The convention is to return 1472 the angle `z` whose real part lies in [-pi/2, pi/2]. 1473 1474 For real-valued input data types, `arctan` always returns real output. 1475 For each value that cannot be expressed as a real number or infinity, 1476 it yields ``nan`` and sets the `invalid` floating point error flag. 1477 1478 For complex-valued input, `arctan` is a complex analytic function that 1479 has [`1j, infj`] and [`-1j, -infj`] as branch cuts, and is continuous 1480 from the left on the former and from the right on the latter. 1481 1482 The inverse tangent is also known as `atan` or tan^{-1}. 1483 1484 References 1485 ---------- 1486 Abramowitz, M. and Stegun, I. A., *Handbook of Mathematical Functions*, 1487 10th printing, New York: Dover, 1964, pp. 79. 1488 http://www.math.sfu.ca/~cbm/aands/ 1489 1490 Examples 1491 -------- 1492 We expect the arctan of 0 to be 0, and of 1 to be pi/4: 1493 1494 >>> np.arctan([0, 1]) 1495 array([ 0. , 0.78539816]) 1496 1497 >>> np.pi/4 1498 0.78539816339744828 1499 1500 Plot arctan: 1501 1502 >>> import matplotlib.pyplot as plt 1503 >>> x = np.linspace(-10, 10) 1504 >>> plt.plot(x, np.arctan(x)) 1505 >>> plt.axis('tight') 1506 >>> plt.show()""" 1507 return ndarray() 1508 def arctan2(x1, x2, out=None): 1509 """arctan2(x1, x2[, out]) 1510 1511 Element-wise arc tangent of ``x1/x2`` choosing the quadrant correctly. 1512 1513 The quadrant (i.e., branch) is chosen so that ``arctan2(x1, x2)`` is 1514 the signed angle in radians between the ray ending at the origin and 1515 passing through the point (1,0), and the ray ending at the origin and 1516 passing through the point (`x2`, `x1`). (Note the role reversal: the 1517 "`y`-coordinate" is the first function parameter, the "`x`-coordinate" 1518 is the second.) By IEEE convention, this function is defined for 1519 `x2` = +/-0 and for either or both of `x1` and `x2` = +/-inf (see 1520 Notes for specific values). 1521 1522 This function is not defined for complex-valued arguments; for the 1523 so-called argument of complex values, use `angle`. 1524 1525 Parameters 1526 ---------- 1527 x1 : array_like, real-valued 1528 `y`-coordinates. 1529 x2 : array_like, real-valued 1530 `x`-coordinates. `x2` must be broadcastable to match the shape of 1531 `x1` or vice versa. 1532 1533 Returns 1534 ------- 1535 angle : ndarray 1536 Array of angles in radians, in the range ``[-pi, pi]``. 1537 1538 See Also 1539 -------- 1540 arctan, tan, angle 1541 1542 Notes 1543 ----- 1544 *arctan2* is identical to the `atan2` function of the underlying 1545 C library. The following special values are defined in the C 1546 standard: [1]_ 1547 1548 ====== ====== ================ 1549 `x1` `x2` `arctan2(x1,x2)` 1550 ====== ====== ================ 1551 +/- 0 +0 +/- 0 1552 +/- 0 -0 +/- pi 1553 > 0 +/-inf +0 / +pi 1554 < 0 +/-inf -0 / -pi 1555 +/-inf +inf +/- (pi/4) 1556 +/-inf -inf +/- (3*pi/4) 1557 ====== ====== ================ 1558 1559 Note that +0 and -0 are distinct floating point numbers, as are +inf 1560 and -inf. 1561 1562 References 1563 ---------- 1564 .. [1] ISO/IEC standard 9899:1999, "Programming language C." 1565 1566 Examples 1567 -------- 1568 Consider four points in different quadrants: 1569 1570 >>> x = np.array([-1, +1, +1, -1]) 1571 >>> y = np.array([-1, -1, +1, +1]) 1572 >>> np.arctan2(y, x) * 180 / np.pi 1573 array([-135., -45., 45., 135.]) 1574 1575 Note the order of the parameters. `arctan2` is defined also when `x2` = 0 1576 and at several other special points, obtaining values in 1577 the range ``[-pi, pi]``: 1578 1579 >>> np.arctan2([1., -1.], [0., 0.]) 1580 array([ 1.57079633, -1.57079633]) 1581 >>> np.arctan2([0., 0., np.inf], [+0., -0., np.inf]) 1582 array([ 0. , 3.14159265, 0.78539816])""" 1583 return ndarray() 1584 def arctanh(x, out=None): 1585 """arctanh(x[, out]) 1586 1587 Inverse hyperbolic tangent elementwise. 1588 1589 Parameters 1590 ---------- 1591 x : array_like 1592 Input array. 1593 1594 Returns 1595 ------- 1596 out : ndarray 1597 Array of the same shape as `x`. 1598 1599 See Also 1600 -------- 1601 emath.arctanh 1602 1603 Notes 1604 ----- 1605 `arctanh` is a multivalued function: for each `x` there are infinitely 1606 many numbers `z` such that `tanh(z) = x`. The convention is to return the 1607 `z` whose imaginary part lies in `[-pi/2, pi/2]`. 1608 1609 For real-valued input data types, `arctanh` always returns real output. 1610 For each value that cannot be expressed as a real number or infinity, it 1611 yields ``nan`` and sets the `invalid` floating point error flag. 1612 1613 For complex-valued input, `arctanh` is a complex analytical function that 1614 has branch cuts `[-1, -inf]` and `[1, inf]` and is continuous from 1615 above on the former and from below on the latter. 1616 1617 The inverse hyperbolic tangent is also known as `atanh` or ``tanh^-1``. 1618 1619 References 1620 ---------- 1621 .. [1] M. Abramowitz and I.A. Stegun, "Handbook of Mathematical Functions", 1622 10th printing, 1964, pp. 86. http://www.math.sfu.ca/~cbm/aands/ 1623 .. [2] Wikipedia, "Inverse hyperbolic function", 1624 http://en.wikipedia.org/wiki/Arctanh 1625 1626 Examples 1627 -------- 1628 >>> np.arctanh([0, -0.5]) 1629 array([ 0. , -0.54930614])""" 1630 return ndarray() 1631 def argmax(a=None, axis=None): 1632 """ 1633 Indices of the maximum values along an axis. 1634 1635 Parameters 1636 ---------- 1637 a : array_like 1638 Input array. 1639 axis : int, optional 1640 By default, the index is into the flattened array, otherwise 1641 along the specified axis. 1642 1643 Returns 1644 ------- 1645 index_array : ndarray of ints 1646 Array of indices into the array. It has the same shape as `a.shape` 1647 with the dimension along `axis` removed. 1648 1649 See Also 1650 -------- 1651 ndarray.argmax, argmin 1652 amax : The maximum value along a given axis. 1653 unravel_index : Convert a flat index into an index tuple. 1654 1655 Notes 1656 ----- 1657 In case of multiple occurrences of the maximum values, the indices 1658 corresponding to the first occurrence are returned. 1659 1660 Examples 1661 -------- 1662 >>> a = np.arange(6).reshape(2,3) 1663 >>> a 1664 array([[0, 1, 2], 1665 [3, 4, 5]]) 1666 >>> np.argmax(a) 1667 5 1668 >>> np.argmax(a, axis=0) 1669 array([1, 1, 1]) 1670 >>> np.argmax(a, axis=1) 1671 array([2, 2]) 1672 1673 >>> b = np.arange(6) 1674 >>> b[1] = 5 1675 >>> b 1676 array([0, 5, 2, 3, 4, 5]) 1677 >>> np.argmax(b) # Only the first occurrence is returned. 1678 1 1679 1680 """ 1681 return ndarray() 1682 def argmin(a=None, axis=None): 1683 """ 1684 Return the indices of the minimum values along an axis. 1685 1686 See Also 1687 -------- 1688 argmax : Similar function. Please refer to `numpy.argmax` for detailed 1689 documentation. 1690 1691 """ 1692 return None 1693 def argpartition(a, kth=None, axis=-1, kind="introselect", order=None): 1694 """ 1695 Perform an indirect partition along the given axis using the algorithm 1696 specified by the `kind` keyword. It returns an array of indices of the 1697 same shape as `a` that index data along the given axis in partitioned 1698 order. 1699 1700 .. versionadded:: 1.8.0 1701 1702 Parameters 1703 ---------- 1704 a : array_like 1705 Array to sort. 1706 kth : int or sequence of ints 1707 Element index to partition by. The kth element will be in its final 1708 sorted position and all smaller elements will be moved before it and 1709 all larger elements behind it. 1710 The order all elements in the partitions is undefined. 1711 If provided with a sequence of kth it will partition all of them into 1712 their sorted position at once. 1713 axis : int or None, optional 1714 Axis along which to sort. The default is -1 (the last axis). If None, 1715 the flattened array is used. 1716 kind : {'introselect'}, optional 1717 Selection algorithm. Default is 'introselect' 1718 order : list, optional 1719 When `a` is an array with fields defined, this argument specifies 1720 which fields to compare first, second, etc. Not all fields need be 1721 specified. 1722 1723 Returns 1724 ------- 1725 index_array : ndarray, int 1726 Array of indices that partition `a` along the specified axis. 1727 In other words, ``a[index_array]`` yields a sorted `a`. 1728 1729 See Also 1730 -------- 1731 partition : Describes partition algorithms used. 1732 ndarray.partition : Inplace partition. 1733 argsort : Full indirect sort 1734 1735 Notes 1736 ----- 1737 See `partition` for notes on the different selection algorithms. 1738 1739 Examples 1740 -------- 1741 One dimensional array: 1742 1743 >>> x = np.array([3, 4, 2, 1]) 1744 >>> x[np.argpartition(x, 3)] 1745 array([2, 1, 3, 4]) 1746 >>> x[np.argpartition(x, (1, 3))] 1747 array([1, 2, 3, 4]) 1748 1749 """ 1750 return ndarray() 1751 def argsort(a=None, axis=-1, kind="quicksort", order=None): 1752 """ 1753 Returns the indices that would sort an array. 1754 1755 Perform an indirect sort along the given axis using the algorithm specified 1756 by the `kind` keyword. It returns an array of indices of the same shape as 1757 `a` that index data along the given axis in sorted order. 1758 1759 Parameters 1760 ---------- 1761 a : array_like 1762 Array to sort. 1763 axis : int or None, optional 1764 Axis along which to sort. The default is -1 (the last axis). If None, 1765 the flattened array is used. 1766 kind : {'quicksort', 'mergesort', 'heapsort'}, optional 1767 Sorting algorithm. 1768 order : list, optional 1769 When `a` is an array with fields defined, this argument specifies 1770 which fields to compare first, second, etc. Not all fields need be 1771 specified. 1772 1773 Returns 1774 ------- 1775 index_array : ndarray, int 1776 Array of indices that sort `a` along the specified axis. 1777 In other words, ``a[index_array]`` yields a sorted `a`. 1778 1779 See Also 1780 -------- 1781 sort : Describes sorting algorithms used. 1782 lexsort : Indirect stable sort with multiple keys. 1783 ndarray.sort : Inplace sort. 1784 argpartition : Indirect partial sort. 1785 1786 Notes 1787 ----- 1788 See `sort` for notes on the different sorting algorithms. 1789 1790 As of NumPy 1.4.0 `argsort` works with real/complex arrays containing 1791 nan values. The enhanced sort order is documented in `sort`. 1792 1793 Examples 1794 -------- 1795 One dimensional array: 1796 1797 >>> x = np.array([3, 1, 2]) 1798 >>> np.argsort(x) 1799 array([1, 2, 0]) 1800 1801 Two-dimensional array: 1802 1803 >>> x = np.array([[0, 3], [2, 2]]) 1804 >>> x 1805 array([[0, 3], 1806 [2, 2]]) 1807 1808 >>> np.argsort(x, axis=0) 1809 array([[0, 1], 1810 [1, 0]]) 1811 1812 >>> np.argsort(x, axis=1) 1813 array([[0, 1], 1814 [0, 1]]) 1815 1816 Sorting with keys: 1817 1818 >>> x = np.array([(1, 0), (0, 1)], dtype=[('x', '<i4'), ('y', '<i4')]) 1819 >>> x 1820 array([(1, 0), (0, 1)], 1821 dtype=[('x', '<i4'), ('y', '<i4')]) 1822 1823 >>> np.argsort(x, order=('x','y')) 1824 array([1, 0]) 1825 1826 >>> np.argsort(x, order=('y','x')) 1827 array([0, 1]) 1828 1829 """ 1830 return ndarray() 1831 def argwhere(a): 1832 """ 1833 Find the indices of array elements that are non-zero, grouped by element. 1834 1835 Parameters 1836 ---------- 1837 a : array_like 1838 Input data. 1839 1840 Returns 1841 ------- 1842 index_array : ndarray 1843 Indices of elements that are non-zero. Indices are grouped by element. 1844 1845 See Also 1846 -------- 1847 where, nonzero 1848 1849 Notes 1850 ----- 1851 ``np.argwhere(a)`` is the same as ``np.transpose(np.nonzero(a))``. 1852 1853 The output of ``argwhere`` is not suitable for indexing arrays. 1854 For this purpose use ``where(a)`` instead. 1855 1856 Examples 1857 -------- 1858 >>> x = np.arange(6).reshape(2,3) 1859 >>> x 1860 array([[0, 1, 2], 1861 [3, 4, 5]]) 1862 >>> np.argwhere(x>1) 1863 array([[0, 2], 1864 [1, 0], 1865 [1, 1], 1866 [1, 2]]) 1867 1868 """ 1869 return ndarray() 1870 def around(a=None, decimals=0, out=None): 1871 """ 1872 Evenly round to the given number of decimals. 1873 1874 Parameters 1875 ---------- 1876 a : array_like 1877 Input data. 1878 decimals : int, optional 1879 Number of decimal places to round to (default: 0). If 1880 decimals is negative, it specifies the number of positions to 1881 the left of the decimal point. 1882 out : ndarray, optional 1883 Alternative output array in which to place the result. It must have 1884 the same shape as the expected output, but the type of the output 1885 values will be cast if necessary. See `doc.ufuncs` (Section 1886 "Output arguments") for details. 1887 1888 Returns 1889 ------- 1890 rounded_array : ndarray 1891 An array of the same type as `a`, containing the rounded values. 1892 Unless `out` was specified, a new array is created. A reference to 1893 the result is returned. 1894 1895 The real and imaginary parts of complex numbers are rounded 1896 separately. The result of rounding a float is a float. 1897 1898 See Also 1899 -------- 1900 ndarray.round : equivalent method 1901 1902 ceil, fix, floor, rint, trunc 1903 1904 1905 Notes 1906 ----- 1907 For values exactly halfway between rounded decimal values, Numpy 1908 rounds to the nearest even value. Thus 1.5 and 2.5 round to 2.0, 1909 -0.5 and 0.5 round to 0.0, etc. Results may also be surprising due 1910 to the inexact representation of decimal fractions in the IEEE 1911 floating point standard [1]_ and errors introduced when scaling 1912 by powers of ten. 1913 1914 References 1915 ---------- 1916 .. [1] "Lecture Notes on the Status of IEEE 754", William Kahan, 1917 http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF 1918 .. [2] "How Futile are Mindless Assessments of 1919 Roundoff in Floating-Point Computation?", William Kahan, 1920 http://www.cs.berkeley.edu/~wkahan/Mindless.pdf 1921 1922 Examples 1923 -------- 1924 >>> np.around([0.37, 1.64]) 1925 array([ 0., 2.]) 1926 >>> np.around([0.37, 1.64], decimals=1) 1927 array([ 0.4, 1.6]) 1928 >>> np.around([.5, 1.5, 2.5, 3.5, 4.5]) # rounds to nearest even value 1929 array([ 0., 2., 2., 4., 4.]) 1930 >>> np.around([1,2,3,11], decimals=1) # ndarray of ints is returned 1931 array([ 1, 2, 3, 11]) 1932 >>> np.around([1,2,3,11], decimals=-1) 1933 array([ 0, 0, 0, 10]) 1934 1935 """ 1936 return ndarray() 1937 def array(object, dtype, copy, order, subok, ndmin): 1938 """array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0) 1939 1940 Create an array. 1941 1942 Parameters 1943 ---------- 1944 object : array_like 1945 An array, any object exposing the array interface, an 1946 object whose __array__ method returns an array, or any 1947 (nested) sequence. 1948 dtype : data-type, optional 1949 The desired data-type for the array. If not given, then 1950 the type will be determined as the minimum type required 1951 to hold the objects in the sequence. This argument can only 1952 be used to 'upcast' the array. For downcasting, use the 1953 .astype(t) method. 1954 copy : bool, optional 1955 If true (default), then the object is copied. Otherwise, a copy 1956 will only be made if __array__ returns a copy, if obj is a 1957 nested sequence, or if a copy is needed to satisfy any of the other 1958 requirements (`dtype`, `order`, etc.). 1959 order : {'C', 'F', 'A'}, optional 1960 Specify the order of the array. If order is 'C' (default), then the 1961 array will be in C-contiguous order (last-index varies the 1962 fastest). If order is 'F', then the returned array 1963 will be in Fortran-contiguous order (first-index varies the 1964 fastest). If order is 'A', then the returned array may 1965 be in any order (either C-, Fortran-contiguous, or even 1966 discontiguous). 1967 subok : bool, optional 1968 If True, then sub-classes will be passed-through, otherwise 1969 the returned array will be forced to be a base-class array (default). 1970 ndmin : int, optional 1971 Specifies the minimum number of dimensions that the resulting 1972 array should have. Ones will be pre-pended to the shape as 1973 needed to meet this requirement. 1974 1975 Returns 1976 ------- 1977 out : ndarray 1978 An array object satisfying the specified requirements. 1979 1980 See Also 1981 -------- 1982 empty, empty_like, zeros, zeros_like, ones, ones_like, fill 1983 1984 Examples 1985 -------- 1986 >>> np.array([1, 2, 3]) 1987 array([1, 2, 3]) 1988 1989 Upcasting: 1990 1991 >>> np.array([1, 2, 3.0]) 1992 array([ 1., 2., 3.]) 1993 1994 More than one dimension: 1995 1996 >>> np.array([[1, 2], [3, 4]]) 1997 array([[1, 2], 1998 [3, 4]]) 1999 2000 Minimum dimensions 2: 2001 2002 >>> np.array([1, 2, 3], ndmin=2) 2003 array([[1, 2, 3]]) 2004 2005 Type provided: 2006 2007 >>> np.array([1, 2, 3], dtype=complex) 2008 array([ 1.+0.j, 2.+0.j, 3.+0.j]) 2009 2010 Data-type consisting of more than one element: 2011 2012 >>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')]) 2013 >>> x['a'] 2014 array([1, 3]) 2015 2016 Creating an array from sub-classes: 2017 2018 >>> np.array(np.mat('1 2; 3 4')) 2019 array([[1, 2], 2020 [3, 4]]) 2021 2022 >>> np.array(np.mat('1 2; 3 4'), subok=True) 2023 matrix([[1, 2], 2024 [3, 4]])""" 2025 return ndarray() 2026 def array2string(a=None, max_line_width=None, precision=None, suppress_small=None, separator=" ", prefix="", style="<built-in function repr>", formatter=None): 2027 """ 2028 Return a string representation of an array. 2029 2030 Parameters 2031 ---------- 2032 a : ndarray 2033 Input array. 2034 max_line_width : int, optional 2035 The maximum number of columns the string should span. Newline 2036 characters splits the string appropriately after array elements. 2037 precision : int, optional 2038 Floating point precision. Default is the current printing 2039 precision (usually 8), which can be altered using `set_printoptions`. 2040 suppress_small : bool, optional 2041 Represent very small numbers as zero. A number is "very small" if it 2042 is smaller than the current printing precision. 2043 separator : str, optional 2044 Inserted between elements. 2045 prefix : str, optional 2046 An array is typically printed as:: 2047 2048 'prefix(' + array2string(a) + ')' 2049 2050 The length of the prefix string is used to align the 2051 output correctly. 2052 style : function, optional 2053 A function that accepts an ndarray and returns a string. Used only 2054 when the shape of `a` is equal to ``()``, i.e. for 0-D arrays. 2055 formatter : dict of callables, optional 2056 If not None, the keys should indicate the type(s) that the respective 2057 formatting function applies to. Callables should return a string. 2058 Types that are not specified (by their corresponding keys) are handled 2059 by the default formatters. Individual types for which a formatter 2060 can be set are:: 2061 2062 - 'bool' 2063 - 'int' 2064 - 'timedelta' : a `numpy.timedelta64` 2065 - 'datetime' : a `numpy.datetime64` 2066 - 'float' 2067 - 'longfloat' : 128-bit floats 2068 - 'complexfloat' 2069 - 'longcomplexfloat' : composed of two 128-bit floats 2070 - 'numpy_str' : types `numpy.string_` and `numpy.unicode_` 2071 - 'str' : all other strings 2072 2073 Other keys that can be used to set a group of types at once are:: 2074 2075 - 'all' : sets all types 2076 - 'int_kind' : sets 'int' 2077 - 'float_kind' : sets 'float' and 'longfloat' 2078 - 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat' 2079 - 'str_kind' : sets 'str' and 'numpystr' 2080 2081 Returns 2082 ------- 2083 array_str : str 2084 String representation of the array. 2085 2086 Raises 2087 ------ 2088 TypeError 2089 if a callable in `formatter` does not return a string. 2090 2091 See Also 2092 -------- 2093 array_str, array_repr, set_printoptions, get_printoptions 2094 2095 Notes 2096 ----- 2097 If a formatter is specified for a certain type, the `precision` keyword is 2098 ignored for that type. 2099 2100 Examples 2101 -------- 2102 >>> x = np.array([1e-16,1,2,3]) 2103 >>> print np.array2string(x, precision=2, separator=',', 2104 ... suppress_small=True) 2105 [ 0., 1., 2., 3.] 2106 2107 >>> x = np.arange(3.) 2108 >>> np.array2string(x, formatter={'float_kind':lambda x: "%.2f" % x}) 2109 '[0.00 1.00 2.00]' 2110 2111 >>> x = np.arange(3) 2112 >>> np.array2string(x, formatter={'int':lambda x: hex(x)}) 2113 '[0x0L 0x1L 0x2L]' 2114 2115 """ 2116 return str() 2117 def array_equal(a1a2): 2118 """ 2119 True if two arrays have the same shape and elements, False otherwise. 2120 2121 Parameters 2122 ---------- 2123 a1, a2 : array_like 2124 Input arrays. 2125 2126 Returns 2127 ------- 2128 b : bool 2129 Returns True if the arrays are equal. 2130 2131 See Also 2132 -------- 2133 allclose: Returns True if two arrays are element-wise equal within a 2134 tolerance. 2135 array_equiv: Returns True if input arrays are shape consistent and all 2136 elements equal. 2137 2138 Examples 2139 -------- 2140 >>> np.array_equal([1, 2], [1, 2]) 2141 True 2142 >>> np.array_equal(np.array([1, 2]), np.array([1, 2])) 2143 True 2144 >>> np.array_equal([1, 2], [1, 2, 3]) 2145 False 2146 >>> np.array_equal([1, 2], [1, 4]) 2147 False 2148 2149 """ 2150 return bool() 2151 def array_equiv(a1a2): 2152 """ 2153 Returns True if input arrays are shape consistent and all elements equal. 2154 2155 Shape consistent means they are either the same shape, or one input array 2156 can be broadcasted to create the same shape as the other one. 2157 2158 Parameters 2159 ---------- 2160 a1, a2 : array_like 2161 Input arrays. 2162 2163 Returns 2164 ------- 2165 out : bool 2166 True if equivalent, False otherwise. 2167 2168 Examples 2169 -------- 2170 >>> np.array_equiv([1, 2], [1, 2]) 2171 True 2172 >>> np.array_equiv([1, 2], [1, 3]) 2173 False 2174 2175 Showing the shape equivalence: 2176 2177 >>> np.array_equiv([1, 2], [[1, 2], [1, 2]]) 2178 True 2179 >>> np.array_equiv([1, 2], [[1, 2, 1, 2], [1, 2, 1, 2]]) 2180 False 2181 2182 >>> np.array_equiv([1, 2], [[1, 2], [1, 3]]) 2183 False 2184 2185 """ 2186 return bool() 2187 def array_repr(arr=None, max_line_width=None, precision=None, suppress_small=None): 2188 """ 2189 Return the string representation of an array. 2190 2191 Parameters 2192 ---------- 2193 arr : ndarray 2194 Input array. 2195 max_line_width : int, optional 2196 The maximum number of columns the string should span. Newline 2197 characters split the string appropriately after array elements. 2198 precision : int, optional 2199 Floating point precision. Default is the current printing precision 2200 (usually 8), which can be altered using `set_printoptions`. 2201 suppress_small : bool, optional 2202 Represent very small numbers as zero, default is False. Very small 2203 is defined by `precision`, if the precision is 8 then 2204 numbers smaller than 5e-9 are represented as zero. 2205 2206 Returns 2207 ------- 2208 string : str 2209 The string representation of an array. 2210 2211 See Also 2212 -------- 2213 array_str, array2string, set_printoptions 2214 2215 Examples 2216 -------- 2217 >>> np.array_repr(np.array([1,2])) 2218 'array([1, 2])' 2219 >>> np.array_repr(np.ma.array([0.])) 2220 'MaskedArray([ 0.])' 2221 >>> np.array_repr(np.array([], np.int32)) 2222 'array([], dtype=int32)' 2223 2224 >>> x = np.array([1e-6, 4e-7, 2, 3]) 2225 >>> np.array_repr(x, precision=6, suppress_small=True) 2226 'array([ 0.000001, 0. , 2. , 3. ])' 2227 2228 """ 2229 return str() 2230 def array_split(ary, indices_or_sections=0, axis=0): 2231 """ 2232 Split an array into multiple sub-arrays. 2233 2234 Please refer to the ``split`` documentation. The only difference 2235 between these functions is that ``array_split`` allows 2236 `indices_or_sections` to be an integer that does *not* equally 2237 divide the axis. 2238 2239 See Also 2240 -------- 2241 split : Split array into multiple sub-arrays of equal size. 2242 2243 Examples 2244 -------- 2245 >>> x = np.arange(8.0) 2246 >>> np.array_split(x, 3) 2247 [array([ 0., 1., 2.]), array([ 3., 4., 5.]), array([ 6., 7.])] 2248 2249 """ 2250 return None 2251 def array_str(a=None, max_line_width=None, precision=None, suppress_small=None): 2252 """ 2253 Return a string representation of the data in an array. 2254 2255 The data in the array is returned as a single string. This function is 2256 similar to `array_repr`, the difference being that `array_repr` also 2257 returns information on the kind of array and its data type. 2258 2259 Parameters 2260 ---------- 2261 a : ndarray 2262 Input array. 2263 max_line_width : int, optional 2264 Inserts newlines if text is longer than `max_line_width`. The 2265 default is, indirectly, 75. 2266 precision : int, optional 2267 Floating point precision. Default is the current printing precision 2268 (usually 8), which can be altered using `set_printoptions`. 2269 suppress_small : bool, optional 2270 Represent numbers "very close" to zero as zero; default is False. 2271 Very close is defined by precision: if the precision is 8, e.g., 2272 numbers smaller (in absolute value) than 5e-9 are represented as 2273 zero. 2274 2275 See Also 2276 -------- 2277 array2string, array_repr, set_printoptions 2278 2279 Examples 2280 -------- 2281 >>> np.array_str(np.arange(3)) 2282 '[0 1 2]' 2283 2284 """ 2285 return None 2286 def asanyarray(a=None, dtype=None, order=None): 2287 """ 2288 Convert the input to an ndarray, but pass ndarray subclasses through. 2289 2290 Parameters 2291 ---------- 2292 a : array_like 2293 Input data, in any form that can be converted to an array. This 2294 includes scalars, lists, lists of tuples, tuples, tuples of tuples, 2295 tuples of lists, and ndarrays. 2296 dtype : data-type, optional 2297 By default, the data-type is inferred from the input data. 2298 order : {'C', 'F'}, optional 2299 Whether to use row-major ('C') or column-major ('F') memory 2300 representation. Defaults to 'C'. 2301 2302 Returns 2303 ------- 2304 out : ndarray or an ndarray subclass 2305 Array interpretation of `a`. If `a` is an ndarray or a subclass 2306 of ndarray, it is returned as-is and no copy is performed. 2307 2308 See Also 2309 -------- 2310 asarray : Similar function which always returns ndarrays. 2311 ascontiguousarray : Convert input to a contiguous array. 2312 asfarray : Convert input to a floating point ndarray. 2313 asfortranarray : Convert input to an ndarray with column-major 2314 memory order. 2315 asarray_chkfinite : Similar function which checks input for NaNs and 2316 Infs. 2317 fromiter : Create an array from an iterator. 2318 fromfunction : Construct an array by executing a function on grid 2319 positions. 2320 2321 Examples 2322 -------- 2323 Convert a list into an array: 2324 2325 >>> a = [1, 2] 2326 >>> np.asanyarray(a) 2327 array([1, 2]) 2328 2329 Instances of `ndarray` subclasses are passed through as-is: 2330 2331 >>> a = np.matrix([1, 2]) 2332 >>> np.asanyarray(a) is a 2333 True 2334 2335 """ 2336 return ndarray() if False else an() 2337 def asarray(a=None, dtype=None, order=None): 2338 """ 2339 Convert the input to an array. 2340 2341 Parameters 2342 ---------- 2343 a : array_like 2344 Input data, in any form that can be converted to an array. This 2345 includes lists, lists of tuples, tuples, tuples of tuples, tuples 2346 of lists and ndarrays. 2347 dtype : data-type, optional 2348 By default, the data-type is inferred from the input data. 2349 order : {'C', 'F'}, optional 2350 Whether to use row-major ('C') or column-major ('F' for FORTRAN) 2351 memory representation. Defaults to 'C'. 2352 2353 Returns 2354 ------- 2355 out : ndarray 2356 Array interpretation of `a`. No copy is performed if the input 2357 is already an ndarray. If `a` is a subclass of ndarray, a base 2358 class ndarray is returned. 2359 2360 See Also 2361 -------- 2362 asanyarray : Similar function which passes through subclasses. 2363 ascontiguousarray : Convert input to a contiguous array. 2364 asfarray : Convert input to a floating point ndarray. 2365 asfortranarray : Convert input to an ndarray with column-major 2366 memory order. 2367 asarray_chkfinite : Similar function which checks input for NaNs and Infs. 2368 fromiter : Create an array from an iterator. 2369 fromfunction : Construct an array by executing a function on grid 2370 positions. 2371 2372 Examples 2373 -------- 2374 Convert a list into an array: 2375 2376 >>> a = [1, 2] 2377 >>> np.asarray(a) 2378 array([1, 2]) 2379 2380 Existing arrays are not copied: 2381 2382 >>> a = np.array([1, 2]) 2383 >>> np.asarray(a) is a 2384 True 2385 2386 If `dtype` is set, array is copied only if dtype does not match: 2387 2388 >>> a = np.array([1, 2], dtype=np.float32) 2389 >>> np.asarray(a, dtype=np.float32) is a 2390 True 2391 >>> np.asarray(a, dtype=np.float64) is a 2392 False 2393 2394 Contrary to `asanyarray`, ndarray subclasses are not passed through: 2395 2396 >>> issubclass(np.matrix, np.ndarray) 2397 True 2398 >>> a = np.matrix([[1, 2]]) 2399 >>> np.asarray(a) is a 2400 False 2401 >>> np.asanyarray(a) is a 2402 True 2403 2404 """ 2405 return ndarray() 2406 def asarray_chkfinite(a=None, dtype=None, order=None): 2407 """ 2408 Convert the input to an array, checking for NaNs or Infs. 2409 2410 Parameters 2411 ---------- 2412 a : array_like 2413 Input data, in any form that can be converted to an array. This 2414 includes lists, lists of tuples, tuples, tuples of tuples, tuples 2415 of lists and ndarrays. Success requires no NaNs or Infs. 2416 dtype : data-type, optional 2417 By default, the data-type is inferred from the input data. 2418 order : {'C', 'F'}, optional 2419 Whether to use row-major ('C') or column-major ('FORTRAN') memory 2420 representation. Defaults to 'C'. 2421 2422 Returns 2423 ------- 2424 out : ndarray 2425 Array interpretation of `a`. No copy is performed if the input 2426 is already an ndarray. If `a` is a subclass of ndarray, a base 2427 class ndarray is returned. 2428 2429 Raises 2430 ------ 2431 ValueError 2432 Raises ValueError if `a` contains NaN (Not a Number) or Inf (Infinity). 2433 2434 See Also 2435 -------- 2436 asarray : Create and array. 2437 asanyarray : Similar function which passes through subclasses. 2438 ascontiguousarray : Convert input to a contiguous array. 2439 asfarray : Convert input to a floating point ndarray. 2440 asfortranarray : Convert input to an ndarray with column-major 2441 memory order. 2442 fromiter : Create an array from an iterator. 2443 fromfunction : Construct an array by executing a function on grid 2444 positions. 2445 2446 Examples 2447 -------- 2448 Convert a list into an array. If all elements are finite 2449 ``asarray_chkfinite`` is identical to ``asarray``. 2450 2451 >>> a = [1, 2] 2452 >>> np.asarray_chkfinite(a, dtype=float) 2453 array([1., 2.]) 2454 2455 Raises ValueError if array_like contains Nans or Infs. 2456 2457 >>> a = [1, 2, np.inf] 2458 >>> try: 2459 ... np.asarray_chkfinite(a) 2460 ... except ValueError: 2461 ... print 'ValueError' 2462 ... 2463 ValueError 2464 2465 """ 2466 return ndarray() 2467 def ascontiguousarray(a=None, dtype=None): 2468 """ 2469 Return a contiguous array in memory (C order). 2470 2471 Parameters 2472 ---------- 2473 a : array_like 2474 Input array. 2475 dtype : str or dtype object, optional 2476 Data-type of returned array. 2477 2478 Returns 2479 ------- 2480 out : ndarray 2481 Contiguous array of same shape and content as `a`, with type `dtype` 2482 if specified. 2483 2484 See Also 2485 -------- 2486 asfortranarray : Convert input to an ndarray with column-major 2487 memory order. 2488 require : Return an ndarray that satisfies requirements. 2489 ndarray.flags : Information about the memory layout of the array. 2490 2491 Examples 2492 -------- 2493 >>> x = np.arange(6).reshape(2,3) 2494 >>> np.ascontiguousarray(x, dtype=np.float32) 2495 array([[ 0., 1., 2.], 2496 [ 3., 4., 5.]], dtype=float32) 2497 >>> x.flags['C_CONTIGUOUS'] 2498 True 2499 2500 """ 2501 return ndarray() 2502 def asfarray(a=typenumpy.float64(), dtype=typenumpy.float64()): 2503 """ 2504 Return an array converted to a float type. 2505 2506 Parameters 2507 ---------- 2508 a : array_like 2509 The input array. 2510 dtype : str or dtype object, optional 2511 Float type code to coerce input array `a`. If `dtype` is one of the 2512 'int' dtypes, it is replaced with float64. 2513 2514 Returns 2515 ------- 2516 out : ndarray 2517 The input `a` as a float ndarray. 2518 2519 Examples 2520 -------- 2521 >>> np.asfarray([2, 3]) 2522 array([ 2., 3.]) 2523 >>> np.asfarray([2, 3], dtype='float') 2524 array([ 2., 3.]) 2525 >>> np.asfarray([2, 3], dtype='int8') 2526 array([ 2., 3.]) 2527 2528 """ 2529 return ndarray() 2530 def asfortranarray(a=None, dtype=None): 2531 """ 2532 Return an array laid out in Fortran order in memory. 2533 2534 Parameters 2535 ---------- 2536 a : array_like 2537 Input array. 2538 dtype : str or dtype object, optional 2539 By default, the data-type is inferred from the input data. 2540 2541 Returns 2542 ------- 2543 out : ndarray 2544 The input `a` in Fortran, or column-major, order. 2545 2546 See Also 2547 -------- 2548 ascontiguousarray : Convert input to a contiguous (C order) array. 2549 asanyarray : Convert input to an ndarray with either row or 2550 column-major memory order. 2551 require : Return an ndarray that satisfies requirements. 2552 ndarray.flags : Information about the memory layout of the array. 2553 2554 Examples 2555 -------- 2556 >>> x = np.arange(6).reshape(2,3) 2557 >>> y = np.asfortranarray(x) 2558 >>> x.flags['F_CONTIGUOUS'] 2559 False 2560 >>> y.flags['F_CONTIGUOUS'] 2561 True 2562 2563 """ 2564 return ndarray() 2565 def asmatrix(data=None, dtype=None): 2566 """ 2567 Interpret the input as a matrix. 2568 2569 Unlike `matrix`, `asmatrix` does not make a copy if the input is already 2570 a matrix or an ndarray. Equivalent to ``matrix(data, copy=False)``. 2571 2572 Parameters 2573 ---------- 2574 data : array_like 2575 Input data. 2576 2577 Returns 2578 ------- 2579 mat : matrix 2580 `data` interpreted as a matrix. 2581 2582 Examples 2583 -------- 2584 >>> x = np.array([[1, 2], [3, 4]]) 2585 2586 >>> m = np.asmatrix(x) 2587 2588 >>> x[0,0] = 5 2589 2590 >>> m 2591 matrix([[5, 2], 2592 [3, 4]]) 2593 2594 """ 2595 return matrix() 2596 def asscalar(a): 2597 """ 2598 Convert an array of size 1 to its scalar equivalent. 2599 2600 Parameters 2601 ---------- 2602 a : ndarray 2603 Input array of size 1. 2604 2605 Returns 2606 ------- 2607 out : scalar 2608 Scalar representation of `a`. The output data type is the same type 2609 returned by the input's `item` method. 2610 2611 Examples 2612 -------- 2613 >>> np.asscalar(np.array([24])) 2614 24 2615 2616 """ 2617 return None 2618 def atleast_1d(): 2619 """ 2620 Convert inputs to arrays with at least one dimension. 2621 2622 Scalar inputs are converted to 1-dimensional arrays, whilst 2623 higher-dimensional inputs are preserved. 2624 2625 Parameters 2626 ---------- 2627 arys1, arys2, ... : array_like 2628 One or more input arrays. 2629 2630 Returns 2631 ------- 2632 ret : ndarray 2633 An array, or sequence of arrays, each with ``a.ndim >= 1``. 2634 Copies are made only if necessary. 2635 2636 See Also 2637 -------- 2638 atleast_2d, atleast_3d 2639 2640 Examples 2641 -------- 2642 >>> np.atleast_1d(1.0) 2643 array([ 1.]) 2644 2645 >>> x = np.arange(9.0).reshape(3,3) 2646 >>> np.atleast_1d(x) 2647 array([[ 0., 1., 2.], 2648 [ 3., 4., 5.], 2649 [ 6., 7., 8.]]) 2650 >>> np.atleast_1d(x) is x 2651 True 2652 2653 >>> np.atleast_1d(1, [3, 4]) 2654 [array([1]), array([3, 4])] 2655 2656 """ 2657 return ndarray() 2658 def atleast_2d(): 2659 """ 2660 View inputs as arrays with at least two dimensions. 2661 2662 Parameters 2663 ---------- 2664 arys1, arys2, ... : array_like 2665 One or more array-like sequences. Non-array inputs are converted 2666 to arrays. Arrays that already have two or more dimensions are 2667 preserved. 2668 2669 Returns 2670 ------- 2671 res, res2, ... : ndarray 2672 An array, or tuple of arrays, each with ``a.ndim >= 2``. 2673 Copies are avoided where possible, and views with two or more 2674 dimensions are returned. 2675 2676 See Also 2677 -------- 2678 atleast_1d, atleast_3d 2679 2680 Examples 2681 -------- 2682 >>> np.atleast_2d(3.0) 2683 array([[ 3.]]) 2684 2685 >>> x = np.arange(3.0) 2686 >>> np.atleast_2d(x) 2687 array([[ 0., 1., 2.]]) 2688 >>> np.atleast_2d(x).base is x 2689 True 2690 2691 >>> np.atleast_2d(1, [1, 2], [[1, 2]]) 2692 [array([[1]]), array([[1, 2]]), array([[1, 2]])] 2693 2694 """ 2695 return ndarray() 2696 def atleast_3d(): 2697 """ 2698 View inputs as arrays with at least three dimensions. 2699 2700 Parameters 2701 ---------- 2702 arys1, arys2, ... : array_like 2703 One or more array-like sequences. Non-array inputs are converted to 2704 arrays. Arrays that already have three or more dimensions are 2705 preserved. 2706 2707 Returns 2708 ------- 2709 res1, res2, ... : ndarray 2710 An array, or tuple of arrays, each with ``a.ndim >= 3``. Copies are 2711 avoided where possible, and views with three or more dimensions are 2712 returned. For example, a 1-D array of shape ``(N,)`` becomes a view 2713 of shape ``(1, N, 1)``, and a 2-D array of shape ``(M, N)`` becomes a 2714 view of shape ``(M, N, 1)``. 2715 2716 See Also 2717 -------- 2718 atleast_1d, atleast_2d 2719 2720 Examples 2721 -------- 2722 >>> np.atleast_3d(3.0) 2723 array([[[ 3.]]]) 2724 2725 >>> x = np.arange(3.0) 2726 >>> np.atleast_3d(x).shape 2727 (1, 3, 1) 2728 2729 >>> x = np.arange(12.0).reshape(4,3) 2730 >>> np.atleast_3d(x).shape 2731 (4, 3, 1) 2732 >>> np.atleast_3d(x).base is x 2733 True 2734 2735 >>> for arr in np.atleast_3d([1, 2], [[1, 2]], [[[1, 2]]]): 2736 ... print arr, arr.shape 2737 ... 2738 [[[1] 2739 [2]]] (1, 2, 1) 2740 [[[1] 2741 [2]]] (1, 2, 1) 2742 [[[1 2]]] (1, 1, 2) 2743 2744 """ 2745 return ndarray() 2746 def average(a=False, axis=None, weights=None, returned=False): 2747 """ 2748 Compute the weighted average along the specified axis. 2749 2750 Parameters 2751 ---------- 2752 a : array_like 2753 Array containing data to be averaged. If `a` is not an array, a 2754 conversion is attempted. 2755 axis : int, optional 2756 Axis along which to average `a`. If `None`, averaging is done over 2757 the flattened array. 2758 weights : array_like, optional 2759 An array of weights associated with the values in `a`. Each value in 2760 `a` contributes to the average according to its associated weight. 2761 The weights array can either be 1-D (in which case its length must be 2762 the size of `a` along the given axis) or of the same shape as `a`. 2763 If `weights=None`, then all data in `a` are assumed to have a 2764 weight equal to one. 2765 returned : bool, optional 2766 Default is `False`. If `True`, the tuple (`average`, `sum_of_weights`) 2767 is returned, otherwise only the average is returned. 2768 If `weights=None`, `sum_of_weights` is equivalent to the number of 2769 elements over which the average is taken. 2770 2771 2772 Returns 2773 ------- 2774 average, [sum_of_weights] : {array_type, double} 2775 Return the average along the specified axis. When returned is `True`, 2776 return a tuple with the average as the first element and the sum 2777 of the weights as the second element. The return type is `Float` 2778 if `a` is of integer type, otherwise it is of the same type as `a`. 2779 `sum_of_weights` is of the same type as `average`. 2780 2781 Raises 2782 ------ 2783 ZeroDivisionError 2784 When all weights along axis are zero. See `numpy.ma.average` for a 2785 version robust to this type of error. 2786 TypeError 2787 When the length of 1D `weights` is not the same as the shape of `a` 2788 along axis. 2789 2790 See Also 2791 -------- 2792 mean 2793 2794 ma.average : average for masked arrays -- useful if your data contains 2795 "missing" values 2796 2797 Examples 2798 -------- 2799 >>> data = range(1,5) 2800 >>> data 2801 [1, 2, 3, 4] 2802 >>> np.average(data) 2803 2.5 2804 >>> np.average(range(1,11), weights=range(10,0,-1)) 2805 4.0 2806 2807 >>> data = np.arange(6).reshape((3,2)) 2808 >>> data 2809 array([[0, 1], 2810 [2, 3], 2811 [4, 5]]) 2812 >>> np.average(data, axis=1, weights=[1./4, 3./4]) 2813 array([ 0.75, 2.75, 4.75]) 2814 >>> np.average(data, weights=[1./4, 3./4]) 2815 Traceback (most recent call last): 2816 ... 2817 TypeError: Axis must be specified when shapes of a and weights differ. 2818 2819 """ 2820 return array_type() 2821 def bartlett(M): 2822 """ 2823 Return the Bartlett window. 2824 2825 The Bartlett window is very similar to a triangular window, except 2826 that the end points are at zero. It is often used in signal 2827 processing for tapering a signal, without generating too much 2828 ripple in the frequency domain. 2829 2830 Parameters 2831 ---------- 2832 M : int 2833 Number of points in the output window. If zero or less, an 2834 empty array is returned. 2835 2836 Returns 2837 ------- 2838 out : array 2839 The triangular window, with the maximum value normalized to one 2840 (the value one appears only if the number of samples is odd), with 2841 the first and last samples equal to zero. 2842 2843 See Also 2844 -------- 2845 blackman, hamming, hanning, kaiser 2846 2847 Notes 2848 ----- 2849 The Bartlett window is defined as 2850 2851 .. math:: w(n) = \frac{2}{M-1} \left( 2852 \frac{M-1}{2} - \left|n - \frac{M-1}{2}\right| 2853 \right) 2854 2855 Most references to the Bartlett window come from the signal 2856 processing literature, where it is used as one of many windowing 2857 functions for smoothing values. Note that convolution with this 2858 window produces linear interpolation. It is also known as an 2859 apodization (which means"removing the foot", i.e. smoothing 2860 discontinuities at the beginning and end of the sampled signal) or 2861 tapering function. The fourier transform of the Bartlett is the product 2862 of two sinc functions. 2863 Note the excellent discussion in Kanasewich. 2864 2865 References 2866 ---------- 2867 .. [1] M.S. Bartlett, "Periodogram Analysis and Continuous Spectra", 2868 Biometrika 37, 1-16, 1950. 2869 .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics", 2870 The University of Alberta Press, 1975, pp. 109-110. 2871 .. [3] A.V. Oppenheim and R.W. Schafer, "Discrete-Time Signal 2872 Processing", Prentice-Hall, 1999, pp. 468-471. 2873 .. [4] Wikipedia, "Window function", 2874 http://en.wikipedia.org/wiki/Window_function 2875 .. [5] W.H. Press, B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling, 2876 "Numerical Recipes", Cambridge University Press, 1986, page 429. 2877 2878 2879 Examples 2880 -------- 2881 >>> np.bartlett(12) 2882 array([ 0. , 0.18181818, 0.36363636, 0.54545455, 0.72727273, 2883 0.90909091, 0.90909091, 0.72727273, 0.54545455, 0.36363636, 2884 0.18181818, 0. ]) 2885 2886 Plot the window and its frequency response (requires SciPy and matplotlib): 2887 2888 >>> from numpy.fft import fft, fftshift 2889 >>> window = np.bartlett(51) 2890 >>> plt.plot(window) 2891 [<matplotlib.lines.Line2D object at 0x...>] 2892 >>> plt.title("Bartlett window") 2893 <matplotlib.text.Text object at 0x...> 2894 >>> plt.ylabel("Amplitude") 2895 <matplotlib.text.Text object at 0x...> 2896 >>> plt.xlabel("Sample") 2897 <matplotlib.text.Text object at 0x...> 2898 >>> plt.show() 2899 2900 >>> plt.figure() 2901 <matplotlib.figure.Figure object at 0x...> 2902 >>> A = fft(window, 2048) / 25.5 2903 >>> mag = np.abs(fftshift(A)) 2904 >>> freq = np.linspace(-0.5, 0.5, len(A)) 2905 >>> response = 20 * np.log10(mag) 2906 >>> response = np.clip(response, -100, 100) 2907 >>> plt.plot(freq, response) 2908 [<matplotlib.lines.Line2D object at 0x...>] 2909 >>> plt.title("Frequency response of Bartlett window") 2910 <matplotlib.text.Text object at 0x...> 2911 >>> plt.ylabel("Magnitude [dB]") 2912 <matplotlib.text.Text object at 0x...> 2913 >>> plt.xlabel("Normalized frequency [cycles per sample]") 2914 <matplotlib.text.Text object at 0x...> 2915 >>> plt.axis('tight') 2916 (-0.5, 0.5, -100.0, ...) 2917 >>> plt.show() 2918 2919 """ 2920 return array() 2921 def base_repr(number=0, base=2, padding=0): 2922 """ 2923 Return a string representation of a number in the given base system. 2924 2925 Parameters 2926 ---------- 2927 number : int 2928 The value to convert. Only positive values are handled. 2929 base : int, optional 2930 Convert `number` to the `base` number system. The valid range is 2-36, 2931 the default value is 2. 2932 padding : int, optional 2933 Number of zeros padded on the left. Default is 0 (no padding). 2934 2935 Returns 2936 ------- 2937 out : str 2938 String representation of `number` in `base` system. 2939 2940 See Also 2941 -------- 2942 binary_repr : Faster version of `base_repr` for base 2. 2943 2944 Examples 2945 -------- 2946 >>> np.base_repr(5) 2947 '101' 2948 >>> np.base_repr(6, 5) 2949 '11' 2950 >>> np.base_repr(7, base=5, padding=3) 2951 '00012' 2952 2953 >>> np.base_repr(10, base=16) 2954 'A' 2955 >>> np.base_repr(32, base=16) 2956 '20' 2957 2958 """ 2959 return str() 2960 def bench(self=None, label="fast", verbose=1, extra_argv=None): 2961 """ 2962 Run benchmarks for module using nose. 2963 2964 Parameters 2965 ---------- 2966 label : {'fast', 'full', '', attribute identifier}, optional 2967 Identifies the benchmarks to run. This can be a string to pass to 2968 the nosetests executable with the '-A' option, or one of several 2969 special values. Special values are: 2970 * 'fast' - the default - which corresponds to the ``nosetests -A`` 2971 option of 'not slow'. 2972 * 'full' - fast (as above) and slow benchmarks as in the 2973 'no -A' option to nosetests - this is the same as ''. 2974 * None or '' - run all tests. 2975 attribute_identifier - string passed directly to nosetests as '-A'. 2976 verbose : int, optional 2977 Verbosity value for benchmark outputs, in the range 1-10. Default is 1. 2978 extra_argv : list, optional 2979 List with any extra arguments to pass to nosetests. 2980 2981 Returns 2982 ------- 2983 success : bool 2984 Returns True if running the benchmarks works, False if an error 2985 occurred. 2986 2987 Notes 2988 ----- 2989 Benchmarks are like tests, but have names starting with "bench" instead 2990 of "test", and can be found under the "benchmarks" sub-directory of the 2991 module. 2992 2993 Each NumPy module exposes `bench` in its namespace to run all benchmarks 2994 for it. 2995 2996 Examples 2997 -------- 2998 >>> success = np.lib.bench() #doctest: +SKIP 2999 Running benchmarks for numpy.lib 3000 ... 3001 using 562341 items: 3002 unique: 3003 0.11 3004 unique1d: 3005 0.11 3006 ratio: 1.0 3007 nUnique: 56230 == 56230 3008 ... 3009 OK 3010 3011 >>> success #doctest: +SKIP 3012 True 3013 3014 """ 3015 return bool() 3016 def binary_repr(num=None, width=None): 3017 """ 3018 Return the binary representation of the input number as a string. 3019 3020 For negative numbers, if width is not given, a minus sign is added to the 3021 front. If width is given, the two's complement of the number is 3022 returned, with respect to that width. 3023 3024 In a two's-complement system negative numbers are represented by the two's 3025 complement of the absolute value. This is the most common method of 3026 representing signed integers on computers [1]_. A N-bit two's-complement 3027 system can represent every integer in the range 3028 :math:`-2^{N-1}` to :math:`+2^{N-1}-1`. 3029 3030 Parameters 3031 ---------- 3032 num : int 3033 Only an integer decimal number can be used. 3034 width : int, optional 3035 The length of the returned string if `num` is positive, the length of 3036 the two's complement if `num` is negative. 3037 3038 Returns 3039 ------- 3040 bin : str 3041 Binary representation of `num` or two's complement of `num`. 3042 3043 See Also 3044 -------- 3045 base_repr: Return a string representation of a number in the given base 3046 system. 3047 3048 Notes 3049 ----- 3050 `binary_repr` is equivalent to using `base_repr` with base 2, but about 25x 3051 faster. 3052 3053 References 3054 ---------- 3055 .. [1] Wikipedia, "Two's complement", 3056 http://en.wikipedia.org/wiki/Two's_complement 3057 3058 Examples 3059 -------- 3060 >>> np.binary_repr(3) 3061 '11' 3062 >>> np.binary_repr(-3) 3063 '-11' 3064 >>> np.binary_repr(3, width=4) 3065 '0011' 3066 3067 The two's complement is returned when the input number is negative and 3068 width is specified: 3069 3070 >>> np.binary_repr(-3, width=4) 3071 '1101' 3072 3073 """ 3074 return str() 3075 def bincount(x, weights, minlength): 3076 """bincount(x, weights=None, minlength=None) 3077 3078 Count number of occurrences of each value in array of non-negative ints. 3079 3080 The number of bins (of size 1) is one larger than the largest value in 3081 `x`. If `minlength` is specified, there will be at least this number 3082 of bins in the output array (though it will be longer if necessary, 3083 depending on the contents of `x`). 3084 Each bin gives the number of occurrences of its index value in `x`. 3085 If `weights` is specified the input array is weighted by it, i.e. if a 3086 value ``n`` is found at position ``i``, ``out[n] += weight[i]`` instead 3087 of ``out[n] += 1``. 3088 3089 Parameters 3090 ---------- 3091 x : array_like, 1 dimension, nonnegative ints 3092 Input array. 3093 weights : array_like, optional 3094 Weights, array of the same shape as `x`. 3095 minlength : int, optional 3096 .. versionadded:: 1.6.0 3097 3098 A minimum number of bins for the output array. 3099 3100 Returns 3101 ------- 3102 out : ndarray of ints 3103 The result of binning the input array. 3104 The length of `out` is equal to ``np.amax(x)+1``. 3105 3106 Raises 3107 ------ 3108 ValueError 3109 If the input is not 1-dimensional, or contains elements with negative 3110 values, or if `minlength` is non-positive. 3111 TypeError 3112 If the type of the input is float or complex. 3113 3114 See Also 3115 -------- 3116 histogram, digitize, unique 3117 3118 Examples 3119 -------- 3120 >>> np.bincount(np.arange(5)) 3121 array([1, 1, 1, 1, 1]) 3122 >>> np.bincount(np.array([0, 1, 1, 3, 2, 1, 7])) 3123 array([1, 3, 1, 1, 0, 0, 0, 1]) 3124 3125 >>> x = np.array([0, 1, 1, 3, 2, 1, 7, 23]) 3126 >>> np.bincount(x).size == np.amax(x)+1 3127 True 3128 3129 The input array needs to be of integer dtype, otherwise a 3130 TypeError is raised: 3131 3132 >>> np.bincount(np.arange(5, dtype=np.float)) 3133 Traceback (most recent call last): 3134 File "<stdin>", line 1, in <module> 3135 TypeError: array cannot be safely cast to required type 3136 3137 A possible use of ``bincount`` is to perform sums over 3138 variable-size chunks of an array, using the ``weights`` keyword. 3139 3140 >>> w = np.array([0.3, 0.5, 0.2, 0.7, 1., -0.6]) # weights 3141 >>> x = np.array([0, 1, 1, 2, 2, 2]) 3142 >>> np.bincount(x, weights=w) 3143 array([ 0.3, 0.7, 1.1])""" 3144 return ndarray() 3145 def bitwise_and(x1, x2, out=None): 3146 """bitwise_and(x1, x2[, out]) 3147 3148 Compute the bit-wise AND of two arrays element-wise. 3149 3150 Computes the bit-wise AND of the underlying binary representation of 3151 the integers in the input arrays. This ufunc implements the C/Python 3152 operator ``&``. 3153 3154 Parameters 3155 ---------- 3156 x1, x2 : array_like 3157 Only integer types are handled (including booleans). 3158 3159 Returns 3160 ------- 3161 out : array_like 3162 Result. 3163 3164 See Also 3165 -------- 3166 logical_and 3167 bitwise_or 3168 bitwise_xor 3169 binary_repr : 3170 Return the binary representation of the input number as a string. 3171 3172 Examples 3173 -------- 3174 The number 13 is represented by ``00001101``. Likewise, 17 is 3175 represented by ``00010001``. The bit-wise AND of 13 and 17 is 3176 therefore ``000000001``, or 1: 3177 3178 >>> np.bitwise_and(13, 17) 3179 1 3180 3181 >>> np.bitwise_and(14, 13) 3182 12 3183 >>> np.binary_repr(12) 3184 '1100' 3185 >>> np.bitwise_and([14,3], 13) 3186 array([12, 1]) 3187 3188 >>> np.bitwise_and([11,7], [4,25]) 3189 array([0, 1]) 3190 >>> np.bitwise_and(np.array([2,5,255]), np.array([3,14,16])) 3191 array([ 2, 4, 16]) 3192 >>> np.bitwise_and([True, True], [False, True]) 3193 array([False, True], dtype=bool)""" 3194 return ndarray() 3195 def invert(x, out=None): 3196 """invert(x[, out]) 3197 3198 Compute bit-wise inversion, or bit-wise NOT, element-wise. 3199 3200 Computes the bit-wise NOT of the underlying binary representation of 3201 the integers in the input arrays. This ufunc implements the C/Python 3202 operator ``~``. 3203 3204 For signed integer inputs, the two's complement is returned. 3205 In a two's-complement system negative numbers are represented by the two's 3206 complement of the absolute value. This is the most common method of 3207 representing signed integers on computers [1]_. A N-bit two's-complement 3208 system can represent every integer in the range 3209 :math:`-2^{N-1}` to :math:`+2^{N-1}-1`. 3210 3211 Parameters 3212 ---------- 3213 x1 : array_like 3214 Only integer types are handled (including booleans). 3215 3216 Returns 3217 ------- 3218 out : array_like 3219 Result. 3220 3221 See Also 3222 -------- 3223 bitwise_and, bitwise_or, bitwise_xor 3224 logical_not 3225 binary_repr : 3226 Return the binary representation of the input number as a string. 3227 3228 Notes 3229 ----- 3230 `bitwise_not` is an alias for `invert`: 3231 3232 >>> np.bitwise_not is np.invert 3233 True 3234 3235 References 3236 ---------- 3237 .. [1] Wikipedia, "Two's complement", 3238 http://en.wikipedia.org/wiki/Two's_complement 3239 3240 Examples 3241 -------- 3242 We've seen that 13 is represented by ``00001101``. 3243 The invert or bit-wise NOT of 13 is then: 3244 3245 >>> np.invert(np.array([13], dtype=uint8)) 3246 array([242], dtype=uint8) 3247 >>> np.binary_repr(x, width=8) 3248 '00001101' 3249 >>> np.binary_repr(242, width=8) 3250 '11110010' 3251 3252 The result depends on the bit-width: 3253 3254 >>> np.invert(np.array([13], dtype=uint16)) 3255 array([65522], dtype=uint16) 3256 >>> np.binary_repr(x, width=16) 3257 '0000000000001101' 3258 >>> np.binary_repr(65522, width=16) 3259 '1111111111110010' 3260 3261 When using signed integer types the result is the two's complement of 3262 the result for the unsigned type: 3263 3264 >>> np.invert(np.array([13], dtype=int8)) 3265 array([-14], dtype=int8) 3266 >>> np.binary_repr(-14, width=8) 3267 '11110010' 3268 3269 Booleans are accepted as well: 3270 3271 >>> np.invert(array([True, False])) 3272 array([False, True], dtype=bool)""" 3273 return ndarray() 3274 def bitwise_or(x1, x2, out=None): 3275 """bitwise_or(x1, x2[, out]) 3276 3277 Compute the bit-wise OR of two arrays element-wise. 3278 3279 Computes the bit-wise OR of the underlying binary representation of 3280 the integers in the input arrays. This ufunc implements the C/Python 3281 operator ``|``. 3282 3283 Parameters 3284 ---------- 3285 x1, x2 : array_like 3286 Only integer types are handled (including booleans). 3287 out : ndarray, optional 3288 Array into which the output is placed. Its type is preserved and it 3289 must be of the right shape to hold the output. See doc.ufuncs. 3290 3291 Returns 3292 ------- 3293 out : array_like 3294 Result. 3295 3296 See Also 3297 -------- 3298 logical_or 3299 bitwise_and 3300 bitwise_xor 3301 binary_repr : 3302 Return the binary representation of the input number as a string. 3303 3304 Examples 3305 -------- 3306 The number 13 has the binaray representation ``00001101``. Likewise, 3307 16 is represented by ``00010000``. The bit-wise OR of 13 and 16 is 3308 then ``000111011``, or 29: 3309 3310 >>> np.bitwise_or(13, 16) 3311 29 3312 >>> np.binary_repr(29) 3313 '11101' 3314 3315 >>> np.bitwise_or(32, 2) 3316 34 3317 >>> np.bitwise_or([33, 4], 1) 3318 array([33, 5]) 3319 >>> np.bitwise_or([33, 4], [1, 2]) 3320 array([33, 6]) 3321 3322 >>> np.bitwise_or(np.array([2, 5, 255]), np.array([4, 4, 4])) 3323 array([ 6, 5, 255]) 3324 >>> np.array([2, 5, 255]) | np.array([4, 4, 4]) 3325 array([ 6, 5, 255]) 3326 >>> np.bitwise_or(np.array([2, 5, 255, 2147483647L], dtype=np.int32), 3327 ... np.array([4, 4, 4, 2147483647L], dtype=np.int32)) 3328 array([ 6, 5, 255, 2147483647]) 3329 >>> np.bitwise_or([True, True], [False, True]) 3330 array([ True, True], dtype=bool)""" 3331 return ndarray() 3332 def bitwise_xor(x1, x2, out=None): 3333 """bitwise_xor(x1, x2[, out]) 3334 3335 Compute the bit-wise XOR of two arrays element-wise. 3336 3337 Computes the bit-wise XOR of the underlying binary representation of 3338 the integers in the input arrays. This ufunc implements the C/Python 3339 operator ``^``. 3340 3341 Parameters 3342 ---------- 3343 x1, x2 : array_like 3344 Only integer types are handled (including booleans). 3345 3346 Returns 3347 ------- 3348 out : array_like 3349 Result. 3350 3351 See Also 3352 -------- 3353 logical_xor 3354 bitwise_and 3355 bitwise_or 3356 binary_repr : 3357 Return the binary representation of the input number as a string. 3358 3359 Examples 3360 -------- 3361 The number 13 is represented by ``00001101``. Likewise, 17 is 3362 represented by ``00010001``. The bit-wise XOR of 13 and 17 is 3363 therefore ``00011100``, or 28: 3364 3365 >>> np.bitwise_xor(13, 17) 3366 28 3367 >>> np.binary_repr(28) 3368 '11100' 3369 3370 >>> np.bitwise_xor(31, 5) 3371 26 3372 >>> np.bitwise_xor([31,3], 5) 3373 array([26, 6]) 3374 3375 >>> np.bitwise_xor([31,3], [5,6]) 3376 array([26, 5]) 3377 >>> np.bitwise_xor([True, True], [False, True]) 3378 array([ True, False], dtype=bool)""" 3379 return ndarray() 3380 def blackman(M): 3381 """ 3382 Return the Blackman window. 3383 3384 The Blackman window is a taper formed by using the the first three 3385 terms of a summation of cosines. It was designed to have close to the 3386 minimal leakage possible. It is close to optimal, only slightly worse 3387 than a Kaiser window. 3388 3389 Parameters 3390 ---------- 3391 M : int 3392 Number of points in the output window. If zero or less, an empty 3393 array is returned. 3394 3395 Returns 3396 ------- 3397 out : ndarray 3398 The window, with the maximum value normalized to one (the value one 3399 appears only if the number of samples is odd). 3400 3401 See Also 3402 -------- 3403 bartlett, hamming, hanning, kaiser 3404 3405 Notes 3406 ----- 3407 The Blackman window is defined as 3408 3409 .. math:: w(n) = 0.42 - 0.5 \cos(2\pi n/M) + 0.08 \cos(4\pi n/M) 3410 3411 Most references to the Blackman window come from the signal processing 3412 literature, where it is used as one of many windowing functions for 3413 smoothing values. It is also known as an apodization (which means 3414 "removing the foot", i.e. smoothing discontinuities at the beginning 3415 and end of the sampled signal) or tapering function. It is known as a 3416 "near optimal" tapering function, almost as good (by some measures) 3417 as the kaiser window. 3418 3419 References 3420 ---------- 3421 Blackman, R.B. and Tukey, J.W., (1958) The measurement of power spectra, 3422 Dover Publications, New York. 3423 3424 Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing. 3425 Upper Saddle River, NJ: Prentice-Hall, 1999, pp. 468-471. 3426 3427 Examples 3428 -------- 3429 >>> np.blackman(12) 3430 array([ -1.38777878e-17, 3.26064346e-02, 1.59903635e-01, 3431 4.14397981e-01, 7.36045180e-01, 9.67046769e-01, 3432 9.67046769e-01, 7.36045180e-01, 4.14397981e-01, 3433 1.59903635e-01, 3.26064346e-02, -1.38777878e-17]) 3434 3435 3436 Plot the window and the frequency response: 3437 3438 >>> from numpy.fft import fft, fftshift 3439 >>> window = np.blackman(51) 3440 >>> plt.plot(window) 3441 [<matplotlib.lines.Line2D object at 0x...>] 3442 >>> plt.title("Blackman window") 3443 <matplotlib.text.Text object at 0x...> 3444 >>> plt.ylabel("Amplitude") 3445 <matplotlib.text.Text object at 0x...> 3446 >>> plt.xlabel("Sample") 3447 <matplotlib.text.Text object at 0x...> 3448 >>> plt.show() 3449 3450 >>> plt.figure() 3451 <matplotlib.figure.Figure object at 0x...> 3452 >>> A = fft(window, 2048) / 25.5 3453 >>> mag = np.abs(fftshift(A)) 3454 >>> freq = np.linspace(-0.5, 0.5, len(A)) 3455 >>> response = 20 * np.log10(mag) 3456 >>> response = np.clip(response, -100, 100) 3457 >>> plt.plot(freq, response) 3458 [<matplotlib.lines.Line2D object at 0x...>] 3459 >>> plt.title("Frequency response of Blackman window") 3460 <matplotlib.text.Text object at 0x...> 3461 >>> plt.ylabel("Magnitude [dB]") 3462 <matplotlib.text.Text object at 0x...> 3463 >>> plt.xlabel("Normalized frequency [cycles per sample]") 3464 <matplotlib.text.Text object at 0x...> 3465 >>> plt.axis('tight') 3466 (-0.5, 0.5, -100.0, ...) 3467 >>> plt.show() 3468 3469 """ 3470 return ndarray() 3471 def bmat(obj=None, ldict=None, gdict=None): 3472 """ 3473 Build a matrix object from a string, nested sequence, or array. 3474 3475 Parameters 3476 ---------- 3477 obj : str or array_like 3478 Input data. Names of variables in the current scope may be 3479 referenced, even if `obj` is a string. 3480 3481 Returns 3482 ------- 3483 out : matrix 3484 Returns a matrix object, which is a specialized 2-D array. 3485 3486 See Also 3487 -------- 3488 matrix 3489 3490 Examples 3491 -------- 3492 >>> A = np.mat('1 1; 1 1') 3493 >>> B = np.mat('2 2; 2 2') 3494 >>> C = np.mat('3 4; 5 6') 3495 >>> D = np.mat('7 8; 9 0') 3496 3497 All the following expressions construct the same block matrix: 3498 3499 >>> np.bmat([[A, B], [C, D]]) 3500 matrix([[1, 1, 2, 2], 3501 [1, 1, 2, 2], 3502 [3, 4, 7, 8], 3503 [5, 6, 9, 0]]) 3504 >>> np.bmat(np.r_[np.c_[A, B], np.c_[C, D]]) 3505 matrix([[1, 1, 2, 2], 3506 [1, 1, 2, 2], 3507 [3, 4, 7, 8], 3508 [5, 6, 9, 0]]) 3509 >>> np.bmat('A,B; C,D') 3510 matrix([[1, 1, 2, 2], 3511 [1, 1, 2, 2], 3512 [3, 4, 7, 8], 3513 [5, 6, 9, 0]]) 3514 3515 """ 3516 return matrix() 3517 class bool: 3518 __doc__ = str() 3519 def bit_length(self, _): 3520 """int.bit_length() -> int 3521 3522 Number of bits necessary to represent self in binary. 3523 >>> bin(37) 3524 '0b100101' 3525 >>> (37).bit_length() 3526 6""" 3527 return None 3528 def conjugate(self, _): 3529 """Returns self, the complex conjugate of any int.""" 3530 return None 3531 denominator = getset_descriptor() 3532 imag = getset_descriptor() 3533 numerator = getset_descriptor() 3534 real = getset_descriptor() 3535 class bool_: 3536 T = getset_descriptor() 3537 __array_interface__ = getset_descriptor() 3538 __array_priority__ = getset_descriptor() 3539 __array_struct__ = getset_descriptor() 3540 __doc__ = str() 3541 base = getset_descriptor() 3542 def conj(self, _): 3543 """None""" 3544 return None 3545 data = getset_descriptor() 3546 dtype = getset_descriptor() 3547 flags = getset_descriptor() 3548 flat = getset_descriptor() 3549 imag = getset_descriptor() 3550 itemsize = getset_descriptor() 3551 nbytes = getset_descriptor() 3552 ndim = getset_descriptor() 3553 def newbyteorder(self, new_order): 3554 """newbyteorder(new_order='S') 3555 3556 Return a new `dtype` with a different byte order. 3557 3558 Changes are also made in all fields and sub-arrays of the data type. 3559 3560 The `new_order` code can be any from the following: 3561 3562 * {'<', 'L'} - little endian 3563 * {'>', 'B'} - big endian 3564 * {'=', 'N'} - native order 3565 * 'S' - swap dtype from current to opposite endian 3566 * {'|', 'I'} - ignore (no change to byte order) 3567 3568 Parameters 3569 ---------- 3570 new_order : str, optional 3571 Byte order to force; a value from the byte order specifications 3572 above. The default value ('S') results in swapping the current 3573 byte order. The code does a case-insensitive check on the first 3574 letter of `new_order` for the alternatives above. For example, 3575 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 3576 3577 3578 Returns 3579 ------- 3580 new_dtype : dtype 3581 New `dtype` object with the given change to the byte order.""" 3582 return dtype() 3583 real = getset_descriptor() 3584 shape = getset_descriptor() 3585 size = getset_descriptor() 3586 strides = getset_descriptor() 3587 class bool_: 3588 T = getset_descriptor() 3589 __array_interface__ = getset_descriptor() 3590 __array_priority__ = getset_descriptor() 3591 __array_struct__ = getset_descriptor() 3592 __doc__ = str() 3593 base = getset_descriptor() 3594 def conj(self, _): 3595 """None""" 3596 return None 3597 data = getset_descriptor() 3598 dtype = getset_descriptor() 3599 flags = getset_descriptor() 3600 flat = getset_descriptor() 3601 imag = getset_descriptor() 3602 itemsize = getset_descriptor() 3603 nbytes = getset_descriptor() 3604 ndim = getset_descriptor() 3605 def newbyteorder(self, new_order): 3606 """newbyteorder(new_order='S') 3607 3608 Return a new `dtype` with a different byte order. 3609 3610 Changes are also made in all fields and sub-arrays of the data type. 3611 3612 The `new_order` code can be any from the following: 3613 3614 * {'<', 'L'} - little endian 3615 * {'>', 'B'} - big endian 3616 * {'=', 'N'} - native order 3617 * 'S' - swap dtype from current to opposite endian 3618 * {'|', 'I'} - ignore (no change to byte order) 3619 3620 Parameters 3621 ---------- 3622 new_order : str, optional 3623 Byte order to force; a value from the byte order specifications 3624 above. The default value ('S') results in swapping the current 3625 byte order. The code does a case-insensitive check on the first 3626 letter of `new_order` for the alternatives above. For example, 3627 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 3628 3629 3630 Returns 3631 ------- 3632 new_dtype : dtype 3633 New `dtype` object with the given change to the byte order.""" 3634 return dtype() 3635 real = getset_descriptor() 3636 shape = getset_descriptor() 3637 size = getset_descriptor() 3638 strides = getset_descriptor() 3639 class broadcast: 3640 __doc__ = str() 3641 index = getset_descriptor() 3642 iters = getset_descriptor() 3643 nd = member_descriptor() 3644 def next(self, _): 3645 """x.next() -> the next value, or raise StopIteration""" 3646 return None 3647 numiter = member_descriptor() 3648 def reset(self, _): 3649 """reset() 3650 3651 Reset the broadcasted result's iterator(s). 3652 3653 Parameters 3654 ---------- 3655 None 3656 3657 Returns 3658 ------- 3659 None 3660 3661 Examples 3662 -------- 3663 >>> x = np.array([1, 2, 3]) 3664 >>> y = np.array([[4], [5], [6]] 3665 >>> b = np.broadcast(x, y) 3666 >>> b.index 3667 0 3668 >>> b.next(), b.next(), b.next() 3669 ((1, 4), (2, 4), (3, 4)) 3670 >>> b.index 3671 3 3672 >>> b.reset() 3673 >>> b.index 3674 0""" 3675 return None 3676 shape = getset_descriptor() 3677 size = getset_descriptor() 3678 def broadcast_arrays(): 3679 """ 3680 Broadcast any number of arrays against each other. 3681 3682 Parameters 3683 ---------- 3684 `*args` : array_likes 3685 The arrays to broadcast. 3686 3687 Returns 3688 ------- 3689 broadcasted : list of arrays 3690 These arrays are views on the original arrays. They are typically 3691 not contiguous. Furthermore, more than one element of a 3692 broadcasted array may refer to a single memory location. If you 3693 need to write to the arrays, make copies first. 3694 3695 Examples 3696 -------- 3697 >>> x = np.array([[1,2,3]]) 3698 >>> y = np.array([[1],[2],[3]]) 3699 >>> np.broadcast_arrays(x, y) 3700 [array([[1, 2, 3], 3701 [1, 2, 3], 3702 [1, 2, 3]]), array([[1, 1, 1], 3703 [2, 2, 2], 3704 [3, 3, 3]])] 3705 3706 Here is a useful idiom for getting contiguous copies instead of 3707 non-contiguous views. 3708 3709 >>> [np.array(a) for a in np.broadcast_arrays(x, y)] 3710 [array([[1, 2, 3], 3711 [1, 2, 3], 3712 [1, 2, 3]]), array([[1, 1, 1], 3713 [2, 2, 2], 3714 [3, 3, 3]])] 3715 3716 """ 3717 return list() 3718 def busday_count(begindates, enddates, weekmask, holidays, busdaycal, out): 3719 """busday_count(begindates, enddates, weekmask='1111100', holidays=[], busdaycal=None, out=None) 3720 3721 Counts the number of valid days between `begindates` and 3722 `enddates`, not including the day of `enddates`. 3723 3724 If ``enddates`` specifies a date value that is earlier than the 3725 corresponding ``begindates`` date value, the count will be negative. 3726 3727 .. versionadded:: 1.7.0 3728 3729 Parameters 3730 ---------- 3731 begindates : array_like of datetime64[D] 3732 The array of the first dates for counting. 3733 enddates : array_like of datetime64[D] 3734 The array of the end dates for counting, which are excluded 3735 from the count themselves. 3736 weekmask : str or array_like of bool, optional 3737 A seven-element array indicating which of Monday through Sunday are 3738 valid days. May be specified as a length-seven list or array, like 3739 [1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string 3740 like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for 3741 weekdays, optionally separated by white space. Valid abbreviations 3742 are: Mon Tue Wed Thu Fri Sat Sun 3743 holidays : array_like of datetime64[D], optional 3744 An array of dates to consider as invalid dates. They may be 3745 specified in any order, and NaT (not-a-time) dates are ignored. 3746 This list is saved in a normalized form that is suited for 3747 fast calculations of valid days. 3748 busdaycal : busdaycalendar, optional 3749 A `busdaycalendar` object which specifies the valid days. If this 3750 parameter is provided, neither weekmask nor holidays may be 3751 provided. 3752 out : array of int, optional 3753 If provided, this array is filled with the result. 3754 3755 Returns 3756 ------- 3757 out : array of int 3758 An array with a shape from broadcasting ``begindates`` and ``enddates`` 3759 together, containing the number of valid days between 3760 the begin and end dates. 3761 3762 See Also 3763 -------- 3764 busdaycalendar: An object that specifies a custom set of valid days. 3765 is_busday : Returns a boolean array indicating valid days. 3766 busday_offset : Applies an offset counted in valid days. 3767 3768 Examples 3769 -------- 3770 >>> # Number of weekdays in January 2011 3771 ... np.busday_count('2011-01', '2011-02') 3772 21 3773 >>> # Number of weekdays in 2011 3774 ... np.busday_count('2011', '2012') 3775 260 3776 >>> # Number of Saturdays in 2011 3777 ... np.busday_count('2011', '2012', weekmask='Sat') 3778 53""" 3779 return array() 3780 def busday_offset(dates, offsets, roll, weekmask, holidays, busdaycal, out): 3781 """busday_offset(dates, offsets, roll='raise', weekmask='1111100', holidays=None, busdaycal=None, out=None) 3782 3783 First adjusts the date to fall on a valid day according to 3784 the ``roll`` rule, then applies offsets to the given dates 3785 counted in valid days. 3786 3787 .. versionadded:: 1.7.0 3788 3789 Parameters 3790 ---------- 3791 dates : array_like of datetime64[D] 3792 The array of dates to process. 3793 offsets : array_like of int 3794 The array of offsets, which is broadcast with ``dates``. 3795 roll : {'raise', 'nat', 'forward', 'following', 'backward', 'preceding', 'modifiedfollowing', 'modifiedpreceding'}, optional 3796 How to treat dates that do not fall on a valid day. The default 3797 is 'raise'. 3798 3799 * 'raise' means to raise an exception for an invalid day. 3800 * 'nat' means to return a NaT (not-a-time) for an invalid day. 3801 * 'forward' and 'following' mean to take the first valid day 3802 later in time. 3803 * 'backward' and 'preceding' mean to take the first valid day 3804 earlier in time. 3805 * 'modifiedfollowing' means to take the first valid day 3806 later in time unless it is across a Month boundary, in which 3807 case to take the first valid day earlier in time. 3808 * 'modifiedpreceding' means to take the first valid day 3809 earlier in time unless it is across a Month boundary, in which 3810 case to take the first valid day later in time. 3811 weekmask : str or array_like of bool, optional 3812 A seven-element array indicating which of Monday through Sunday are 3813 valid days. May be specified as a length-seven list or array, like 3814 [1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string 3815 like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for 3816 weekdays, optionally separated by white space. Valid abbreviations 3817 are: Mon Tue Wed Thu Fri Sat Sun 3818 holidays : array_like of datetime64[D], optional 3819 An array of dates to consider as invalid dates. They may be 3820 specified in any order, and NaT (not-a-time) dates are ignored. 3821 This list is saved in a normalized form that is suited for 3822 fast calculations of valid days. 3823 busdaycal : busdaycalendar, optional 3824 A `busdaycalendar` object which specifies the valid days. If this 3825 parameter is provided, neither weekmask nor holidays may be 3826 provided. 3827 out : array of datetime64[D], optional 3828 If provided, this array is filled with the result. 3829 3830 Returns 3831 ------- 3832 out : array of datetime64[D] 3833 An array with a shape from broadcasting ``dates`` and ``offsets`` 3834 together, containing the dates with offsets applied. 3835 3836 See Also 3837 -------- 3838 busdaycalendar: An object that specifies a custom set of valid days. 3839 is_busday : Returns a boolean array indicating valid days. 3840 busday_count : Counts how many valid days are in a half-open date range. 3841 3842 Examples 3843 -------- 3844 >>> # First business day in October 2011 (not accounting for holidays) 3845 ... np.busday_offset('2011-10', 0, roll='forward') 3846 numpy.datetime64('2011-10-03','D') 3847 >>> # Last business day in February 2012 (not accounting for holidays) 3848 ... np.busday_offset('2012-03', -1, roll='forward') 3849 numpy.datetime64('2012-02-29','D') 3850 >>> # Third Wednesday in January 2011 3851 ... np.busday_offset('2011-01', 2, roll='forward', weekmask='Wed') 3852 numpy.datetime64('2011-01-19','D') 3853 >>> # 2012 Mother's Day in Canada and the U.S. 3854 ... np.busday_offset('2012-05', 1, roll='forward', weekmask='Sun') 3855 numpy.datetime64('2012-05-13','D') 3856 3857 >>> # First business day on or after a date 3858 ... np.busday_offset('2011-03-20', 0, roll='forward') 3859 numpy.datetime64('2011-03-21','D') 3860 >>> np.busday_offset('2011-03-22', 0, roll='forward') 3861 numpy.datetime64('2011-03-22','D') 3862 >>> # First business day after a date 3863 ... np.busday_offset('2011-03-20', 1, roll='backward') 3864 numpy.datetime64('2011-03-21','D') 3865 >>> np.busday_offset('2011-03-22', 1, roll='backward') 3866 numpy.datetime64('2011-03-23','D')""" 3867 return array() 3868 class busdaycalendar: 3869 __doc__ = str() 3870 holidays = getset_descriptor() 3871 weekmask = getset_descriptor() 3872 class int8: 3873 T = getset_descriptor() 3874 __array_interface__ = getset_descriptor() 3875 __array_priority__ = getset_descriptor() 3876 __array_struct__ = getset_descriptor() 3877 __doc__ = str() 3878 base = getset_descriptor() 3879 def conj(self, _): 3880 """None""" 3881 return None 3882 data = getset_descriptor() 3883 dtype = getset_descriptor() 3884 flags = getset_descriptor() 3885 flat = getset_descriptor() 3886 imag = getset_descriptor() 3887 itemsize = getset_descriptor() 3888 nbytes = getset_descriptor() 3889 ndim = getset_descriptor() 3890 def newbyteorder(self, new_order): 3891 """newbyteorder(new_order='S') 3892 3893 Return a new `dtype` with a different byte order. 3894 3895 Changes are also made in all fields and sub-arrays of the data type. 3896 3897 The `new_order` code can be any from the following: 3898 3899 * {'<', 'L'} - little endian 3900 * {'>', 'B'} - big endian 3901 * {'=', 'N'} - native order 3902 * 'S' - swap dtype from current to opposite endian 3903 * {'|', 'I'} - ignore (no change to byte order) 3904 3905 Parameters 3906 ---------- 3907 new_order : str, optional 3908 Byte order to force; a value from the byte order specifications 3909 above. The default value ('S') results in swapping the current 3910 byte order. The code does a case-insensitive check on the first 3911 letter of `new_order` for the alternatives above. For example, 3912 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 3913 3914 3915 Returns 3916 ------- 3917 new_dtype : dtype 3918 New `dtype` object with the given change to the byte order.""" 3919 return dtype() 3920 real = getset_descriptor() 3921 shape = getset_descriptor() 3922 size = getset_descriptor() 3923 strides = getset_descriptor() 3924 def byte_bounds(a): 3925 """ 3926 Returns pointers to the end-points of an array. 3927 3928 Parameters 3929 ---------- 3930 a : ndarray 3931 Input array. It must conform to the Python-side of the array interface. 3932 3933 Returns 3934 ------- 3935 (low, high) : tuple of 2 integers 3936 The first integer is the first byte of the array, the second integer is 3937 just past the last byte of the array. If `a` is not contiguous it 3938 will not use every byte between the (`low`, `high`) values. 3939 3940 Examples 3941 -------- 3942 >>> I = np.eye(2, dtype='f'); I.dtype 3943 dtype('float32') 3944 >>> low, high = np.byte_bounds(I) 3945 >>> high - low == I.size*I.itemsize 3946 True 3947 >>> I = np.eye(2, dtype='G'); I.dtype 3948 dtype('complex192') 3949 >>> low, high = np.byte_bounds(I) 3950 >>> high - low == I.size*I.itemsize 3951 True 3952 3953 """ 3954 return tuple() 3955 class string_: 3956 T = getset_descriptor() 3957 __array_interface__ = getset_descriptor() 3958 __array_priority__ = getset_descriptor() 3959 __array_struct__ = getset_descriptor() 3960 __doc__ = None 3961 def _formatter_field_name_split(self, _): 3962 """None""" 3963 return None 3964 def _formatter_parser(self, _): 3965 """None""" 3966 return None 3967 base = getset_descriptor() 3968 def capitalize(self, _): 3969 """S.capitalize() -> string 3970 3971 Return a copy of the string S with only its first character 3972 capitalized.""" 3973 return None 3974 def center(self, width, fillchar): 3975 """S.center(width[, fillchar]) -> string 3976 3977 Return S centered in a string of length width. Padding is 3978 done using the specified fill character (default is a space)""" 3979 return None 3980 def conj(self, _): 3981 """None""" 3982 return None 3983 def count(self, sub, start, end): 3984 """S.count(sub[, start[, end]]) -> int 3985 3986 Return the number of non-overlapping occurrences of substring sub in 3987 string S[start:end]. Optional arguments start and end are interpreted 3988 as in slice notation.""" 3989 return None 3990 data = getset_descriptor() 3991 def decode(self, encoding, errors): 3992 """S.decode([encoding[,errors]]) -> object 3993 3994 Decodes S using the codec registered for encoding. encoding defaults 3995 to the default encoding. errors may be given to set a different error 3996 handling scheme. Default is 'strict' meaning that encoding errors raise 3997 a UnicodeDecodeError. Other possible values are 'ignore' and 'replace' 3998 as well as any other name registered with codecs.register_error that is 3999 able to handle UnicodeDecodeErrors.""" 4000 return None 4001 dtype = getset_descriptor() 4002 def encode(self, encoding, errors): 4003 """S.encode([encoding[,errors]]) -> object 4004 4005 Encodes S using the codec registered for encoding. encoding defaults 4006 to the default encoding. errors may be given to set a different error 4007 handling scheme. Default is 'strict' meaning that encoding errors raise 4008 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 4009 'xmlcharrefreplace' as well as any other name registered with 4010 codecs.register_error that is able to handle UnicodeEncodeErrors.""" 4011 return None 4012 def endswith(self, suffix, start, end): 4013 """S.endswith(suffix[, start[, end]]) -> bool 4014 4015 Return True if S ends with the specified suffix, False otherwise. 4016 With optional start, test S beginning at that position. 4017 With optional end, stop comparing S at that position. 4018 suffix can also be a tuple of strings to try.""" 4019 return None 4020 def expandtabs(self, tabsize): 4021 """S.expandtabs([tabsize]) -> string 4022 4023 Return a copy of S where all tab characters are expanded using spaces. 4024 If tabsize is not given, a tab size of 8 characters is assumed.""" 4025 return None 4026 def find(self, sub, start, end): 4027 """S.find(sub [,start [,end]]) -> int 4028 4029 Return the lowest index in S where substring sub is found, 4030 such that sub is contained within S[start:end]. Optional 4031 arguments start and end are interpreted as in slice notation. 4032 4033 Return -1 on failure.""" 4034 return None 4035 flags = getset_descriptor() 4036 flat = getset_descriptor() 4037 def format(self, args, kwargs): 4038 """S.format(*args, **kwargs) -> string 4039 4040 Return a formatted version of S, using substitutions from args and kwargs. 4041 The substitutions are identified by braces ('{' and '}').""" 4042 return None 4043 imag = getset_descriptor() 4044 def index(self, sub, start, end): 4045 """S.index(sub [,start [,end]]) -> int 4046 4047 Like S.find() but raise ValueError when the substring is not found.""" 4048 return None 4049 def isalnum(self, _): 4050 """S.isalnum() -> bool 4051 4052 Return True if all characters in S are alphanumeric 4053 and there is at least one character in S, False otherwise.""" 4054 return None 4055 def isalpha(self, _): 4056 """S.isalpha() -> bool 4057 4058 Return True if all characters in S are alphabetic 4059 and there is at least one character in S, False otherwise.""" 4060 return None 4061 def isdigit(self, _): 4062 """S.isdigit() -> bool 4063 4064 Return True if all characters in S are digits 4065 and there is at least one character in S, False otherwise.""" 4066 return None 4067 def islower(self, _): 4068 """S.islower() -> bool 4069 4070 Return True if all cased characters in S are lowercase and there is 4071 at least one cased character in S, False otherwise.""" 4072 return None 4073 def isspace(self, _): 4074 """S.isspace() -> bool 4075 4076 Return True if all characters in S are whitespace 4077 and there is at least one character in S, False otherwise.""" 4078 return None 4079 def istitle(self, _): 4080 """S.istitle() -> bool 4081 4082 Return True if S is a titlecased string and there is at least one 4083 character in S, i.e. uppercase characters may only follow uncased 4084 characters and lowercase characters only cased ones. Return False 4085 otherwise.""" 4086 return None 4087 def isupper(self, _): 4088 """S.isupper() -> bool 4089 4090 Return True if all cased characters in S are uppercase and there is 4091 at least one cased character in S, False otherwise.""" 4092 return None 4093 itemsize = getset_descriptor() 4094 def join(self, iterable): 4095 """S.join(iterable) -> string 4096 4097 Return a string which is the concatenation of the strings in the 4098 iterable. The separator between elements is S.""" 4099 return None 4100 def ljust(self, width, fillchar): 4101 """S.ljust(width[, fillchar]) -> string 4102 4103 Return S left-justified in a string of length width. Padding is 4104 done using the specified fill character (default is a space).""" 4105 return None 4106 def lower(self, _): 4107 """S.lower() -> string 4108 4109 Return a copy of the string S converted to lowercase.""" 4110 return None 4111 def lstrip(self, chars): 4112 """S.lstrip([chars]) -> string or unicode 4113 4114 Return a copy of the string S with leading whitespace removed. 4115 If chars is given and not None, remove characters in chars instead. 4116 If chars is unicode, S will be converted to unicode before stripping""" 4117 return None 4118 nbytes = getset_descriptor() 4119 ndim = getset_descriptor() 4120 def newbyteorder(self, new_order): 4121 """newbyteorder(new_order='S') 4122 4123 Return a new `dtype` with a different byte order. 4124 4125 Changes are also made in all fields and sub-arrays of the data type. 4126 4127 The `new_order` code can be any from the following: 4128 4129 * {'<', 'L'} - little endian 4130 * {'>', 'B'} - big endian 4131 * {'=', 'N'} - native order 4132 * 'S' - swap dtype from current to opposite endian 4133 * {'|', 'I'} - ignore (no change to byte order) 4134 4135 Parameters 4136 ---------- 4137 new_order : str, optional 4138 Byte order to force; a value from the byte order specifications 4139 above. The default value ('S') results in swapping the current 4140 byte order. The code does a case-insensitive check on the first 4141 letter of `new_order` for the alternatives above. For example, 4142 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 4143 4144 4145 Returns 4146 ------- 4147 new_dtype : dtype 4148 New `dtype` object with the given change to the byte order.""" 4149 return dtype() 4150 def partition(self, sep): 4151 """S.partition(sep) -> (head, sep, tail) 4152 4153 Search for the separator sep in S, and return the part before it, 4154 the separator itself, and the part after it. If the separator is not 4155 found, return S and two empty strings.""" 4156 return None 4157 real = getset_descriptor() 4158 def replace(self, old, new, count): 4159 """S.replace(old, new[, count]) -> string 4160 4161 Return a copy of string S with all occurrences of substring 4162 old replaced by new. If the optional argument count is 4163 given, only the first count occurrences are replaced.""" 4164 return None 4165 def rfind(self, sub, start, end): 4166 """S.rfind(sub [,start [,end]]) -> int 4167 4168 Return the highest index in S where substring sub is found, 4169 such that sub is contained within S[start:end]. Optional 4170 arguments start and end are interpreted as in slice notation. 4171 4172 Return -1 on failure.""" 4173 return None 4174 def rindex(self, sub, start, end): 4175 """S.rindex(sub [,start [,end]]) -> int 4176 4177 Like S.rfind() but raise ValueError when the substring is not found.""" 4178 return None 4179 def rjust(self, width, fillchar): 4180 """S.rjust(width[, fillchar]) -> string 4181 4182 Return S right-justified in a string of length width. Padding is 4183 done using the specified fill character (default is a space)""" 4184 return None 4185 def rpartition(self, sep): 4186 """S.rpartition(sep) -> (head, sep, tail) 4187 4188 Search for the separator sep in S, starting at the end of S, and return 4189 the part before it, the separator itself, and the part after it. If the 4190 separator is not found, return two empty strings and S.""" 4191 return None 4192 def rsplit(self, sep, maxsplit): 4193 """S.rsplit([sep [,maxsplit]]) -> list of strings 4194 4195 Return a list of the words in the string S, using sep as the 4196 delimiter string, starting at the end of the string and working 4197 to the front. If maxsplit is given, at most maxsplit splits are 4198 done. If sep is not specified or is None, any whitespace string 4199 is a separator.""" 4200 return None 4201 def rstrip(self, chars): 4202 """S.rstrip([chars]) -> string or unicode 4203 4204 Return a copy of the string S with trailing whitespace removed. 4205 If chars is given and not None, remove characters in chars instead. 4206 If chars is unicode, S will be converted to unicode before stripping""" 4207 return None 4208 shape = getset_descriptor() 4209 size = getset_descriptor() 4210 def split(self, sep, maxsplit): 4211 """S.split([sep [,maxsplit]]) -> list of strings 4212 4213 Return a list of the words in the string S, using sep as the 4214 delimiter string. If maxsplit is given, at most maxsplit 4215 splits are done. If sep is not specified or is None, any 4216 whitespace string is a separator and empty strings are removed 4217 from the result.""" 4218 return None 4219 def splitlines(self, keepends=False): 4220 """S.splitlines(keepends=False) -> list of strings 4221 4222 Return a list of the lines in S, breaking at line boundaries. 4223 Line breaks are not included in the resulting list unless keepends 4224 is given and true.""" 4225 return None 4226 def startswith(self, prefix, start, end): 4227 """S.startswith(prefix[, start[, end]]) -> bool 4228 4229 Return True if S starts with the specified prefix, False otherwise. 4230 With optional start, test S beginning at that position. 4231 With optional end, stop comparing S at that position. 4232 prefix can also be a tuple of strings to try.""" 4233 return None 4234 strides = getset_descriptor() 4235 def strip(self, chars): 4236 """S.strip([chars]) -> string or unicode 4237 4238 Return a copy of the string S with leading and trailing 4239 whitespace removed. 4240 If chars is given and not None, remove characters in chars instead. 4241 If chars is unicode, S will be converted to unicode before stripping""" 4242 return None 4243 def swapcase(self, _): 4244 """S.swapcase() -> string 4245 4246 Return a copy of the string S with uppercase characters 4247 converted to lowercase and vice versa.""" 4248 return None 4249 def title(self, _): 4250 """S.title() -> string 4251 4252 Return a titlecased version of S, i.e. words start with uppercase 4253 characters, all remaining cased characters have lowercase.""" 4254 return None 4255 def translate(self, table, deletechars): 4256 """S.translate(table [,deletechars]) -> string 4257 4258 Return a copy of the string S, where all characters occurring 4259 in the optional argument deletechars are removed, and the 4260 remaining characters have been mapped through the given 4261 translation table, which must be a string of length 256 or None. 4262 If the table argument is None, no translation is applied and 4263 the operation simply removes the characters in deletechars.""" 4264 return None 4265 def upper(self, _): 4266 """S.upper() -> string 4267 4268 Return a copy of the string S converted to uppercase.""" 4269 return None 4270 def zfill(self, width): 4271 """S.zfill(width) -> string 4272 4273 Pad a numeric string S with zeros on the left, to fill a field 4274 of the specified width. The string S is never truncated.""" 4275 return None 4276 c_ = CClass() 4277 def can_cast(_from, totype, casting): 4278 """can_cast(from, totype, casting = 'safe') 4279 4280 Returns True if cast between data types can occur according to the 4281 casting rule. If from is a scalar or array scalar, also returns 4282 True if the scalar value can be cast without overflow or truncation 4283 to an integer. 4284 4285 Parameters 4286 ---------- 4287 from : dtype, dtype specifier, scalar, or array 4288 Data type, scalar, or array to cast from. 4289 totype : dtype or dtype specifier 4290 Data type to cast to. 4291 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional 4292 Controls what kind of data casting may occur. 4293 4294 * 'no' means the data types should not be cast at all. 4295 * 'equiv' means only byte-order changes are allowed. 4296 * 'safe' means only casts which can preserve values are allowed. 4297 * 'same_kind' means only safe casts or casts within a kind, 4298 like float64 to float32, are allowed. 4299 * 'unsafe' means any data conversions may be done. 4300 4301 Returns 4302 ------- 4303 out : bool 4304 True if cast can occur according to the casting rule. 4305 4306 See also 4307 -------- 4308 dtype, result_type 4309 4310 Examples 4311 -------- 4312 Basic examples 4313 4314 >>> np.can_cast(np.int32, np.int64) 4315 True 4316 >>> np.can_cast(np.float64, np.complex) 4317 True 4318 >>> np.can_cast(np.complex, np.float) 4319 False 4320 4321 >>> np.can_cast('i8', 'f8') 4322 True 4323 >>> np.can_cast('i8', 'f4') 4324 False 4325 >>> np.can_cast('i4', 'S4') 4326 True 4327 4328 Casting scalars 4329 4330 >>> np.can_cast(100, 'i1') 4331 True 4332 >>> np.can_cast(150, 'i1') 4333 False 4334 >>> np.can_cast(150, 'u1') 4335 True 4336 4337 >>> np.can_cast(3.5e100, np.float32) 4338 False 4339 >>> np.can_cast(1000.0, np.float32) 4340 True 4341 4342 Array scalar checks the value, array does not 4343 4344 >>> np.can_cast(np.array(1000.0), np.float32) 4345 True 4346 >>> np.can_cast(np.array([1000.0]), np.float32) 4347 False 4348 4349 Using the casting rules 4350 4351 >>> np.can_cast('i8', 'i8', 'no') 4352 True 4353 >>> np.can_cast('<i8', '>i8', 'no') 4354 False 4355 4356 >>> np.can_cast('<i8', '>i8', 'equiv') 4357 True 4358 >>> np.can_cast('<i4', '>i8', 'equiv') 4359 False 4360 4361 >>> np.can_cast('<i4', '>i8', 'safe') 4362 True 4363 >>> np.can_cast('<i8', '>i4', 'safe') 4364 False 4365 4366 >>> np.can_cast('<i8', '>i4', 'same_kind') 4367 True 4368 >>> np.can_cast('<i8', '>u4', 'same_kind') 4369 False 4370 4371 >>> np.can_cast('<i8', '>u4', 'unsafe') 4372 True""" 4373 return bool() 4374 cast = _typedict() 4375 class complex128: 4376 T = getset_descriptor() 4377 __array_interface__ = getset_descriptor() 4378 __array_priority__ = getset_descriptor() 4379 __array_struct__ = getset_descriptor() 4380 __doc__ = str() 4381 base = getset_descriptor() 4382 def conj(self, _): 4383 """None""" 4384 return None 4385 data = getset_descriptor() 4386 dtype = getset_descriptor() 4387 flags = getset_descriptor() 4388 flat = getset_descriptor() 4389 imag = getset_descriptor() 4390 itemsize = getset_descriptor() 4391 nbytes = getset_descriptor() 4392 ndim = getset_descriptor() 4393 def newbyteorder(self, new_order): 4394 """newbyteorder(new_order='S') 4395 4396 Return a new `dtype` with a different byte order. 4397 4398 Changes are also made in all fields and sub-arrays of the data type. 4399 4400 The `new_order` code can be any from the following: 4401 4402 * {'<', 'L'} - little endian 4403 * {'>', 'B'} - big endian 4404 * {'=', 'N'} - native order 4405 * 'S' - swap dtype from current to opposite endian 4406 * {'|', 'I'} - ignore (no change to byte order) 4407 4408 Parameters 4409 ---------- 4410 new_order : str, optional 4411 Byte order to force; a value from the byte order specifications 4412 above. The default value ('S') results in swapping the current 4413 byte order. The code does a case-insensitive check on the first 4414 letter of `new_order` for the alternatives above. For example, 4415 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 4416 4417 4418 Returns 4419 ------- 4420 new_dtype : dtype 4421 New `dtype` object with the given change to the byte order.""" 4422 return dtype() 4423 real = getset_descriptor() 4424 shape = getset_descriptor() 4425 size = getset_descriptor() 4426 strides = getset_descriptor() 4427 def ceil(x, out=None): 4428 """ceil(x[, out]) 4429 4430 Return the ceiling of the input, element-wise. 4431 4432 The ceil of the scalar `x` is the smallest integer `i`, such that 4433 `i >= x`. It is often denoted as :math:`\lceil x \rceil`. 4434 4435 Parameters 4436 ---------- 4437 x : array_like 4438 Input data. 4439 4440 Returns 4441 ------- 4442 y : {ndarray, scalar} 4443 The ceiling of each element in `x`, with `float` dtype. 4444 4445 See Also 4446 -------- 4447 floor, trunc, rint 4448 4449 Examples 4450 -------- 4451 >>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) 4452 >>> np.ceil(a) 4453 array([-1., -1., -0., 1., 2., 2., 2.])""" 4454 return None 4455 class complex128: 4456 T = getset_descriptor() 4457 __array_interface__ = getset_descriptor() 4458 __array_priority__ = getset_descriptor() 4459 __array_struct__ = getset_descriptor() 4460 __doc__ = str() 4461 base = getset_descriptor() 4462 def conj(self, _): 4463 """None""" 4464 return None 4465 data = getset_descriptor() 4466 dtype = getset_descriptor() 4467 flags = getset_descriptor() 4468 flat = getset_descriptor() 4469 imag = getset_descriptor() 4470 itemsize = getset_descriptor() 4471 nbytes = getset_descriptor() 4472 ndim = getset_descriptor() 4473 def newbyteorder(self, new_order): 4474 """newbyteorder(new_order='S') 4475 4476 Return a new `dtype` with a different byte order. 4477 4478 Changes are also made in all fields and sub-arrays of the data type. 4479 4480 The `new_order` code can be any from the following: 4481 4482 * {'<', 'L'} - little endian 4483 * {'>', 'B'} - big endian 4484 * {'=', 'N'} - native order 4485 * 'S' - swap dtype from current to opposite endian 4486 * {'|', 'I'} - ignore (no change to byte order) 4487 4488 Parameters 4489 ---------- 4490 new_order : str, optional 4491 Byte order to force; a value from the byte order specifications 4492 above. The default value ('S') results in swapping the current 4493 byte order. The code does a case-insensitive check on the first 4494 letter of `new_order` for the alternatives above. For example, 4495 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 4496 4497 4498 Returns 4499 ------- 4500 new_dtype : dtype 4501 New `dtype` object with the given change to the byte order.""" 4502 return dtype() 4503 real = getset_descriptor() 4504 shape = getset_descriptor() 4505 size = getset_descriptor() 4506 strides = getset_descriptor() 4507 class character: 4508 T = getset_descriptor() 4509 __array_interface__ = getset_descriptor() 4510 __array_priority__ = getset_descriptor() 4511 __array_struct__ = getset_descriptor() 4512 __doc__ = None 4513 base = getset_descriptor() 4514 def conj(self, _): 4515 """None""" 4516 return None 4517 data = getset_descriptor() 4518 dtype = getset_descriptor() 4519 flags = getset_descriptor() 4520 flat = getset_descriptor() 4521 imag = getset_descriptor() 4522 itemsize = getset_descriptor() 4523 nbytes = getset_descriptor() 4524 ndim = getset_descriptor() 4525 def newbyteorder(self, new_order): 4526 """newbyteorder(new_order='S') 4527 4528 Return a new `dtype` with a different byte order. 4529 4530 Changes are also made in all fields and sub-arrays of the data type. 4531 4532 The `new_order` code can be any from the following: 4533 4534 * {'<', 'L'} - little endian 4535 * {'>', 'B'} - big endian 4536 * {'=', 'N'} - native order 4537 * 'S' - swap dtype from current to opposite endian 4538 * {'|', 'I'} - ignore (no change to byte order) 4539 4540 Parameters 4541 ---------- 4542 new_order : str, optional 4543 Byte order to force; a value from the byte order specifications 4544 above. The default value ('S') results in swapping the current 4545 byte order. The code does a case-insensitive check on the first 4546 letter of `new_order` for the alternatives above. For example, 4547 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 4548 4549 4550 Returns 4551 ------- 4552 new_dtype : dtype 4553 New `dtype` object with the given change to the byte order.""" 4554 return dtype() 4555 real = getset_descriptor() 4556 shape = getset_descriptor() 4557 size = getset_descriptor() 4558 strides = getset_descriptor() 4559 class chararray: 4560 T = getset_descriptor() 4561 __array_interface__ = getset_descriptor() 4562 __array_priority__ = getset_descriptor() 4563 __array_struct__ = getset_descriptor() 4564 __dict__ = dictproxy() 4565 __doc__ = str() 4566 __module__ = str() 4567 def all(self, axis=None, out=None): 4568 """a.all(axis=None, out=None) 4569 4570 Returns True if all elements evaluate to True. 4571 4572 Refer to `numpy.all` for full documentation. 4573 4574 See Also 4575 -------- 4576 numpy.all : equivalent function""" 4577 return None 4578 def any(self, axis=None, out=None): 4579 """a.any(axis=None, out=None) 4580 4581 Returns True if any of the elements of `a` evaluate to True. 4582 4583 Refer to `numpy.any` for full documentation. 4584 4585 See Also 4586 -------- 4587 numpy.any : equivalent function""" 4588 return None 4589 def argmax(self, axis=None, out=None): 4590 """a.argmax(axis=None, out=None) 4591 4592 Return indices of the maximum values along the given axis. 4593 4594 Refer to `numpy.argmax` for full documentation. 4595 4596 See Also 4597 -------- 4598 numpy.argmax : equivalent function""" 4599 return None 4600 def argmin(self, axis=None, out=None): 4601 """a.argmin(axis=None, out=None) 4602 4603 Return indices of the minimum values along the given axis of `a`. 4604 4605 Refer to `numpy.argmin` for detailed documentation. 4606 4607 See Also 4608 -------- 4609 numpy.argmin : equivalent function""" 4610 return None 4611 def argpartition(self, kth, axis=_1, kind=quickselect, order=None): 4612 """a.argpartition(kth, axis=-1, kind='quickselect', order=None) 4613 4614 Returns the indices that would partition this array. 4615 4616 Refer to `numpy.argpartition` for full documentation. 4617 4618 .. versionadded:: 1.8.0 4619 4620 See Also 4621 -------- 4622 numpy.argpartition : equivalent function""" 4623 return None 4624 def argsort(self=None, axis=-1, kind="quicksort", order=None): 4625 """None""" 4626 return None 4627 def astype(self, dtype, order, casting, subok, copy): 4628 """a.astype(dtype, order='K', casting='unsafe', subok=True, copy=True) 4629 4630 Copy of the array, cast to a specified type. 4631 4632 Parameters 4633 ---------- 4634 dtype : str or dtype 4635 Typecode or data-type to which the array is cast. 4636 order : {'C', 'F', 'A', 'K'}, optional 4637 Controls the memory layout order of the result. 4638 'C' means C order, 'F' means Fortran order, 'A' 4639 means 'F' order if all the arrays are Fortran contiguous, 4640 'C' order otherwise, and 'K' means as close to the 4641 order the array elements appear in memory as possible. 4642 Default is 'K'. 4643 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional 4644 Controls what kind of data casting may occur. Defaults to 'unsafe' 4645 for backwards compatibility. 4646 4647 * 'no' means the data types should not be cast at all. 4648 * 'equiv' means only byte-order changes are allowed. 4649 * 'safe' means only casts which can preserve values are allowed. 4650 * 'same_kind' means only safe casts or casts within a kind, 4651 like float64 to float32, are allowed. 4652 * 'unsafe' means any data conversions may be done. 4653 subok : bool, optional 4654 If True, then sub-classes will be passed-through (default), otherwise 4655 the returned array will be forced to be a base-class array. 4656 copy : bool, optional 4657 By default, astype always returns a newly allocated array. If this 4658 is set to false, and the `dtype`, `order`, and `subok` 4659 requirements are satisfied, the input array is returned instead 4660 of a copy. 4661 4662 Returns 4663 ------- 4664 arr_t : ndarray 4665 Unless `copy` is False and the other conditions for returning the input 4666 array are satisfied (see description for `copy` input paramter), `arr_t` 4667 is a new array of the same shape as the input array, with dtype, order 4668 given by `dtype`, `order`. 4669 4670 Raises 4671 ------ 4672 ComplexWarning 4673 When casting from complex to float or int. To avoid this, 4674 one should use ``a.real.astype(t)``. 4675 4676 Examples 4677 -------- 4678 >>> x = np.array([1, 2, 2.5]) 4679 >>> x 4680 array([ 1. , 2. , 2.5]) 4681 4682 >>> x.astype(int) 4683 array([1, 2, 2])""" 4684 return ndarray() 4685 base = getset_descriptor() 4686 def byteswap(self, inplace): 4687 """a.byteswap(inplace) 4688 4689 Swap the bytes of the array elements 4690 4691 Toggle between low-endian and big-endian data representation by 4692 returning a byteswapped array, optionally swapped in-place. 4693 4694 Parameters 4695 ---------- 4696 inplace : bool, optional 4697 If ``True``, swap bytes in-place, default is ``False``. 4698 4699 Returns 4700 ------- 4701 out : ndarray 4702 The byteswapped array. If `inplace` is ``True``, this is 4703 a view to self. 4704 4705 Examples 4706 -------- 4707 >>> A = np.array([1, 256, 8755], dtype=np.int16) 4708 >>> map(hex, A) 4709 ['0x1', '0x100', '0x2233'] 4710 >>> A.byteswap(True) 4711 array([ 256, 1, 13090], dtype=int16) 4712 >>> map(hex, A) 4713 ['0x100', '0x1', '0x3322'] 4714 4715 Arrays of strings are not swapped 4716 4717 >>> A = np.array(['ceg', 'fac']) 4718 >>> A.byteswap() 4719 array(['ceg', 'fac'], 4720 dtype='|S3')""" 4721 return ndarray() 4722 def capitalize(self, _): 4723 """ 4724 Return a copy of `self` with only the first character of each element 4725 capitalized. 4726 4727 See also 4728 -------- 4729 char.capitalize 4730 4731 """ 4732 return None 4733 def center(self, width=" ", fillchar=" "): 4734 """ 4735 Return a copy of `self` with its elements centered in a 4736 string of length `width`. 4737 4738 See also 4739 -------- 4740 center 4741 """ 4742 return None 4743 def choose(self, choices, out=None, mode=_raise): 4744 """a.choose(choices, out=None, mode='raise') 4745 4746 Use an index array to construct a new array from a set of choices. 4747 4748 Refer to `numpy.choose` for full documentation. 4749 4750 See Also 4751 -------- 4752 numpy.choose : equivalent function""" 4753 return None 4754 def clip(self, a_min, a_max, out=None): 4755 """a.clip(a_min, a_max, out=None) 4756 4757 Return an array whose values are limited to ``[a_min, a_max]``. 4758 4759 Refer to `numpy.clip` for full documentation. 4760 4761 See Also 4762 -------- 4763 numpy.clip : equivalent function""" 4764 return None 4765 def compress(self, condition, axis=None, out=None): 4766 """a.compress(condition, axis=None, out=None) 4767 4768 Return selected slices of this array along given axis. 4769 4770 Refer to `numpy.compress` for full documentation. 4771 4772 See Also 4773 -------- 4774 numpy.compress : equivalent function""" 4775 return None 4776 def conj(self, _): 4777 """a.conj() 4778 4779 Complex-conjugate all elements. 4780 4781 Refer to `numpy.conjugate` for full documentation. 4782 4783 See Also 4784 -------- 4785 numpy.conjugate : equivalent function""" 4786 return None 4787 def conjugate(self, _): 4788 """a.conjugate() 4789 4790 Return the complex conjugate, element-wise. 4791 4792 Refer to `numpy.conjugate` for full documentation. 4793 4794 See Also 4795 -------- 4796 numpy.conjugate : equivalent function""" 4797 return None 4798 def copy(self, order): 4799 """a.copy(order='C') 4800 4801 Return a copy of the array. 4802 4803 Parameters 4804 ---------- 4805 order : {'C', 'F', 'A', 'K'}, optional 4806 Controls the memory layout of the copy. 'C' means C-order, 4807 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, 4808 'C' otherwise. 'K' means match the layout of `a` as closely 4809 as possible. (Note that this function and :func:numpy.copy are very 4810 similar, but have different default values for their order= 4811 arguments.) 4812 4813 See also 4814 -------- 4815 numpy.copy 4816 numpy.copyto 4817 4818 Examples 4819 -------- 4820 >>> x = np.array([[1,2,3],[4,5,6]], order='F') 4821 4822 >>> y = x.copy() 4823 4824 >>> x.fill(0) 4825 4826 >>> x 4827 array([[0, 0, 0], 4828 [0, 0, 0]]) 4829 4830 >>> y 4831 array([[1, 2, 3], 4832 [4, 5, 6]]) 4833 4834 >>> y.flags['C_CONTIGUOUS'] 4835 True""" 4836 return None 4837 def count(self, sub=None, start=0, end=None): 4838 """ 4839 Returns an array with the number of non-overlapping occurrences of 4840 substring `sub` in the range [`start`, `end`]. 4841 4842 See also 4843 -------- 4844 char.count 4845 4846 """ 4847 return None 4848 ctypes = getset_descriptor() 4849 def cumprod(self, axis=None, dtype=None, out=None): 4850 """a.cumprod(axis=None, dtype=None, out=None) 4851 4852 Return the cumulative product of the elements along the given axis. 4853 4854 Refer to `numpy.cumprod` for full documentation. 4855 4856 See Also 4857 -------- 4858 numpy.cumprod : equivalent function""" 4859 return None 4860 def cumsum(self, axis=None, dtype=None, out=None): 4861 """a.cumsum(axis=None, dtype=None, out=None) 4862 4863 Return the cumulative sum of the elements along the given axis. 4864 4865 Refer to `numpy.cumsum` for full documentation. 4866 4867 See Also 4868 -------- 4869 numpy.cumsum : equivalent function""" 4870 return None 4871 data = getset_descriptor() 4872 def decode(self=None, encoding=None, errors=None): 4873 """ 4874 Calls `str.decode` element-wise. 4875 4876 See also 4877 -------- 4878 char.decode 4879 4880 """ 4881 return None 4882 def diagonal(self, offset=0, axis1=0, axis2=1): 4883 """a.diagonal(offset=0, axis1=0, axis2=1) 4884 4885 Return specified diagonals. 4886 4887 Refer to :func:`numpy.diagonal` for full documentation. 4888 4889 See Also 4890 -------- 4891 numpy.diagonal : equivalent function""" 4892 return None 4893 def dot(self, b, out=None): 4894 """a.dot(b, out=None) 4895 4896 Dot product of two arrays. 4897 4898 Refer to `numpy.dot` for full documentation. 4899 4900 See Also 4901 -------- 4902 numpy.dot : equivalent function 4903 4904 Examples 4905 -------- 4906 >>> a = np.eye(2) 4907 >>> b = np.ones((2, 2)) * 2 4908 >>> a.dot(b) 4909 array([[ 2., 2.], 4910 [ 2., 2.]]) 4911 4912 This array method can be conveniently chained: 4913 4914 >>> a.dot(b).dot(b) 4915 array([[ 8., 8.], 4916 [ 8., 8.]])""" 4917 return None 4918 dtype = getset_descriptor() 4919 def dump(self, file): 4920 """a.dump(file) 4921 4922 Dump a pickle of the array to the specified file. 4923 The array can be read back with pickle.load or numpy.load. 4924 4925 Parameters 4926 ---------- 4927 file : str 4928 A string naming the dump file.""" 4929 return None 4930 def dumps(self, _): 4931 """a.dumps() 4932 4933 Returns the pickle of the array as a string. 4934 pickle.loads or numpy.loads will convert the string back to an array. 4935 4936 Parameters 4937 ---------- 4938 None""" 4939 return None 4940 def encode(self=None, encoding=None, errors=None): 4941 """ 4942 Calls `str.encode` element-wise. 4943 4944 See also 4945 -------- 4946 char.encode 4947 4948 """ 4949 return None 4950 def endswith(self, suffix=None, start=0, end=None): 4951 """ 4952 Returns a boolean array which is `True` where the string element 4953 in `self` ends with `suffix`, otherwise `False`. 4954 4955 See also 4956 -------- 4957 char.endswith 4958 4959 """ 4960 return None 4961 def expandtabs(self=8, tabsize=8): 4962 """ 4963 Return a copy of each string element where all tab characters are 4964 replaced by one or more spaces. 4965 4966 See also 4967 -------- 4968 char.expandtabs 4969 4970 """ 4971 return None 4972 def fill(self, value): 4973 """a.fill(value) 4974 4975 Fill the array with a scalar value. 4976 4977 Parameters 4978 ---------- 4979 value : scalar 4980 All elements of `a` will be assigned this value. 4981 4982 Examples 4983 -------- 4984 >>> a = np.array([1, 2]) 4985 >>> a.fill(0) 4986 >>> a 4987 array([0, 0]) 4988 >>> a = np.empty(2) 4989 >>> a.fill(1) 4990 >>> a 4991 array([ 1., 1.])""" 4992 return None 4993 def find(self, sub=None, start=0, end=None): 4994 """ 4995 For each element, return the lowest index in the string where 4996 substring `sub` is found. 4997 4998 See also 4999 -------- 5000 char.find 5001 5002 """ 5003 return None 5004 flags = getset_descriptor() 5005 flat = getset_descriptor() 5006 def flatten(self, order): 5007 """a.flatten(order='C') 5008 5009 Return a copy of the array collapsed into one dimension. 5010 5011 Parameters 5012 ---------- 5013 order : {'C', 'F', 'A'}, optional 5014 Whether to flatten in C (row-major), Fortran (column-major) order, 5015 or preserve the C/Fortran ordering from `a`. 5016 The default is 'C'. 5017 5018 Returns 5019 ------- 5020 y : ndarray 5021 A copy of the input array, flattened to one dimension. 5022 5023 See Also 5024 -------- 5025 ravel : Return a flattened array. 5026 flat : A 1-D flat iterator over the array. 5027 5028 Examples 5029 -------- 5030 >>> a = np.array([[1,2], [3,4]]) 5031 >>> a.flatten() 5032 array([1, 2, 3, 4]) 5033 >>> a.flatten('F') 5034 array([1, 3, 2, 4])""" 5035 return ndarray() 5036 def getfield(self, dtype, offset): 5037 """a.getfield(dtype, offset=0) 5038 5039 Returns a field of the given array as a certain type. 5040 5041 A field is a view of the array data with a given data-type. The values in 5042 the view are determined by the given type and the offset into the current 5043 array in bytes. The offset needs to be such that the view dtype fits in the 5044 array dtype; for example an array of dtype complex128 has 16-byte elements. 5045 If taking a view with a 32-bit integer (4 bytes), the offset needs to be 5046 between 0 and 12 bytes. 5047 5048 Parameters 5049 ---------- 5050 dtype : str or dtype 5051 The data type of the view. The dtype size of the view can not be larger 5052 than that of the array itself. 5053 offset : int 5054 Number of bytes to skip before beginning the element view. 5055 5056 Examples 5057 -------- 5058 >>> x = np.diag([1.+1.j]*2) 5059 >>> x[1, 1] = 2 + 4.j 5060 >>> x 5061 array([[ 1.+1.j, 0.+0.j], 5062 [ 0.+0.j, 2.+4.j]]) 5063 >>> x.getfield(np.float64) 5064 array([[ 1., 0.], 5065 [ 0., 2.]]) 5066 5067 By choosing an offset of 8 bytes we can select the complex part of the 5068 array for our view: 5069 5070 >>> x.getfield(np.float64, offset=8) 5071 array([[ 1., 0.], 5072 [ 0., 4.]])""" 5073 return array() 5074 imag = getset_descriptor() 5075 def index(self, sub=None, start=0, end=None): 5076 """ 5077 Like `find`, but raises `ValueError` when the substring is not found. 5078 5079 See also 5080 -------- 5081 char.index 5082 5083 """ 5084 return None 5085 def isalnum(self, _): 5086 """ 5087 Returns true for each element if all characters in the string 5088 are alphanumeric and there is at least one character, false 5089 otherwise. 5090 5091 See also 5092 -------- 5093 char.isalnum 5094 5095 """ 5096 return None 5097 def isalpha(self, _): 5098 """ 5099 Returns true for each element if all characters in the string 5100 are alphabetic and there is at least one character, false 5101 otherwise. 5102 5103 See also 5104 -------- 5105 char.isalpha 5106 5107 """ 5108 return None 5109 def isdecimal(self, _): 5110 """ 5111 For each element in `self`, return True if there are only 5112 decimal characters in the element. 5113 5114 See also 5115 -------- 5116 char.isdecimal 5117 5118 """ 5119 return None 5120 def isdigit(self, _): 5121 """ 5122 Returns true for each element if all characters in the string are 5123 digits and there is at least one character, false otherwise. 5124 5125 See also 5126 -------- 5127 char.isdigit 5128 5129 """ 5130 return None 5131 def islower(self, _): 5132 """ 5133 Returns true for each element if all cased characters in the 5134 string are lowercase and there is at least one cased character, 5135 false otherwise. 5136 5137 See also 5138 -------- 5139 char.islower 5140 5141 """ 5142 return None 5143 def isnumeric(self, _): 5144 """ 5145 For each element in `self`, return True if there are only 5146 numeric characters in the element. 5147 5148 See also 5149 -------- 5150 char.isnumeric 5151 5152 """ 5153 return None 5154 def isspace(self, _): 5155 """ 5156 Returns true for each element if there are only whitespace 5157 characters in the string and there is at least one character, 5158 false otherwise. 5159 5160 See also 5161 -------- 5162 char.isspace 5163 5164 """ 5165 return None 5166 def istitle(self, _): 5167 """ 5168 Returns true for each element if the element is a titlecased 5169 string and there is at least one character, false otherwise. 5170 5171 See also 5172 -------- 5173 char.istitle 5174 5175 """ 5176 return None 5177 def isupper(self, _): 5178 """ 5179 Returns true for each element if all cased characters in the 5180 string are uppercase and there is at least one character, false 5181 otherwise. 5182 5183 See also 5184 -------- 5185 char.isupper 5186 5187 """ 5188 return None 5189 def item(self, ESCargs): 5190 """a.item(*args) 5191 5192 Copy an element of an array to a standard Python scalar and return it. 5193 5194 Parameters 5195 ---------- 5196 \*args : Arguments (variable number and type) 5197 5198 * none: in this case, the method only works for arrays 5199 with one element (`a.size == 1`), which element is 5200 copied into a standard Python scalar object and returned. 5201 5202 * int_type: this argument is interpreted as a flat index into 5203 the array, specifying which element to copy and return. 5204 5205 * tuple of int_types: functions as does a single int_type argument, 5206 except that the argument is interpreted as an nd-index into the 5207 array. 5208 5209 Returns 5210 ------- 5211 z : Standard Python scalar object 5212 A copy of the specified element of the array as a suitable 5213 Python scalar 5214 5215 Notes 5216 ----- 5217 When the data type of `a` is longdouble or clongdouble, item() returns 5218 a scalar array object because there is no available Python scalar that 5219 would not lose information. Void arrays return a buffer object for item(), 5220 unless fields are defined, in which case a tuple is returned. 5221 5222 `item` is very similar to a[args], except, instead of an array scalar, 5223 a standard Python scalar is returned. This can be useful for speeding up 5224 access to elements of the array and doing arithmetic on elements of the 5225 array using Python's optimized math. 5226 5227 Examples 5228 -------- 5229 >>> x = np.random.randint(9, size=(3, 3)) 5230 >>> x 5231 array([[3, 1, 7], 5232 [2, 8, 3], 5233 [8, 5, 3]]) 5234 >>> x.item(3) 5235 2 5236 >>> x.item(7) 5237 5 5238 >>> x.item((0, 1)) 5239 1 5240 >>> x.item((2, 2)) 5241 3""" 5242 return Standard() 5243 def itemset(self, ESCargs): 5244 """a.itemset(*args) 5245 5246 Insert scalar into an array (scalar is cast to array's dtype, if possible) 5247 5248 There must be at least 1 argument, and define the last argument 5249 as *item*. Then, ``a.itemset(*args)`` is equivalent to but faster 5250 than ``a[args] = item``. The item should be a scalar value and `args` 5251 must select a single item in the array `a`. 5252 5253 Parameters 5254 ---------- 5255 \*args : Arguments 5256 If one argument: a scalar, only used in case `a` is of size 1. 5257 If two arguments: the last argument is the value to be set 5258 and must be a scalar, the first argument specifies a single array 5259 element location. It is either an int or a tuple. 5260 5261 Notes 5262 ----- 5263 Compared to indexing syntax, `itemset` provides some speed increase 5264 for placing a scalar into a particular location in an `ndarray`, 5265 if you must do this. However, generally this is discouraged: 5266 among other problems, it complicates the appearance of the code. 5267 Also, when using `itemset` (and `item`) inside a loop, be sure 5268 to assign the methods to a local variable to avoid the attribute 5269 look-up at each loop iteration. 5270 5271 Examples 5272 -------- 5273 >>> x = np.random.randint(9, size=(3, 3)) 5274 >>> x 5275 array([[3, 1, 7], 5276 [2, 8, 3], 5277 [8, 5, 3]]) 5278 >>> x.itemset(4, 0) 5279 >>> x.itemset((2, 2), 9) 5280 >>> x 5281 array([[3, 1, 7], 5282 [2, 0, 3], 5283 [8, 5, 9]])""" 5284 return None 5285 itemsize = getset_descriptor() 5286 def join(self, _): 5287 """ 5288 Return a string which is the concatenation of the strings in the 5289 sequence `seq`. 5290 5291 See also 5292 -------- 5293 char.join 5294 5295 """ 5296 return None 5297 def ljust(self, width=" ", fillchar=" "): 5298 """ 5299 Return an array with the elements of `self` left-justified in a 5300 string of length `width`. 5301 5302 See also 5303 -------- 5304 char.ljust 5305 5306 """ 5307 return None 5308 def lower(self, _): 5309 """ 5310 Return an array with the elements of `self` converted to 5311 lowercase. 5312 5313 See also 5314 -------- 5315 char.lower 5316 5317 """ 5318 return None 5319 def lstrip(self=None, chars=None): 5320 """ 5321 For each element in `self`, return a copy with the leading characters 5322 removed. 5323 5324 See also 5325 -------- 5326 char.lstrip 5327 5328 """ 5329 return None 5330 def max(self, axis=None, out=None): 5331 """a.max(axis=None, out=None) 5332 5333 Return the maximum along a given axis. 5334 5335 Refer to `numpy.amax` for full documentation. 5336 5337 See Also 5338 -------- 5339 numpy.amax : equivalent function""" 5340 return None 5341 def mean(self, axis=None, dtype=None, out=None): 5342 """a.mean(axis=None, dtype=None, out=None) 5343 5344 Returns the average of the array elements along given axis. 5345 5346 Refer to `numpy.mean` for full documentation. 5347 5348 See Also 5349 -------- 5350 numpy.mean : equivalent function""" 5351 return None 5352 def min(self, axis=None, out=None): 5353 """a.min(axis=None, out=None) 5354 5355 Return the minimum along a given axis. 5356 5357 Refer to `numpy.amin` for full documentation. 5358 5359 See Also 5360 -------- 5361 numpy.amin : equivalent function""" 5362 return None 5363 nbytes = getset_descriptor() 5364 ndim = getset_descriptor() 5365 def newbyteorder(self, new_order): 5366 """arr.newbyteorder(new_order='S') 5367 5368 Return the array with the same data viewed with a different byte order. 5369 5370 Equivalent to:: 5371 5372 arr.view(arr.dtype.newbytorder(new_order)) 5373 5374 Changes are also made in all fields and sub-arrays of the array data 5375 type. 5376 5377 5378 5379 Parameters 5380 ---------- 5381 new_order : string, optional 5382 Byte order to force; a value from the byte order specifications 5383 above. `new_order` codes can be any of:: 5384 5385 * 'S' - swap dtype from current to opposite endian 5386 * {'<', 'L'} - little endian 5387 * {'>', 'B'} - big endian 5388 * {'=', 'N'} - native order 5389 * {'|', 'I'} - ignore (no change to byte order) 5390 5391 The default value ('S') results in swapping the current 5392 byte order. The code does a case-insensitive check on the first 5393 letter of `new_order` for the alternatives above. For example, 5394 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 5395 5396 5397 Returns 5398 ------- 5399 new_arr : array 5400 New array object with the dtype reflecting given change to the 5401 byte order.""" 5402 return array() 5403 def nonzero(self, _): 5404 """a.nonzero() 5405 5406 Return the indices of the elements that are non-zero. 5407 5408 Refer to `numpy.nonzero` for full documentation. 5409 5410 See Also 5411 -------- 5412 numpy.nonzero : equivalent function""" 5413 return None 5414 def partition(self, _): 5415 """ 5416 Partition each element in `self` around `sep`. 5417 5418 See also 5419 -------- 5420 partition 5421 """ 5422 return None 5423 def prod(self, axis=None, dtype=None, out=None): 5424 """a.prod(axis=None, dtype=None, out=None) 5425 5426 Return the product of the array elements over the given axis 5427 5428 Refer to `numpy.prod` for full documentation. 5429 5430 See Also 5431 -------- 5432 numpy.prod : equivalent function""" 5433 return None 5434 def ptp(self, axis=None, out=None): 5435 """a.ptp(axis=None, out=None) 5436 5437 Peak to peak (maximum - minimum) value along a given axis. 5438 5439 Refer to `numpy.ptp` for full documentation. 5440 5441 See Also 5442 -------- 5443 numpy.ptp : equivalent function""" 5444 return None 5445 def put(self, indices, values, mode=_raise): 5446 """a.put(indices, values, mode='raise') 5447 5448 Set ``a.flat[n] = values[n]`` for all `n` in indices. 5449 5450 Refer to `numpy.put` for full documentation. 5451 5452 See Also 5453 -------- 5454 numpy.put : equivalent function""" 5455 return None 5456 def ravel(self, order): 5457 """a.ravel([order]) 5458 5459 Return a flattened array. 5460 5461 Refer to `numpy.ravel` for full documentation. 5462 5463 See Also 5464 -------- 5465 numpy.ravel : equivalent function 5466 5467 ndarray.flat : a flat iterator on the array.""" 5468 return None 5469 real = getset_descriptor() 5470 def repeat(self, repeats, axis=None): 5471 """a.repeat(repeats, axis=None) 5472 5473 Repeat elements of an array. 5474 5475 Refer to `numpy.repeat` for full documentation. 5476 5477 See Also 5478 -------- 5479 numpy.repeat : equivalent function""" 5480 return None 5481 def replace(self, old, new=None, count=None): 5482 """ 5483 For each element in `self`, return a copy of the string with all 5484 occurrences of substring `old` replaced by `new`. 5485 5486 See also 5487 -------- 5488 char.replace 5489 5490 """ 5491 return None 5492 def reshape(self, shape, order=C): 5493 """a.reshape(shape, order='C') 5494 5495 Returns an array containing the same data with a new shape. 5496 5497 Refer to `numpy.reshape` for full documentation. 5498 5499 See Also 5500 -------- 5501 numpy.reshape : equivalent function""" 5502 return None 5503 def resize(self, new_shape, refcheck): 5504 """a.resize(new_shape, refcheck=True) 5505 5506 Change shape and size of array in-place. 5507 5508 Parameters 5509 ---------- 5510 new_shape : tuple of ints, or `n` ints 5511 Shape of resized array. 5512 refcheck : bool, optional 5513 If False, reference count will not be checked. Default is True. 5514 5515 Returns 5516 ------- 5517 None 5518 5519 Raises 5520 ------ 5521 ValueError 5522 If `a` does not own its own data or references or views to it exist, 5523 and the data memory must be changed. 5524 5525 SystemError 5526 If the `order` keyword argument is specified. This behaviour is a 5527 bug in NumPy. 5528 5529 See Also 5530 -------- 5531 resize : Return a new array with the specified shape. 5532 5533 Notes 5534 ----- 5535 This reallocates space for the data area if necessary. 5536 5537 Only contiguous arrays (data elements consecutive in memory) can be 5538 resized. 5539 5540 The purpose of the reference count check is to make sure you 5541 do not use this array as a buffer for another Python object and then 5542 reallocate the memory. However, reference counts can increase in 5543 other ways so if you are sure that you have not shared the memory 5544 for this array with another Python object, then you may safely set 5545 `refcheck` to False. 5546 5547 Examples 5548 -------- 5549 Shrinking an array: array is flattened (in the order that the data are 5550 stored in memory), resized, and reshaped: 5551 5552 >>> a = np.array([[0, 1], [2, 3]], order='C') 5553 >>> a.resize((2, 1)) 5554 >>> a 5555 array([[0], 5556 [1]]) 5557 5558 >>> a = np.array([[0, 1], [2, 3]], order='F') 5559 >>> a.resize((2, 1)) 5560 >>> a 5561 array([[0], 5562 [2]]) 5563 5564 Enlarging an array: as above, but missing entries are filled with zeros: 5565 5566 >>> b = np.array([[0, 1], [2, 3]]) 5567 >>> b.resize(2, 3) # new_shape parameter doesn't have to be a tuple 5568 >>> b 5569 array([[0, 1, 2], 5570 [3, 0, 0]]) 5571 5572 Referencing an array prevents resizing... 5573 5574 >>> c = a 5575 >>> a.resize((1, 1)) 5576 Traceback (most recent call last): 5577 ... 5578 ValueError: cannot resize an array that has been referenced ... 5579 5580 Unless `refcheck` is False: 5581 5582 >>> a.resize((1, 1), refcheck=False) 5583 >>> a 5584 array([[0]]) 5585 >>> c 5586 array([[0]])""" 5587 return None 5588 def rfind(self, sub=None, start=0, end=None): 5589 """ 5590 For each element in `self`, return the highest index in the string 5591 where substring `sub` is found, such that `sub` is contained 5592 within [`start`, `end`]. 5593 5594 See also 5595 -------- 5596 char.rfind 5597 5598 """ 5599 return None 5600 def rindex(self, sub=None, start=0, end=None): 5601 """ 5602 Like `rfind`, but raises `ValueError` when the substring `sub` is 5603 not found. 5604 5605 See also 5606 -------- 5607 char.rindex 5608 5609 """ 5610 return None 5611 def rjust(self, width=" ", fillchar=" "): 5612 """ 5613 Return an array with the elements of `self` 5614 right-justified in a string of length `width`. 5615 5616 See also 5617 -------- 5618 char.rjust 5619 5620 """ 5621 return None 5622 def round(self, decimals=0, out=None): 5623 """a.round(decimals=0, out=None) 5624 5625 Return `a` with each element rounded to the given number of decimals. 5626 5627 Refer to `numpy.around` for full documentation. 5628 5629 See Also 5630 -------- 5631 numpy.around : equivalent function""" 5632 return None 5633 def rpartition(self, _): 5634 """ 5635 Partition each element in `self` around `sep`. 5636 5637 See also 5638 -------- 5639 rpartition 5640 """ 5641 return None 5642 def rsplit(self=None, sep=None, maxsplit=None): 5643 """ 5644 For each element in `self`, return a list of the words in 5645 the string, using `sep` as the delimiter string. 5646 5647 See also 5648 -------- 5649 char.rsplit 5650 5651 """ 5652 return None 5653 def rstrip(self=None, chars=None): 5654 """ 5655 For each element in `self`, return a copy with the trailing 5656 characters removed. 5657 5658 See also 5659 -------- 5660 char.rstrip 5661 5662 """ 5663 return None 5664 def searchsorted(self, v, side=left, sorter=None): 5665 """a.searchsorted(v, side='left', sorter=None) 5666 5667 Find indices where elements of v should be inserted in a to maintain order. 5668 5669 For full documentation, see `numpy.searchsorted` 5670 5671 See Also 5672 -------- 5673 numpy.searchsorted : equivalent function""" 5674 return None 5675 def setfield(self, val, dtype, offset): 5676 """a.setfield(val, dtype, offset=0) 5677 5678 Put a value into a specified place in a field defined by a data-type. 5679 5680 Place `val` into `a`'s field defined by `dtype` and beginning `offset` 5681 bytes into the field. 5682 5683 Parameters 5684 ---------- 5685 val : object 5686 Value to be placed in field. 5687 dtype : dtype object 5688 Data-type of the field in which to place `val`. 5689 offset : int, optional 5690 The number of bytes into the field at which to place `val`. 5691 5692 Returns 5693 ------- 5694 None 5695 5696 See Also 5697 -------- 5698 getfield 5699 5700 Examples 5701 -------- 5702 >>> x = np.eye(3) 5703 >>> x.getfield(np.float64) 5704 array([[ 1., 0., 0.], 5705 [ 0., 1., 0.], 5706 [ 0., 0., 1.]]) 5707 >>> x.setfield(3, np.int32) 5708 >>> x.getfield(np.int32) 5709 array([[3, 3, 3], 5710 [3, 3, 3], 5711 [3, 3, 3]]) 5712 >>> x 5713 array([[ 1.00000000e+000, 1.48219694e-323, 1.48219694e-323], 5714 [ 1.48219694e-323, 1.00000000e+000, 1.48219694e-323], 5715 [ 1.48219694e-323, 1.48219694e-323, 1.00000000e+000]]) 5716 >>> x.setfield(np.eye(3), np.int32) 5717 >>> x 5718 array([[ 1., 0., 0.], 5719 [ 0., 1., 0.], 5720 [ 0., 0., 1.]])""" 5721 return None 5722 def setflags(self, write, align, uic): 5723 """a.setflags(write=None, align=None, uic=None) 5724 5725 Set array flags WRITEABLE, ALIGNED, and UPDATEIFCOPY, respectively. 5726 5727 These Boolean-valued flags affect how numpy interprets the memory 5728 area used by `a` (see Notes below). The ALIGNED flag can only 5729 be set to True if the data is actually aligned according to the type. 5730 The UPDATEIFCOPY flag can never be set to True. The flag WRITEABLE 5731 can only be set to True if the array owns its own memory, or the 5732 ultimate owner of the memory exposes a writeable buffer interface, 5733 or is a string. (The exception for string is made so that unpickling 5734 can be done without copying memory.) 5735 5736 Parameters 5737 ---------- 5738 write : bool, optional 5739 Describes whether or not `a` can be written to. 5740 align : bool, optional 5741 Describes whether or not `a` is aligned properly for its type. 5742 uic : bool, optional 5743 Describes whether or not `a` is a copy of another "base" array. 5744 5745 Notes 5746 ----- 5747 Array flags provide information about how the memory area used 5748 for the array is to be interpreted. There are 6 Boolean flags 5749 in use, only three of which can be changed by the user: 5750 UPDATEIFCOPY, WRITEABLE, and ALIGNED. 5751 5752 WRITEABLE (W) the data area can be written to; 5753 5754 ALIGNED (A) the data and strides are aligned appropriately for the hardware 5755 (as determined by the compiler); 5756 5757 UPDATEIFCOPY (U) this array is a copy of some other array (referenced 5758 by .base). When this array is deallocated, the base array will be 5759 updated with the contents of this array. 5760 5761 All flags can be accessed using their first (upper case) letter as well 5762 as the full name. 5763 5764 Examples 5765 -------- 5766 >>> y 5767 array([[3, 1, 7], 5768 [2, 0, 0], 5769 [8, 5, 9]]) 5770 >>> y.flags 5771 C_CONTIGUOUS : True 5772 F_CONTIGUOUS : False 5773 OWNDATA : True 5774 WRITEABLE : True 5775 ALIGNED : True 5776 UPDATEIFCOPY : False 5777 >>> y.setflags(write=0, align=0) 5778 >>> y.flags 5779 C_CONTIGUOUS : True 5780 F_CONTIGUOUS : False 5781 OWNDATA : True 5782 WRITEABLE : False 5783 ALIGNED : False 5784 UPDATEIFCOPY : False 5785 >>> y.setflags(uic=1) 5786 Traceback (most recent call last): 5787 File "<stdin>", line 1, in <module> 5788 ValueError: cannot set UPDATEIFCOPY flag to True""" 5789 return None 5790 shape = getset_descriptor() 5791 size = getset_descriptor() 5792 def sort(self, axis, kind, order): 5793 """a.sort(axis=-1, kind='quicksort', order=None) 5794 5795 Sort an array, in-place. 5796 5797 Parameters 5798 ---------- 5799 axis : int, optional 5800 Axis along which to sort. Default is -1, which means sort along the 5801 last axis. 5802 kind : {'quicksort', 'mergesort', 'heapsort'}, optional 5803 Sorting algorithm. Default is 'quicksort'. 5804 order : list, optional 5805 When `a` is an array with fields defined, this argument specifies 5806 which fields to compare first, second, etc. Not all fields need be 5807 specified. 5808 5809 See Also 5810 -------- 5811 numpy.sort : Return a sorted copy of an array. 5812 argsort : Indirect sort. 5813 lexsort : Indirect stable sort on multiple keys. 5814 searchsorted : Find elements in sorted array. 5815 partition: Partial sort. 5816 5817 Notes 5818 ----- 5819 See ``sort`` for notes on the different sorting algorithms. 5820 5821 Examples 5822 -------- 5823 >>> a = np.array([[1,4], [3,1]]) 5824 >>> a.sort(axis=1) 5825 >>> a 5826 array([[1, 4], 5827 [1, 3]]) 5828 >>> a.sort(axis=0) 5829 >>> a 5830 array([[1, 3], 5831 [1, 4]]) 5832 5833 Use the `order` keyword to specify a field to use when sorting a 5834 structured array: 5835 5836 >>> a = np.array([('a', 2), ('c', 1)], dtype=[('x', 'S1'), ('y', int)]) 5837 >>> a.sort(order='y') 5838 >>> a 5839 array([('c', 1), ('a', 2)], 5840 dtype=[('x', '|S1'), ('y', '<i4')])""" 5841 return None 5842 def split(self=None, sep=None, maxsplit=None): 5843 """ 5844 For each element in `self`, return a list of the words in the 5845 string, using `sep` as the delimiter string. 5846 5847 See also 5848 -------- 5849 char.split 5850 5851 """ 5852 return None 5853 def splitlines(self=None, keepends=None): 5854 """ 5855 For each element in `self`, return a list of the lines in the 5856 element, breaking at line boundaries. 5857 5858 See also 5859 -------- 5860 char.splitlines 5861 5862 """ 5863 return None 5864 def squeeze(self, axis=None): 5865 """a.squeeze(axis=None) 5866 5867 Remove single-dimensional entries from the shape of `a`. 5868 5869 Refer to `numpy.squeeze` for full documentation. 5870 5871 See Also 5872 -------- 5873 numpy.squeeze : equivalent function""" 5874 return None 5875 def startswith(self, prefix=None, start=0, end=None): 5876 """ 5877 Returns a boolean array which is `True` where the string element 5878 in `self` starts with `prefix`, otherwise `False`. 5879 5880 See also 5881 -------- 5882 char.startswith 5883 5884 """ 5885 return None 5886 def std(self, axis=None, dtype=None, out=None, ddof=0): 5887 """a.std(axis=None, dtype=None, out=None, ddof=0) 5888 5889 Returns the standard deviation of the array elements along given axis. 5890 5891 Refer to `numpy.std` for full documentation. 5892 5893 See Also 5894 -------- 5895 numpy.std : equivalent function""" 5896 return None 5897 strides = getset_descriptor() 5898 def strip(self=None, chars=None): 5899 """ 5900 For each element in `self`, return a copy with the leading and 5901 trailing characters removed. 5902 5903 See also 5904 -------- 5905 char.strip 5906 5907 """ 5908 return None 5909 def sum(self, axis=None, dtype=None, out=None): 5910 """a.sum(axis=None, dtype=None, out=None) 5911 5912 Return the sum of the array elements over the given axis. 5913 5914 Refer to `numpy.sum` for full documentation. 5915 5916 See Also 5917 -------- 5918 numpy.sum : equivalent function""" 5919 return None 5920 def swapaxes(self, axis1, axis2): 5921 """a.swapaxes(axis1, axis2) 5922 5923 Return a view of the array with `axis1` and `axis2` interchanged. 5924 5925 Refer to `numpy.swapaxes` for full documentation. 5926 5927 See Also 5928 -------- 5929 numpy.swapaxes : equivalent function""" 5930 return None 5931 def swapcase(self, _): 5932 """ 5933 For each element in `self`, return a copy of the string with 5934 uppercase characters converted to lowercase and vice versa. 5935 5936 See also 5937 -------- 5938 char.swapcase 5939 5940 """ 5941 return None 5942 def take(self, indices, axis=None, out=None, mode=_raise): 5943 """a.take(indices, axis=None, out=None, mode='raise') 5944 5945 Return an array formed from the elements of `a` at the given indices. 5946 5947 Refer to `numpy.take` for full documentation. 5948 5949 See Also 5950 -------- 5951 numpy.take : equivalent function""" 5952 return None 5953 def title(self, _): 5954 """ 5955 For each element in `self`, return a titlecased version of the 5956 string: words start with uppercase characters, all remaining cased 5957 characters are lowercase. 5958 5959 See also 5960 -------- 5961 char.title 5962 5963 """ 5964 return None 5965 def tofile(self, fid, sep, format): 5966 """a.tofile(fid, sep="", format="%s") 5967 5968 Write array to a file as text or binary (default). 5969 5970 Data is always written in 'C' order, independent of the order of `a`. 5971 The data produced by this method can be recovered using the function 5972 fromfile(). 5973 5974 Parameters 5975 ---------- 5976 fid : file or str 5977 An open file object, or a string containing a filename. 5978 sep : str 5979 Separator between array items for text output. 5980 If "" (empty), a binary file is written, equivalent to 5981 ``file.write(a.tostring())``. 5982 format : str 5983 Format string for text file output. 5984 Each entry in the array is formatted to text by first converting 5985 it to the closest Python type, and then using "format" % item. 5986 5987 Notes 5988 ----- 5989 This is a convenience function for quick storage of array data. 5990 Information on endianness and precision is lost, so this method is not a 5991 good choice for files intended to archive data or transport data between 5992 machines with different endianness. Some of these problems can be overcome 5993 by outputting the data as text files, at the expense of speed and file 5994 size.""" 5995 return None 5996 def tolist(self, _): 5997 """a.tolist() 5998 5999 Return the array as a (possibly nested) list. 6000 6001 Return a copy of the array data as a (nested) Python list. 6002 Data items are converted to the nearest compatible Python type. 6003 6004 Parameters 6005 ---------- 6006 none 6007 6008 Returns 6009 ------- 6010 y : list 6011 The possibly nested list of array elements. 6012 6013 Notes 6014 ----- 6015 The array may be recreated, ``a = np.array(a.tolist())``. 6016 6017 Examples 6018 -------- 6019 >>> a = np.array([1, 2]) 6020 >>> a.tolist() 6021 [1, 2] 6022 >>> a = np.array([[1, 2], [3, 4]]) 6023 >>> list(a) 6024 [array([1, 2]), array([3, 4])] 6025 >>> a.tolist() 6026 [[1, 2], [3, 4]]""" 6027 return list() 6028 def tostring(self, order): 6029 """a.tostring(order='C') 6030 6031 Construct a Python string containing the raw data bytes in the array. 6032 6033 Constructs a Python string showing a copy of the raw contents of 6034 data memory. The string can be produced in either 'C' or 'Fortran', 6035 or 'Any' order (the default is 'C'-order). 'Any' order means C-order 6036 unless the F_CONTIGUOUS flag in the array is set, in which case it 6037 means 'Fortran' order. 6038 6039 Parameters 6040 ---------- 6041 order : {'C', 'F', None}, optional 6042 Order of the data for multidimensional arrays: 6043 C, Fortran, or the same as for the original array. 6044 6045 Returns 6046 ------- 6047 s : str 6048 A Python string exhibiting a copy of `a`'s raw data. 6049 6050 Examples 6051 -------- 6052 >>> x = np.array([[0, 1], [2, 3]]) 6053 >>> x.tostring() 6054 '\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00' 6055 >>> x.tostring('C') == x.tostring() 6056 True 6057 >>> x.tostring('F') 6058 '\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00'""" 6059 return str() 6060 def trace(self, offset=0, axis1=0, axis2=1, dtype=None, out=None): 6061 """a.trace(offset=0, axis1=0, axis2=1, dtype=None, out=None) 6062 6063 Return the sum along diagonals of the array. 6064 6065 Refer to `numpy.trace` for full documentation. 6066 6067 See Also 6068 -------- 6069 numpy.trace : equivalent function""" 6070 return None 6071 def translate(self, table=None, deletechars=None): 6072 """ 6073 For each element in `self`, return a copy of the string where 6074 all characters occurring in the optional argument 6075 `deletechars` are removed, and the remaining characters have 6076 been mapped through the given translation table. 6077 6078 See also 6079 -------- 6080 char.translate 6081 6082 """ 6083 return None 6084 def transpose(self, axes): 6085 """a.transpose(*axes) 6086 6087 Returns a view of the array with axes transposed. 6088 6089 For a 1-D array, this has no effect. (To change between column and 6090 row vectors, first cast the 1-D array into a matrix object.) 6091 For a 2-D array, this is the usual matrix transpose. 6092 For an n-D array, if axes are given, their order indicates how the 6093 axes are permuted (see Examples). If axes are not provided and 6094 ``a.shape = (i[0], i[1], ... i[n-2], i[n-1])``, then 6095 ``a.transpose().shape = (i[n-1], i[n-2], ... i[1], i[0])``. 6096 6097 Parameters 6098 ---------- 6099 axes : None, tuple of ints, or `n` ints 6100 6101 * None or no argument: reverses the order of the axes. 6102 6103 * tuple of ints: `i` in the `j`-th place in the tuple means `a`'s 6104 `i`-th axis becomes `a.transpose()`'s `j`-th axis. 6105 6106 * `n` ints: same as an n-tuple of the same ints (this form is 6107 intended simply as a "convenience" alternative to the tuple form) 6108 6109 Returns 6110 ------- 6111 out : ndarray 6112 View of `a`, with axes suitably permuted. 6113 6114 See Also 6115 -------- 6116 ndarray.T : Array property returning the array transposed. 6117 6118 Examples 6119 -------- 6120 >>> a = np.array([[1, 2], [3, 4]]) 6121 >>> a 6122 array([[1, 2], 6123 [3, 4]]) 6124 >>> a.transpose() 6125 array([[1, 3], 6126 [2, 4]]) 6127 >>> a.transpose((1, 0)) 6128 array([[1, 3], 6129 [2, 4]]) 6130 >>> a.transpose(1, 0) 6131 array([[1, 3], 6132 [2, 4]])""" 6133 return ndarray() 6134 def upper(self, _): 6135 """ 6136 Return an array with the elements of `self` converted to 6137 uppercase. 6138 6139 See also 6140 -------- 6141 char.upper 6142 6143 """ 6144 return None 6145 def var(self, axis=None, dtype=None, out=None, ddof=0): 6146 """a.var(axis=None, dtype=None, out=None, ddof=0) 6147 6148 Returns the variance of the array elements, along given axis. 6149 6150 Refer to `numpy.var` for full documentation. 6151 6152 See Also 6153 -------- 6154 numpy.var : equivalent function""" 6155 return None 6156 def view(self, dtype, type): 6157 """a.view(dtype=None, type=None) 6158 6159 New view of array with the same data. 6160 6161 Parameters 6162 ---------- 6163 dtype : data-type or ndarray sub-class, optional 6164 Data-type descriptor of the returned view, e.g., float32 or int16. The 6165 default, None, results in the view having the same data-type as `a`. 6166 This argument can also be specified as an ndarray sub-class, which 6167 then specifies the type of the returned object (this is equivalent to 6168 setting the ``type`` parameter). 6169 type : Python type, optional 6170 Type of the returned view, e.g., ndarray or matrix. Again, the 6171 default None results in type preservation. 6172 6173 Notes 6174 ----- 6175 ``a.view()`` is used two different ways: 6176 6177 ``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view 6178 of the array's memory with a different data-type. This can cause a 6179 reinterpretation of the bytes of memory. 6180 6181 ``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just 6182 returns an instance of `ndarray_subclass` that looks at the same array 6183 (same shape, dtype, etc.) This does not cause a reinterpretation of the 6184 memory. 6185 6186 For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of 6187 bytes per entry than the previous dtype (for example, converting a 6188 regular array to a structured array), then the behavior of the view 6189 cannot be predicted just from the superficial appearance of ``a`` (shown 6190 by ``print(a)``). It also depends on exactly how ``a`` is stored in 6191 memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus 6192 defined as a slice or transpose, etc., the view may give different 6193 results. 6194 6195 6196 Examples 6197 -------- 6198 >>> x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)]) 6199 6200 Viewing array data using a different type and dtype: 6201 6202 >>> y = x.view(dtype=np.int16, type=np.matrix) 6203 >>> y 6204 matrix([[513]], dtype=int16) 6205 >>> print type(y) 6206 <class 'numpy.matrixlib.defmatrix.matrix'> 6207 6208 Creating a view on a structured array so it can be used in calculations 6209 6210 >>> x = np.array([(1, 2),(3,4)], dtype=[('a', np.int8), ('b', np.int8)]) 6211 >>> xv = x.view(dtype=np.int8).reshape(-1,2) 6212 >>> xv 6213 array([[1, 2], 6214 [3, 4]], dtype=int8) 6215 >>> xv.mean(0) 6216 array([ 2., 3.]) 6217 6218 Making changes to the view changes the underlying array 6219 6220 >>> xv[0,1] = 20 6221 >>> print x 6222 [(1, 20) (3, 4)] 6223 6224 Using a view to convert an array to a record array: 6225 6226 >>> z = x.view(np.recarray) 6227 >>> z.a 6228 array([1], dtype=int8) 6229 6230 Views share data: 6231 6232 >>> x[0] = (9, 10) 6233 >>> z[0] 6234 (9, 10) 6235 6236 Views that change the dtype size (bytes per entry) should normally be 6237 avoided on arrays defined by slices, transposes, fortran-ordering, etc.: 6238 6239 >>> x = np.array([[1,2,3],[4,5,6]], dtype=np.int16) 6240 >>> y = x[:, 0:2] 6241 >>> y 6242 array([[1, 2], 6243 [4, 5]], dtype=int16) 6244 >>> y.view(dtype=[('width', np.int16), ('length', np.int16)]) 6245 Traceback (most recent call last): 6246 File "<stdin>", line 1, in <module> 6247 ValueError: new type not compatible with array. 6248 >>> z = y.copy() 6249 >>> z.view(dtype=[('width', np.int16), ('length', np.int16)]) 6250 array([[(1, 2)], 6251 [(4, 5)]], dtype=[('width', '<i2'), ('length', '<i2')])""" 6252 return None 6253 def zfill(self, _): 6254 """ 6255 Return the numeric string left-filled with zeros in a string of 6256 length `width`. 6257 6258 See also 6259 -------- 6260 char.zfill 6261 6262 """ 6263 return None 6264 def choose(a, choices="raise", out=None, mode="raise"): 6265 """ 6266 Construct an array from an index array and a set of arrays to choose from. 6267 6268 First of all, if confused or uncertain, definitely look at the Examples - 6269 in its full generality, this function is less simple than it might 6270 seem from the following code description (below ndi = 6271 `numpy.lib.index_tricks`): 6272 6273 ``np.choose(a,c) == np.array([c[a[I]][I] for I in ndi.ndindex(a.shape)])``. 6274 6275 But this omits some subtleties. Here is a fully general summary: 6276 6277 Given an "index" array (`a`) of integers and a sequence of `n` arrays 6278 (`choices`), `a` and each choice array are first broadcast, as necessary, 6279 to arrays of a common shape; calling these *Ba* and *Bchoices[i], i = 6280 0,...,n-1* we have that, necessarily, ``Ba.shape == Bchoices[i].shape`` 6281 for each `i`. Then, a new array with shape ``Ba.shape`` is created as 6282 follows: 6283 6284 * if ``mode=raise`` (the default), then, first of all, each element of 6285 `a` (and thus `Ba`) must be in the range `[0, n-1]`; now, suppose that 6286 `i` (in that range) is the value at the `(j0, j1, ..., jm)` position 6287 in `Ba` - then the value at the same position in the new array is the 6288 value in `Bchoices[i]` at that same position; 6289 6290 * if ``mode=wrap``, values in `a` (and thus `Ba`) may be any (signed) 6291 integer; modular arithmetic is used to map integers outside the range 6292 `[0, n-1]` back into that range; and then the new array is constructed 6293 as above; 6294 6295 * if ``mode=clip``, values in `a` (and thus `Ba`) may be any (signed) 6296 integer; negative integers are mapped to 0; values greater than `n-1` 6297 are mapped to `n-1`; and then the new array is constructed as above. 6298 6299 Parameters 6300 ---------- 6301 a : int array 6302 This array must contain integers in `[0, n-1]`, where `n` is the number 6303 of choices, unless ``mode=wrap`` or ``mode=clip``, in which cases any 6304 integers are permissible. 6305 choices : sequence of arrays 6306 Choice arrays. `a` and all of the choices must be broadcastable to the 6307 same shape. If `choices` is itself an array (not recommended), then 6308 its outermost dimension (i.e., the one corresponding to 6309 ``choices.shape[0]``) is taken as defining the "sequence". 6310 out : array, optional 6311 If provided, the result will be inserted into this array. It should 6312 be of the appropriate shape and dtype. 6313 mode : {'raise' (default), 'wrap', 'clip'}, optional 6314 Specifies how indices outside `[0, n-1]` will be treated: 6315 6316 * 'raise' : an exception is raised 6317 * 'wrap' : value becomes value mod `n` 6318 * 'clip' : values < 0 are mapped to 0, values > n-1 are mapped to n-1 6319 6320 Returns 6321 ------- 6322 merged_array : array 6323 The merged result. 6324 6325 Raises 6326 ------ 6327 ValueError: shape mismatch 6328 If `a` and each choice array are not all broadcastable to the same 6329 shape. 6330 6331 See Also 6332 -------- 6333 ndarray.choose : equivalent method 6334 6335 Notes 6336 ----- 6337 To reduce the chance of misinterpretation, even though the following 6338 "abuse" is nominally supported, `choices` should neither be, nor be 6339 thought of as, a single array, i.e., the outermost sequence-like container 6340 should be either a list or a tuple. 6341 6342 Examples 6343 -------- 6344 6345 >>> choices = [[0, 1, 2, 3], [10, 11, 12, 13], 6346 ... [20, 21, 22, 23], [30, 31, 32, 33]] 6347 >>> np.choose([2, 3, 1, 0], choices 6348 ... # the first element of the result will be the first element of the 6349 ... # third (2+1) "array" in choices, namely, 20; the second element 6350 ... # will be the second element of the fourth (3+1) choice array, i.e., 6351 ... # 31, etc. 6352 ... ) 6353 array([20, 31, 12, 3]) 6354 >>> np.choose([2, 4, 1, 0], choices, mode='clip') # 4 goes to 3 (4-1) 6355 array([20, 31, 12, 3]) 6356 >>> # because there are 4 choice arrays 6357 >>> np.choose([2, 4, 1, 0], choices, mode='wrap') # 4 goes to (4 mod 4) 6358 array([20, 1, 12, 3]) 6359 >>> # i.e., 0 6360 6361 A couple examples illustrating how choose broadcasts: 6362 6363 >>> a = [[1, 0, 1], [0, 1, 0], [1, 0, 1]] 6364 >>> choices = [-10, 10] 6365 >>> np.choose(a, choices) 6366 array([[ 10, -10, 10], 6367 [-10, 10, -10], 6368 [ 10, -10, 10]]) 6369 6370 >>> # With thanks to Anne Archibald 6371 >>> a = np.array([0, 1]).reshape((2,1,1)) 6372 >>> c1 = np.array([1, 2, 3]).reshape((1,3,1)) 6373 >>> c2 = np.array([-1, -2, -3, -4, -5]).reshape((1,1,5)) 6374 >>> np.choose(a, (c1, c2)) # result is 2x3x5, res[0,:,:]=c1, res[1,:,:]=c2 6375 array([[[ 1, 1, 1, 1, 1], 6376 [ 2, 2, 2, 2, 2], 6377 [ 3, 3, 3, 3, 3]], 6378 [[-1, -2, -3, -4, -5], 6379 [-1, -2, -3, -4, -5], 6380 [-1, -2, -3, -4, -5]]]) 6381 6382 """ 6383 return array() 6384 def clip(a, a_min, a_max=None, out=None): 6385 """ 6386 Clip (limit) the values in an array. 6387 6388 Given an interval, values outside the interval are clipped to 6389 the interval edges. For example, if an interval of ``[0, 1]`` 6390 is specified, values smaller than 0 become 0, and values larger 6391 than 1 become 1. 6392 6393 Parameters 6394 ---------- 6395 a : array_like 6396 Array containing elements to clip. 6397 a_min : scalar or array_like 6398 Minimum value. 6399 a_max : scalar or array_like 6400 Maximum value. If `a_min` or `a_max` are array_like, then they will 6401 be broadcasted to the shape of `a`. 6402 out : ndarray, optional 6403 The results will be placed in this array. It may be the input 6404 array for in-place clipping. `out` must be of the right shape 6405 to hold the output. Its type is preserved. 6406 6407 Returns 6408 ------- 6409 clipped_array : ndarray 6410 An array with the elements of `a`, but where values 6411 < `a_min` are replaced with `a_min`, and those > `a_max` 6412 with `a_max`. 6413 6414 See Also 6415 -------- 6416 numpy.doc.ufuncs : Section "Output arguments" 6417 6418 Examples 6419 -------- 6420 >>> a = np.arange(10) 6421 >>> np.clip(a, 1, 8) 6422 array([1, 1, 2, 3, 4, 5, 6, 7, 8, 8]) 6423 >>> a 6424 array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) 6425 >>> np.clip(a, 3, 6, out=a) 6426 array([3, 3, 3, 3, 4, 5, 6, 6, 6, 6]) 6427 >>> a = np.arange(10) 6428 >>> a 6429 array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) 6430 >>> np.clip(a, [3,4,1,1,1,4,4,4,4,4], 8) 6431 array([3, 4, 2, 3, 4, 5, 6, 7, 8, 8]) 6432 6433 """ 6434 return ndarray() 6435 class complex256: 6436 T = getset_descriptor() 6437 __array_interface__ = getset_descriptor() 6438 __array_priority__ = getset_descriptor() 6439 __array_struct__ = getset_descriptor() 6440 __doc__ = str() 6441 base = getset_descriptor() 6442 def conj(self, _): 6443 """None""" 6444 return None 6445 data = getset_descriptor() 6446 dtype = getset_descriptor() 6447 flags = getset_descriptor() 6448 flat = getset_descriptor() 6449 imag = getset_descriptor() 6450 itemsize = getset_descriptor() 6451 nbytes = getset_descriptor() 6452 ndim = getset_descriptor() 6453 def newbyteorder(self, new_order): 6454 """newbyteorder(new_order='S') 6455 6456 Return a new `dtype` with a different byte order. 6457 6458 Changes are also made in all fields and sub-arrays of the data type. 6459 6460 The `new_order` code can be any from the following: 6461 6462 * {'<', 'L'} - little endian 6463 * {'>', 'B'} - big endian 6464 * {'=', 'N'} - native order 6465 * 'S' - swap dtype from current to opposite endian 6466 * {'|', 'I'} - ignore (no change to byte order) 6467 6468 Parameters 6469 ---------- 6470 new_order : str, optional 6471 Byte order to force; a value from the byte order specifications 6472 above. The default value ('S') results in swapping the current 6473 byte order. The code does a case-insensitive check on the first 6474 letter of `new_order` for the alternatives above. For example, 6475 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 6476 6477 6478 Returns 6479 ------- 6480 new_dtype : dtype 6481 New `dtype` object with the given change to the byte order.""" 6482 return dtype() 6483 real = getset_descriptor() 6484 shape = getset_descriptor() 6485 size = getset_descriptor() 6486 strides = getset_descriptor() 6487 class complex256: 6488 T = getset_descriptor() 6489 __array_interface__ = getset_descriptor() 6490 __array_priority__ = getset_descriptor() 6491 __array_struct__ = getset_descriptor() 6492 __doc__ = str() 6493 base = getset_descriptor() 6494 def conj(self, _): 6495 """None""" 6496 return None 6497 data = getset_descriptor() 6498 dtype = getset_descriptor() 6499 flags = getset_descriptor() 6500 flat = getset_descriptor() 6501 imag = getset_descriptor() 6502 itemsize = getset_descriptor() 6503 nbytes = getset_descriptor() 6504 ndim = getset_descriptor() 6505 def newbyteorder(self, new_order): 6506 """newbyteorder(new_order='S') 6507 6508 Return a new `dtype` with a different byte order. 6509 6510 Changes are also made in all fields and sub-arrays of the data type. 6511 6512 The `new_order` code can be any from the following: 6513 6514 * {'<', 'L'} - little endian 6515 * {'>', 'B'} - big endian 6516 * {'=', 'N'} - native order 6517 * 'S' - swap dtype from current to opposite endian 6518 * {'|', 'I'} - ignore (no change to byte order) 6519 6520 Parameters 6521 ---------- 6522 new_order : str, optional 6523 Byte order to force; a value from the byte order specifications 6524 above. The default value ('S') results in swapping the current 6525 byte order. The code does a case-insensitive check on the first 6526 letter of `new_order` for the alternatives above. For example, 6527 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 6528 6529 6530 Returns 6531 ------- 6532 new_dtype : dtype 6533 New `dtype` object with the given change to the byte order.""" 6534 return dtype() 6535 real = getset_descriptor() 6536 shape = getset_descriptor() 6537 size = getset_descriptor() 6538 strides = getset_descriptor() 6539 def column_stack(tup): 6540 """ 6541 Stack 1-D arrays as columns into a 2-D array. 6542 6543 Take a sequence of 1-D arrays and stack them as columns 6544 to make a single 2-D array. 2-D arrays are stacked as-is, 6545 just like with `hstack`. 1-D arrays are turned into 2-D columns 6546 first. 6547 6548 Parameters 6549 ---------- 6550 tup : sequence of 1-D or 2-D arrays. 6551 Arrays to stack. All of them must have the same first dimension. 6552 6553 Returns 6554 ------- 6555 stacked : 2-D array 6556 The array formed by stacking the given arrays. 6557 6558 See Also 6559 -------- 6560 hstack, vstack, concatenate 6561 6562 Notes 6563 ----- 6564 This function is equivalent to ``np.vstack(tup).T``. 6565 6566 Examples 6567 -------- 6568 >>> a = np.array((1,2,3)) 6569 >>> b = np.array((2,3,4)) 6570 >>> np.column_stack((a,b)) 6571 array([[1, 2], 6572 [2, 3], 6573 [3, 4]]) 6574 6575 """ 6576 return _2_D() 6577 def common_type(): 6578 """ 6579 Return a scalar type which is common to the input arrays. 6580 6581 The return type will always be an inexact (i.e. floating point) scalar 6582 type, even if all the arrays are integer arrays. If one of the inputs is 6583 an integer array, the minimum precision type that is returned is a 6584 64-bit floating point dtype. 6585 6586 All input arrays can be safely cast to the returned dtype without loss 6587 of information. 6588 6589 Parameters 6590 ---------- 6591 array1, array2, ... : ndarrays 6592 Input arrays. 6593 6594 Returns 6595 ------- 6596 out : data type code 6597 Data type code. 6598 6599 See Also 6600 -------- 6601 dtype, mintypecode 6602 6603 Examples 6604 -------- 6605 >>> np.common_type(np.arange(2, dtype=np.float32)) 6606 <type 'numpy.float32'> 6607 >>> np.common_type(np.arange(2, dtype=np.float32), np.arange(2)) 6608 <type 'numpy.float64'> 6609 >>> np.common_type(np.arange(4), np.array([45, 6.j]), np.array([45.0])) 6610 <type 'numpy.complex128'> 6611 6612 """ 6613 return data() 6614 def compare_chararrays(): 6615 """None""" 6616 return None 6617 class complex: 6618 __doc__ = str() 6619 def conjugate(self, _): 6620 """complex.conjugate() -> complex 6621 6622 Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j.""" 6623 return None 6624 imag = member_descriptor() 6625 real = member_descriptor() 6626 class complex128: 6627 T = getset_descriptor() 6628 __array_interface__ = getset_descriptor() 6629 __array_priority__ = getset_descriptor() 6630 __array_struct__ = getset_descriptor() 6631 __doc__ = str() 6632 base = getset_descriptor() 6633 def conj(self, _): 6634 """None""" 6635 return None 6636 data = getset_descriptor() 6637 dtype = getset_descriptor() 6638 flags = getset_descriptor() 6639 flat = getset_descriptor() 6640 imag = getset_descriptor() 6641 itemsize = getset_descriptor() 6642 nbytes = getset_descriptor() 6643 ndim = getset_descriptor() 6644 def newbyteorder(self, new_order): 6645 """newbyteorder(new_order='S') 6646 6647 Return a new `dtype` with a different byte order. 6648 6649 Changes are also made in all fields and sub-arrays of the data type. 6650 6651 The `new_order` code can be any from the following: 6652 6653 * {'<', 'L'} - little endian 6654 * {'>', 'B'} - big endian 6655 * {'=', 'N'} - native order 6656 * 'S' - swap dtype from current to opposite endian 6657 * {'|', 'I'} - ignore (no change to byte order) 6658 6659 Parameters 6660 ---------- 6661 new_order : str, optional 6662 Byte order to force; a value from the byte order specifications 6663 above. The default value ('S') results in swapping the current 6664 byte order. The code does a case-insensitive check on the first 6665 letter of `new_order` for the alternatives above. For example, 6666 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 6667 6668 6669 Returns 6670 ------- 6671 new_dtype : dtype 6672 New `dtype` object with the given change to the byte order.""" 6673 return dtype() 6674 real = getset_descriptor() 6675 shape = getset_descriptor() 6676 size = getset_descriptor() 6677 strides = getset_descriptor() 6678 class complex256: 6679 T = getset_descriptor() 6680 __array_interface__ = getset_descriptor() 6681 __array_priority__ = getset_descriptor() 6682 __array_struct__ = getset_descriptor() 6683 __doc__ = str() 6684 base = getset_descriptor() 6685 def conj(self, _): 6686 """None""" 6687 return None 6688 data = getset_descriptor() 6689 dtype = getset_descriptor() 6690 flags = getset_descriptor() 6691 flat = getset_descriptor() 6692 imag = getset_descriptor() 6693 itemsize = getset_descriptor() 6694 nbytes = getset_descriptor() 6695 ndim = getset_descriptor() 6696 def newbyteorder(self, new_order): 6697 """newbyteorder(new_order='S') 6698 6699 Return a new `dtype` with a different byte order. 6700 6701 Changes are also made in all fields and sub-arrays of the data type. 6702 6703 The `new_order` code can be any from the following: 6704 6705 * {'<', 'L'} - little endian 6706 * {'>', 'B'} - big endian 6707 * {'=', 'N'} - native order 6708 * 'S' - swap dtype from current to opposite endian 6709 * {'|', 'I'} - ignore (no change to byte order) 6710 6711 Parameters 6712 ---------- 6713 new_order : str, optional 6714 Byte order to force; a value from the byte order specifications 6715 above. The default value ('S') results in swapping the current 6716 byte order. The code does a case-insensitive check on the first 6717 letter of `new_order` for the alternatives above. For example, 6718 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 6719 6720 6721 Returns 6722 ------- 6723 new_dtype : dtype 6724 New `dtype` object with the given change to the byte order.""" 6725 return dtype() 6726 real = getset_descriptor() 6727 shape = getset_descriptor() 6728 size = getset_descriptor() 6729 strides = getset_descriptor() 6730 class complex64: 6731 T = getset_descriptor() 6732 __array_interface__ = getset_descriptor() 6733 __array_priority__ = getset_descriptor() 6734 __array_struct__ = getset_descriptor() 6735 __doc__ = str() 6736 base = getset_descriptor() 6737 def conj(self, _): 6738 """None""" 6739 return None 6740 data = getset_descriptor() 6741 dtype = getset_descriptor() 6742 flags = getset_descriptor() 6743 flat = getset_descriptor() 6744 imag = getset_descriptor() 6745 itemsize = getset_descriptor() 6746 nbytes = getset_descriptor() 6747 ndim = getset_descriptor() 6748 def newbyteorder(self, new_order): 6749 """newbyteorder(new_order='S') 6750 6751 Return a new `dtype` with a different byte order. 6752 6753 Changes are also made in all fields and sub-arrays of the data type. 6754 6755 The `new_order` code can be any from the following: 6756 6757 * {'<', 'L'} - little endian 6758 * {'>', 'B'} - big endian 6759 * {'=', 'N'} - native order 6760 * 'S' - swap dtype from current to opposite endian 6761 * {'|', 'I'} - ignore (no change to byte order) 6762 6763 Parameters 6764 ---------- 6765 new_order : str, optional 6766 Byte order to force; a value from the byte order specifications 6767 above. The default value ('S') results in swapping the current 6768 byte order. The code does a case-insensitive check on the first 6769 letter of `new_order` for the alternatives above. For example, 6770 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 6771 6772 6773 Returns 6774 ------- 6775 new_dtype : dtype 6776 New `dtype` object with the given change to the byte order.""" 6777 return dtype() 6778 real = getset_descriptor() 6779 shape = getset_descriptor() 6780 size = getset_descriptor() 6781 strides = getset_descriptor() 6782 class complex128: 6783 T = getset_descriptor() 6784 __array_interface__ = getset_descriptor() 6785 __array_priority__ = getset_descriptor() 6786 __array_struct__ = getset_descriptor() 6787 __doc__ = str() 6788 base = getset_descriptor() 6789 def conj(self, _): 6790 """None""" 6791 return None 6792 data = getset_descriptor() 6793 dtype = getset_descriptor() 6794 flags = getset_descriptor() 6795 flat = getset_descriptor() 6796 imag = getset_descriptor() 6797 itemsize = getset_descriptor() 6798 nbytes = getset_descriptor() 6799 ndim = getset_descriptor() 6800 def newbyteorder(self, new_order): 6801 """newbyteorder(new_order='S') 6802 6803 Return a new `dtype` with a different byte order. 6804 6805 Changes are also made in all fields and sub-arrays of the data type. 6806 6807 The `new_order` code can be any from the following: 6808 6809 * {'<', 'L'} - little endian 6810 * {'>', 'B'} - big endian 6811 * {'=', 'N'} - native order 6812 * 'S' - swap dtype from current to opposite endian 6813 * {'|', 'I'} - ignore (no change to byte order) 6814 6815 Parameters 6816 ---------- 6817 new_order : str, optional 6818 Byte order to force; a value from the byte order specifications 6819 above. The default value ('S') results in swapping the current 6820 byte order. The code does a case-insensitive check on the first 6821 letter of `new_order` for the alternatives above. For example, 6822 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 6823 6824 6825 Returns 6826 ------- 6827 new_dtype : dtype 6828 New `dtype` object with the given change to the byte order.""" 6829 return dtype() 6830 real = getset_descriptor() 6831 shape = getset_descriptor() 6832 size = getset_descriptor() 6833 strides = getset_descriptor() 6834 class complexfloating: 6835 T = getset_descriptor() 6836 __array_interface__ = getset_descriptor() 6837 __array_priority__ = getset_descriptor() 6838 __array_struct__ = getset_descriptor() 6839 __doc__ = None 6840 base = getset_descriptor() 6841 def conj(self, _): 6842 """None""" 6843 return None 6844 data = getset_descriptor() 6845 dtype = getset_descriptor() 6846 flags = getset_descriptor() 6847 flat = getset_descriptor() 6848 imag = getset_descriptor() 6849 itemsize = getset_descriptor() 6850 nbytes = getset_descriptor() 6851 ndim = getset_descriptor() 6852 def newbyteorder(self, new_order): 6853 """newbyteorder(new_order='S') 6854 6855 Return a new `dtype` with a different byte order. 6856 6857 Changes are also made in all fields and sub-arrays of the data type. 6858 6859 The `new_order` code can be any from the following: 6860 6861 * {'<', 'L'} - little endian 6862 * {'>', 'B'} - big endian 6863 * {'=', 'N'} - native order 6864 * 'S' - swap dtype from current to opposite endian 6865 * {'|', 'I'} - ignore (no change to byte order) 6866 6867 Parameters 6868 ---------- 6869 new_order : str, optional 6870 Byte order to force; a value from the byte order specifications 6871 above. The default value ('S') results in swapping the current 6872 byte order. The code does a case-insensitive check on the first 6873 letter of `new_order` for the alternatives above. For example, 6874 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 6875 6876 6877 Returns 6878 ------- 6879 new_dtype : dtype 6880 New `dtype` object with the given change to the byte order.""" 6881 return dtype() 6882 real = getset_descriptor() 6883 shape = getset_descriptor() 6884 size = getset_descriptor() 6885 strides = getset_descriptor() 6886 def compress(condition, a=None, axis=None, out=None): 6887 """ 6888 Return selected slices of an array along given axis. 6889 6890 When working along a given axis, a slice along that axis is returned in 6891 `output` for each index where `condition` evaluates to True. When 6892 working on a 1-D array, `compress` is equivalent to `extract`. 6893 6894 Parameters 6895 ---------- 6896 condition : 1-D array of bools 6897 Array that selects which entries to return. If len(condition) 6898 is less than the size of `a` along the given axis, then output is 6899 truncated to the length of the condition array. 6900 a : array_like 6901 Array from which to extract a part. 6902 axis : int, optional 6903 Axis along which to take slices. If None (default), work on the 6904 flattened array. 6905 out : ndarray, optional 6906 Output array. Its type is preserved and it must be of the right 6907 shape to hold the output. 6908 6909 Returns 6910 ------- 6911 compressed_array : ndarray 6912 A copy of `a` without the slices along axis for which `condition` 6913 is false. 6914 6915 See Also 6916 -------- 6917 take, choose, diag, diagonal, select 6918 ndarray.compress : Equivalent method in ndarray 6919 np.extract: Equivalent method when working on 1-D arrays 6920 numpy.doc.ufuncs : Section "Output arguments" 6921 6922 Examples 6923 -------- 6924 >>> a = np.array([[1, 2], [3, 4], [5, 6]]) 6925 >>> a 6926 array([[1, 2], 6927 [3, 4], 6928 [5, 6]]) 6929 >>> np.compress([0, 1], a, axis=0) 6930 array([[3, 4]]) 6931 >>> np.compress([False, True, True], a, axis=0) 6932 array([[3, 4], 6933 [5, 6]]) 6934 >>> np.compress([False, True], a, axis=1) 6935 array([[2], 6936 [4], 6937 [6]]) 6938 6939 Working on the flattened array does not return slices along an axis but 6940 selects elements. 6941 6942 >>> np.compress([False, True], a) 6943 array([2]) 6944 6945 """ 6946 return ndarray() 6947 def concatenate(a1, a2, more_args, axis=0): 6948 """concatenate((a1, a2, ...), axis=0) 6949 6950 Join a sequence of arrays together. 6951 6952 Parameters 6953 ---------- 6954 a1, a2, ... : sequence of array_like 6955 The arrays must have the same shape, except in the dimension 6956 corresponding to `axis` (the first, by default). 6957 axis : int, optional 6958 The axis along which the arrays will be joined. Default is 0. 6959 6960 Returns 6961 ------- 6962 res : ndarray 6963 The concatenated array. 6964 6965 See Also 6966 -------- 6967 ma.concatenate : Concatenate function that preserves input masks. 6968 array_split : Split an array into multiple sub-arrays of equal or 6969 near-equal size. 6970 split : Split array into a list of multiple sub-arrays of equal size. 6971 hsplit : Split array into multiple sub-arrays horizontally (column wise) 6972 vsplit : Split array into multiple sub-arrays vertically (row wise) 6973 dsplit : Split array into multiple sub-arrays along the 3rd axis (depth). 6974 hstack : Stack arrays in sequence horizontally (column wise) 6975 vstack : Stack arrays in sequence vertically (row wise) 6976 dstack : Stack arrays in sequence depth wise (along third dimension) 6977 6978 Notes 6979 ----- 6980 When one or more of the arrays to be concatenated is a MaskedArray, 6981 this function will return a MaskedArray object instead of an ndarray, 6982 but the input masks are *not* preserved. In cases where a MaskedArray 6983 is expected as input, use the ma.concatenate function from the masked 6984 array module instead. 6985 6986 Examples 6987 -------- 6988 >>> a = np.array([[1, 2], [3, 4]]) 6989 >>> b = np.array([[5, 6]]) 6990 >>> np.concatenate((a, b), axis=0) 6991 array([[1, 2], 6992 [3, 4], 6993 [5, 6]]) 6994 >>> np.concatenate((a, b.T), axis=1) 6995 array([[1, 2, 5], 6996 [3, 4, 6]]) 6997 6998 This function will not preserve masking of MaskedArray inputs. 6999 7000 >>> a = np.ma.arange(3) 7001 >>> a[1] = np.ma.masked 7002 >>> b = np.arange(2, 5) 7003 >>> a 7004 masked_array(data = [0 -- 2], 7005 mask = [False True False], 7006 fill_value = 999999) 7007 >>> b 7008 array([2, 3, 4]) 7009 >>> np.concatenate([a, b]) 7010 masked_array(data = [0 1 2 2 3 4], 7011 mask = False, 7012 fill_value = 999999) 7013 >>> np.ma.concatenate([a, b]) 7014 masked_array(data = [0 -- 2 2 3 4], 7015 mask = [False True False False False False], 7016 fill_value = 999999)""" 7017 return ndarray() 7018 def conjugate(x, out=None): 7019 """conjugate(x[, out]) 7020 7021 Return the complex conjugate, element-wise. 7022 7023 The complex conjugate of a complex number is obtained by changing the 7024 sign of its imaginary part. 7025 7026 Parameters 7027 ---------- 7028 x : array_like 7029 Input value. 7030 7031 Returns 7032 ------- 7033 y : ndarray 7034 The complex conjugate of `x`, with same dtype as `y`. 7035 7036 Examples 7037 -------- 7038 >>> np.conjugate(1+2j) 7039 (1-2j) 7040 7041 >>> x = np.eye(2) + 1j * np.eye(2) 7042 >>> np.conjugate(x) 7043 array([[ 1.-1.j, 0.-0.j], 7044 [ 0.-0.j, 1.-1.j]])""" 7045 return ndarray() 7046 def conjugate(x, out=None): 7047 """conjugate(x[, out]) 7048 7049 Return the complex conjugate, element-wise. 7050 7051 The complex conjugate of a complex number is obtained by changing the 7052 sign of its imaginary part. 7053 7054 Parameters 7055 ---------- 7056 x : array_like 7057 Input value. 7058 7059 Returns 7060 ------- 7061 y : ndarray 7062 The complex conjugate of `x`, with same dtype as `y`. 7063 7064 Examples 7065 -------- 7066 >>> np.conjugate(1+2j) 7067 (1-2j) 7068 7069 >>> x = np.eye(2) + 1j * np.eye(2) 7070 >>> np.conjugate(x) 7071 array([[ 1.-1.j, 0.-0.j], 7072 [ 0.-0.j, 1.-1.j]])""" 7073 return ndarray() 7074 def convolve(a, v="full", mode="full"): 7075 """ 7076 Returns the discrete, linear convolution of two one-dimensional sequences. 7077 7078 The convolution operator is often seen in signal processing, where it 7079 models the effect of a linear time-invariant system on a signal [1]_. In 7080 probability theory, the sum of two independent random variables is 7081 distributed according to the convolution of their individual 7082 distributions. 7083 7084 Parameters 7085 ---------- 7086 a : (N,) array_like 7087 First one-dimensional input array. 7088 v : (M,) array_like 7089 Second one-dimensional input array. 7090 mode : {'full', 'valid', 'same'}, optional 7091 'full': 7092 By default, mode is 'full'. This returns the convolution 7093 at each point of overlap, with an output shape of (N+M-1,). At 7094 the end-points of the convolution, the signals do not overlap 7095 completely, and boundary effects may be seen. 7096 7097 'same': 7098 Mode `same` returns output of length ``max(M, N)``. Boundary 7099 effects are still visible. 7100 7101 'valid': 7102 Mode `valid` returns output of length 7103 ``max(M, N) - min(M, N) + 1``. The convolution product is only given 7104 for points where the signals overlap completely. Values outside 7105 the signal boundary have no effect. 7106 7107 Returns 7108 ------- 7109 out : ndarray 7110 Discrete, linear convolution of `a` and `v`. 7111 7112 See Also 7113 -------- 7114 scipy.signal.fftconvolve : Convolve two arrays using the Fast Fourier 7115 Transform. 7116 scipy.linalg.toeplitz : Used to construct the convolution operator. 7117 7118 Notes 7119 ----- 7120 The discrete convolution operation is defined as 7121 7122 .. math:: (f * g)[n] = \sum_{m = -\infty}^{\infty} f[m] g[n - m] 7123 7124 It can be shown that a convolution :math:`x(t) * y(t)` in time/space 7125 is equivalent to the multiplication :math:`X(f) Y(f)` in the Fourier 7126 domain, after appropriate padding (padding is necessary to prevent 7127 circular convolution). Since multiplication is more efficient (faster) 7128 than convolution, the function `scipy.signal.fftconvolve` exploits the 7129 FFT to calculate the convolution of large data-sets. 7130 7131 References 7132 ---------- 7133 .. [1] Wikipedia, "Convolution", http://en.wikipedia.org/wiki/Convolution. 7134 7135 Examples 7136 -------- 7137 Note how the convolution operator flips the second array 7138 before "sliding" the two across one another: 7139 7140 >>> np.convolve([1, 2, 3], [0, 1, 0.5]) 7141 array([ 0. , 1. , 2.5, 4. , 1.5]) 7142 7143 Only return the middle values of the convolution. 7144 Contains boundary effects, where zeros are taken 7145 into account: 7146 7147 >>> np.convolve([1,2,3],[0,1,0.5], 'same') 7148 array([ 1. , 2.5, 4. ]) 7149 7150 The two arrays are of the same length, so there 7151 is only one position where they completely overlap: 7152 7153 >>> np.convolve([1,2,3],[0,1,0.5], 'valid') 7154 array([ 2.5]) 7155 7156 """ 7157 return ndarray() 7158 def copy(a="K", order="K"): 7159 """ 7160 Return an array copy of the given object. 7161 7162 Parameters 7163 ---------- 7164 a : array_like 7165 Input data. 7166 order : {'C', 'F', 'A', 'K'}, optional 7167 Controls the memory layout of the copy. 'C' means C-order, 7168 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, 7169 'C' otherwise. 'K' means match the layout of `a` as closely 7170 as possible. (Note that this function and :meth:ndarray.copy are very 7171 similar, but have different default values for their order= 7172 arguments.) 7173 7174 Returns 7175 ------- 7176 arr : ndarray 7177 Array interpretation of `a`. 7178 7179 Notes 7180 ----- 7181 This is equivalent to 7182 7183 >>> np.array(a, copy=True) #doctest: +SKIP 7184 7185 Examples 7186 -------- 7187 Create an array x, with a reference y and a copy z: 7188 7189 >>> x = np.array([1, 2, 3]) 7190 >>> y = x 7191 >>> z = np.copy(x) 7192 7193 Note that, when we modify x, y changes, but not z: 7194 7195 >>> x[0] = 10 7196 >>> x[0] == y[0] 7197 True 7198 >>> x[0] == z[0] 7199 False 7200 7201 """ 7202 return ndarray() 7203 def copysign(x1, x2, out): 7204 """copysign(x1, x2[, out]) 7205 7206 Change the sign of x1 to that of x2, element-wise. 7207 7208 If both arguments are arrays or sequences, they have to be of the same 7209 length. If `x2` is a scalar, its sign will be copied to all elements of 7210 `x1`. 7211 7212 Parameters 7213 ---------- 7214 x1 : array_like 7215 Values to change the sign of. 7216 x2 : array_like 7217 The sign of `x2` is copied to `x1`. 7218 out : ndarray, optional 7219 Array into which the output is placed. Its type is preserved and it 7220 must be of the right shape to hold the output. See doc.ufuncs. 7221 7222 Returns 7223 ------- 7224 out : array_like 7225 The values of `x1` with the sign of `x2`. 7226 7227 Examples 7228 -------- 7229 >>> np.copysign(1.3, -1) 7230 -1.3 7231 >>> 1/np.copysign(0, 1) 7232 inf 7233 >>> 1/np.copysign(0, -1) 7234 -inf 7235 7236 >>> np.copysign([-1, 0, 1], -1.1) 7237 array([-1., -0., -1.]) 7238 >>> np.copysign([-1, 0, 1], np.arange(3)-1) 7239 array([-1., 0., 1.])""" 7240 return ndarray() 7241 def copyto(dst, src, casting=same_kind, where=None, preservena=False): 7242 """copyto(dst, src, casting='same_kind', where=None, preservena=False) 7243 7244 Copies values from one array to another, broadcasting as necessary. 7245 7246 Raises a TypeError if the `casting` rule is violated, and if 7247 `where` is provided, it selects which elements to copy. 7248 7249 .. versionadded:: 1.7.0 7250 7251 Parameters 7252 ---------- 7253 dst : ndarray 7254 The array into which values are copied. 7255 src : array_like 7256 The array from which values are copied. 7257 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional 7258 Controls what kind of data casting may occur when copying. 7259 7260 * 'no' means the data types should not be cast at all. 7261 * 'equiv' means only byte-order changes are allowed. 7262 * 'safe' means only casts which can preserve values are allowed. 7263 * 'same_kind' means only safe casts or casts within a kind, 7264 like float64 to float32, are allowed. 7265 * 'unsafe' means any data conversions may be done. 7266 where : array_like of bool, optional 7267 A boolean array which is broadcasted to match the dimensions 7268 of `dst`, and selects elements to copy from `src` to `dst` 7269 wherever it contains the value True. 7270 preservena : bool, optional 7271 If set to True, leaves any NA values in `dst` untouched. This 7272 is similar to the "hard mask" feature in numpy.ma.""" 7273 return None 7274 def corrcoef(x=None, y=None, rowvar=1, bias=0, ddof=None): 7275 """ 7276 Return correlation coefficients. 7277 7278 Please refer to the documentation for `cov` for more detail. The 7279 relationship between the correlation coefficient matrix, `P`, and the 7280 covariance matrix, `C`, is 7281 7282 .. math:: P_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } } 7283 7284 The values of `P` are between -1 and 1, inclusive. 7285 7286 Parameters 7287 ---------- 7288 x : array_like 7289 A 1-D or 2-D array containing multiple variables and observations. 7290 Each row of `m` represents a variable, and each column a single 7291 observation of all those variables. Also see `rowvar` below. 7292 y : array_like, optional 7293 An additional set of variables and observations. `y` has the same 7294 shape as `m`. 7295 rowvar : int, optional 7296 If `rowvar` is non-zero (default), then each row represents a 7297 variable, with observations in the columns. Otherwise, the relationship 7298 is transposed: each column represents a variable, while the rows 7299 contain observations. 7300 bias : int, optional 7301 Default normalization is by ``(N - 1)``, where ``N`` is the number of 7302 observations (unbiased estimate). If `bias` is 1, then 7303 normalization is by ``N``. These values can be overridden by using 7304 the keyword ``ddof`` in numpy versions >= 1.5. 7305 ddof : {None, int}, optional 7306 .. versionadded:: 1.5 7307 If not ``None`` normalization is by ``(N - ddof)``, where ``N`` is 7308 the number of observations; this overrides the value implied by 7309 ``bias``. The default value is ``None``. 7310 7311 Returns 7312 ------- 7313 out : ndarray 7314 The correlation coefficient matrix of the variables. 7315 7316 See Also 7317 -------- 7318 cov : Covariance matrix 7319 7320 """ 7321 return ndarray() 7322 def correlate(a, v=False, mode="valid", old_behavior=False): 7323 """ 7324 Cross-correlation of two 1-dimensional sequences. 7325 7326 This function computes the correlation as generally defined in signal 7327 processing texts:: 7328 7329 z[k] = sum_n a[n] * conj(v[n+k]) 7330 7331 with a and v sequences being zero-padded where necessary and conj being 7332 the conjugate. 7333 7334 Parameters 7335 ---------- 7336 a, v : array_like 7337 Input sequences. 7338 mode : {'valid', 'same', 'full'}, optional 7339 Refer to the `convolve` docstring. Note that the default 7340 is `valid`, unlike `convolve`, which uses `full`. 7341 old_behavior : bool 7342 If True, uses the old behavior from Numeric, 7343 (correlate(a,v) == correlate(v,a), and the conjugate is not taken 7344 for complex arrays). If False, uses the conventional signal 7345 processing definition. 7346 7347 See Also 7348 -------- 7349 convolve : Discrete, linear convolution of two one-dimensional sequences. 7350 7351 Examples 7352 -------- 7353 >>> np.correlate([1, 2, 3], [0, 1, 0.5]) 7354 array([ 3.5]) 7355 >>> np.correlate([1, 2, 3], [0, 1, 0.5], "same") 7356 array([ 2. , 3.5, 3. ]) 7357 >>> np.correlate([1, 2, 3], [0, 1, 0.5], "full") 7358 array([ 0.5, 2. , 3.5, 3. , 0. ]) 7359 7360 """ 7361 return None 7362 def cos(x, out): 7363 """cos(x[, out]) 7364 7365 Cosine elementwise. 7366 7367 Parameters 7368 ---------- 7369 x : array_like 7370 Input array in radians. 7371 out : ndarray, optional 7372 Output array of same shape as `x`. 7373 7374 Returns 7375 ------- 7376 y : ndarray 7377 The corresponding cosine values. 7378 7379 Raises 7380 ------ 7381 ValueError: invalid return array shape 7382 if `out` is provided and `out.shape` != `x.shape` (See Examples) 7383 7384 Notes 7385 ----- 7386 If `out` is provided, the function writes the result into it, 7387 and returns a reference to `out`. (See Examples) 7388 7389 References 7390 ---------- 7391 M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions. 7392 New York, NY: Dover, 1972. 7393 7394 Examples 7395 -------- 7396 >>> np.cos(np.array([0, np.pi/2, np.pi])) 7397 array([ 1.00000000e+00, 6.12303177e-17, -1.00000000e+00]) 7398 >>> 7399 >>> # Example of providing the optional output parameter 7400 >>> out2 = np.cos([0.1], out1) 7401 >>> out2 is out1 7402 True 7403 >>> 7404 >>> # Example of ValueError due to provision of shape mis-matched `out` 7405 >>> np.cos(np.zeros((3,3)),np.zeros((2,2))) 7406 Traceback (most recent call last): 7407 File "<stdin>", line 1, in <module> 7408 ValueError: invalid return array shape""" 7409 return ndarray() 7410 def cosh(x, out=None): 7411 """cosh(x[, out]) 7412 7413 Hyperbolic cosine, element-wise. 7414 7415 Equivalent to ``1/2 * (np.exp(x) + np.exp(-x))`` and ``np.cos(1j*x)``. 7416 7417 Parameters 7418 ---------- 7419 x : array_like 7420 Input array. 7421 7422 Returns 7423 ------- 7424 out : ndarray 7425 Output array of same shape as `x`. 7426 7427 Examples 7428 -------- 7429 >>> np.cosh(0) 7430 1.0 7431 7432 The hyperbolic cosine describes the shape of a hanging cable: 7433 7434 >>> import matplotlib.pyplot as plt 7435 >>> x = np.linspace(-4, 4, 1000) 7436 >>> plt.plot(x, np.cosh(x)) 7437 >>> plt.show()""" 7438 return ndarray() 7439 def count_nonzero(a): 7440 """count_nonzero(a) 7441 7442 Counts the number of non-zero values in the array ``a``. 7443 7444 Parameters 7445 ---------- 7446 a : array_like 7447 The array for which to count non-zeros. 7448 7449 Returns 7450 ------- 7451 count : int or array of int 7452 Number of non-zero values in the array. 7453 7454 See Also 7455 -------- 7456 nonzero : Return the coordinates of all the non-zero values. 7457 7458 Examples 7459 -------- 7460 >>> np.count_nonzero(np.eye(4)) 7461 4 7462 >>> np.count_nonzero([[0,1,7,0,0],[3,0,0,2,19]]) 7463 5""" 7464 return int() if False else array() 7465 def cov(m=None, y=None, rowvar=1, bias=0, ddof=None): 7466 """ 7467 Estimate a covariance matrix, given data. 7468 7469 Covariance indicates the level to which two variables vary together. 7470 If we examine N-dimensional samples, :math:`X = [x_1, x_2, ... x_N]^T`, 7471 then the covariance matrix element :math:`C_{ij}` is the covariance of 7472 :math:`x_i` and :math:`x_j`. The element :math:`C_{ii}` is the variance 7473 of :math:`x_i`. 7474 7475 Parameters 7476 ---------- 7477 m : array_like 7478 A 1-D or 2-D array containing multiple variables and observations. 7479 Each row of `m` represents a variable, and each column a single 7480 observation of all those variables. Also see `rowvar` below. 7481 y : array_like, optional 7482 An additional set of variables and observations. `y` has the same 7483 form as that of `m`. 7484 rowvar : int, optional 7485 If `rowvar` is non-zero (default), then each row represents a 7486 variable, with observations in the columns. Otherwise, the relationship 7487 is transposed: each column represents a variable, while the rows 7488 contain observations. 7489 bias : int, optional 7490 Default normalization is by ``(N - 1)``, where ``N`` is the number of 7491 observations given (unbiased estimate). If `bias` is 1, then 7492 normalization is by ``N``. These values can be overridden by using 7493 the keyword ``ddof`` in numpy versions >= 1.5. 7494 ddof : int, optional 7495 .. versionadded:: 1.5 7496 If not ``None`` normalization is by ``(N - ddof)``, where ``N`` is 7497 the number of observations; this overrides the value implied by 7498 ``bias``. The default value is ``None``. 7499 7500 Returns 7501 ------- 7502 out : ndarray 7503 The covariance matrix of the variables. 7504 7505 See Also 7506 -------- 7507 corrcoef : Normalized covariance matrix 7508 7509 Examples 7510 -------- 7511 Consider two variables, :math:`x_0` and :math:`x_1`, which 7512 correlate perfectly, but in opposite directions: 7513 7514 >>> x = np.array([[0, 2], [1, 1], [2, 0]]).T 7515 >>> x 7516 array([[0, 1, 2], 7517 [2, 1, 0]]) 7518 7519 Note how :math:`x_0` increases while :math:`x_1` decreases. The covariance 7520 matrix shows this clearly: 7521 7522 >>> np.cov(x) 7523 array([[ 1., -1.], 7524 [-1., 1.]]) 7525 7526 Note that element :math:`C_{0,1}`, which shows the correlation between 7527 :math:`x_0` and :math:`x_1`, is negative. 7528 7529 Further, note how `x` and `y` are combined: 7530 7531 >>> x = [-2.1, -1, 4.3] 7532 >>> y = [3, 1.1, 0.12] 7533 >>> X = np.vstack((x,y)) 7534 >>> print np.cov(X) 7535 [[ 11.71 -4.286 ] 7536 [ -4.286 2.14413333]] 7537 >>> print np.cov(x, y) 7538 [[ 11.71 -4.286 ] 7539 [ -4.286 2.14413333]] 7540 >>> print np.cov(x) 7541 11.71 7542 7543 """ 7544 return ndarray() 7545 def cross(a, b=None, axisa=-1, axisb=-1, axisc=-1, axis=None): 7546 """ 7547 Return the cross product of two (arrays of) vectors. 7548 7549 The cross product of `a` and `b` in :math:`R^3` is a vector perpendicular 7550 to both `a` and `b`. If `a` and `b` are arrays of vectors, the vectors 7551 are defined by the last axis of `a` and `b` by default, and these axes 7552 can have dimensions 2 or 3. Where the dimension of either `a` or `b` is 7553 2, the third component of the input vector is assumed to be zero and the 7554 cross product calculated accordingly. In cases where both input vectors 7555 have dimension 2, the z-component of the cross product is returned. 7556 7557 Parameters 7558 ---------- 7559 a : array_like 7560 Components of the first vector(s). 7561 b : array_like 7562 Components of the second vector(s). 7563 axisa : int, optional 7564 Axis of `a` that defines the vector(s). By default, the last axis. 7565 axisb : int, optional 7566 Axis of `b` that defines the vector(s). By default, the last axis. 7567 axisc : int, optional 7568 Axis of `c` containing the cross product vector(s). By default, the 7569 last axis. 7570 axis : int, optional 7571 If defined, the axis of `a`, `b` and `c` that defines the vector(s) 7572 and cross product(s). Overrides `axisa`, `axisb` and `axisc`. 7573 7574 Returns 7575 ------- 7576 c : ndarray 7577 Vector cross product(s). 7578 7579 Raises 7580 ------ 7581 ValueError 7582 When the dimension of the vector(s) in `a` and/or `b` does not 7583 equal 2 or 3. 7584 7585 See Also 7586 -------- 7587 inner : Inner product 7588 outer : Outer product. 7589 ix_ : Construct index arrays. 7590 7591 Examples 7592 -------- 7593 Vector cross-product. 7594 7595 >>> x = [1, 2, 3] 7596 >>> y = [4, 5, 6] 7597 >>> np.cross(x, y) 7598 array([-3, 6, -3]) 7599 7600 One vector with dimension 2. 7601 7602 >>> x = [1, 2] 7603 >>> y = [4, 5, 6] 7604 >>> np.cross(x, y) 7605 array([12, -6, -3]) 7606 7607 Equivalently: 7608 7609 >>> x = [1, 2, 0] 7610 >>> y = [4, 5, 6] 7611 >>> np.cross(x, y) 7612 array([12, -6, -3]) 7613 7614 Both vectors with dimension 2. 7615 7616 >>> x = [1,2] 7617 >>> y = [4,5] 7618 >>> np.cross(x, y) 7619 -3 7620 7621 Multiple vector cross-products. Note that the direction of the cross 7622 product vector is defined by the `right-hand rule`. 7623 7624 >>> x = np.array([[1,2,3], [4,5,6]]) 7625 >>> y = np.array([[4,5,6], [1,2,3]]) 7626 >>> np.cross(x, y) 7627 array([[-3, 6, -3], 7628 [ 3, -6, 3]]) 7629 7630 The orientation of `c` can be changed using the `axisc` keyword. 7631 7632 >>> np.cross(x, y, axisc=0) 7633 array([[-3, 3], 7634 [ 6, -6], 7635 [-3, 3]]) 7636 7637 Change the vector definition of `x` and `y` using `axisa` and `axisb`. 7638 7639 >>> x = np.array([[1,2,3], [4,5,6], [7, 8, 9]]) 7640 >>> y = np.array([[7, 8, 9], [4,5,6], [1,2,3]]) 7641 >>> np.cross(x, y) 7642 array([[ -6, 12, -6], 7643 [ 0, 0, 0], 7644 [ 6, -12, 6]]) 7645 >>> np.cross(x, y, axisa=0, axisb=0) 7646 array([[-24, 48, -24], 7647 [-30, 60, -30], 7648 [-36, 72, -36]]) 7649 7650 """ 7651 return ndarray() 7652 class complex64: 7653 T = getset_descriptor() 7654 __array_interface__ = getset_descriptor() 7655 __array_priority__ = getset_descriptor() 7656 __array_struct__ = getset_descriptor() 7657 __doc__ = str() 7658 base = getset_descriptor() 7659 def conj(self, _): 7660 """None""" 7661 return None 7662 data = getset_descriptor() 7663 dtype = getset_descriptor() 7664 flags = getset_descriptor() 7665 flat = getset_descriptor() 7666 imag = getset_descriptor() 7667 itemsize = getset_descriptor() 7668 nbytes = getset_descriptor() 7669 ndim = getset_descriptor() 7670 def newbyteorder(self, new_order): 7671 """newbyteorder(new_order='S') 7672 7673 Return a new `dtype` with a different byte order. 7674 7675 Changes are also made in all fields and sub-arrays of the data type. 7676 7677 The `new_order` code can be any from the following: 7678 7679 * {'<', 'L'} - little endian 7680 * {'>', 'B'} - big endian 7681 * {'=', 'N'} - native order 7682 * 'S' - swap dtype from current to opposite endian 7683 * {'|', 'I'} - ignore (no change to byte order) 7684 7685 Parameters 7686 ---------- 7687 new_order : str, optional 7688 Byte order to force; a value from the byte order specifications 7689 above. The default value ('S') results in swapping the current 7690 byte order. The code does a case-insensitive check on the first 7691 letter of `new_order` for the alternatives above. For example, 7692 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 7693 7694 7695 Returns 7696 ------- 7697 new_dtype : dtype 7698 New `dtype` object with the given change to the byte order.""" 7699 return dtype() 7700 real = getset_descriptor() 7701 shape = getset_descriptor() 7702 size = getset_descriptor() 7703 strides = getset_descriptor() 7704 def cumprod(a=None, axis=None, dtype=None, out=None): 7705 """ 7706 Return the cumulative product of elements along a given axis. 7707 7708 Parameters 7709 ---------- 7710 a : array_like 7711 Input array. 7712 axis : int, optional 7713 Axis along which the cumulative product is computed. By default 7714 the input is flattened. 7715 dtype : dtype, optional 7716 Type of the returned array, as well as of the accumulator in which 7717 the elements are multiplied. If *dtype* is not specified, it 7718 defaults to the dtype of `a`, unless `a` has an integer dtype with 7719 a precision less than that of the default platform integer. In 7720 that case, the default platform integer is used instead. 7721 out : ndarray, optional 7722 Alternative output array in which to place the result. It must 7723 have the same shape and buffer length as the expected output 7724 but the type of the resulting values will be cast if necessary. 7725 7726 Returns 7727 ------- 7728 cumprod : ndarray 7729 A new array holding the result is returned unless `out` is 7730 specified, in which case a reference to out is returned. 7731 7732 See Also 7733 -------- 7734 numpy.doc.ufuncs : Section "Output arguments" 7735 7736 Notes 7737 ----- 7738 Arithmetic is modular when using integer types, and no error is 7739 raised on overflow. 7740 7741 Examples 7742 -------- 7743 >>> a = np.array([1,2,3]) 7744 >>> np.cumprod(a) # intermediate results 1, 1*2 7745 ... # total product 1*2*3 = 6 7746 array([1, 2, 6]) 7747 >>> a = np.array([[1, 2, 3], [4, 5, 6]]) 7748 >>> np.cumprod(a, dtype=float) # specify type of output 7749 array([ 1., 2., 6., 24., 120., 720.]) 7750 7751 The cumulative product for each column (i.e., over the rows) of `a`: 7752 7753 >>> np.cumprod(a, axis=0) 7754 array([[ 1, 2, 3], 7755 [ 4, 10, 18]]) 7756 7757 The cumulative product for each row (i.e. over the columns) of `a`: 7758 7759 >>> np.cumprod(a,axis=1) 7760 array([[ 1, 2, 6], 7761 [ 4, 20, 120]]) 7762 7763 """ 7764 return ndarray() 7765 def cumproduct(a=None, axis=None, dtype=None, out=None): 7766 """ 7767 Return the cumulative product over the given axis. 7768 7769 7770 See Also 7771 -------- 7772 cumprod : equivalent function; see for details. 7773 7774 """ 7775 return None 7776 def cumsum(a=None, axis=None, dtype=None, out=None): 7777 """ 7778 Return the cumulative sum of the elements along a given axis. 7779 7780 Parameters 7781 ---------- 7782 a : array_like 7783 Input array. 7784 axis : int, optional 7785 Axis along which the cumulative sum is computed. The default 7786 (None) is to compute the cumsum over the flattened array. 7787 dtype : dtype, optional 7788 Type of the returned array and of the accumulator in which the 7789 elements are summed. If `dtype` is not specified, it defaults 7790 to the dtype of `a`, unless `a` has an integer dtype with a 7791 precision less than that of the default platform integer. In 7792 that case, the default platform integer is used. 7793 out : ndarray, optional 7794 Alternative output array in which to place the result. It must 7795 have the same shape and buffer length as the expected output 7796 but the type will be cast if necessary. See `doc.ufuncs` 7797 (Section "Output arguments") for more details. 7798 7799 Returns 7800 ------- 7801 cumsum_along_axis : ndarray. 7802 A new array holding the result is returned unless `out` is 7803 specified, in which case a reference to `out` is returned. The 7804 result has the same size as `a`, and the same shape as `a` if 7805 `axis` is not None or `a` is a 1-d array. 7806 7807 7808 See Also 7809 -------- 7810 sum : Sum array elements. 7811 7812 trapz : Integration of array values using the composite trapezoidal rule. 7813 7814 diff : Calculate the n-th order discrete difference along given axis. 7815 7816 Notes 7817 ----- 7818 Arithmetic is modular when using integer types, and no error is 7819 raised on overflow. 7820 7821 Examples 7822 -------- 7823 >>> a = np.array([[1,2,3], [4,5,6]]) 7824 >>> a 7825 array([[1, 2, 3], 7826 [4, 5, 6]]) 7827 >>> np.cumsum(a) 7828 array([ 1, 3, 6, 10, 15, 21]) 7829 >>> np.cumsum(a, dtype=float) # specifies type of output value(s) 7830 array([ 1., 3., 6., 10., 15., 21.]) 7831 7832 >>> np.cumsum(a,axis=0) # sum over rows for each of the 3 columns 7833 array([[1, 2, 3], 7834 [5, 7, 9]]) 7835 >>> np.cumsum(a,axis=1) # sum over columns for each of the 2 rows 7836 array([[ 1, 3, 6], 7837 [ 4, 9, 15]]) 7838 7839 """ 7840 return ndarray() 7841 class datetime64: 7842 T = getset_descriptor() 7843 __array_interface__ = getset_descriptor() 7844 __array_priority__ = getset_descriptor() 7845 __array_struct__ = getset_descriptor() 7846 __doc__ = None 7847 base = getset_descriptor() 7848 def conj(self, _): 7849 """None""" 7850 return None 7851 data = getset_descriptor() 7852 dtype = getset_descriptor() 7853 flags = getset_descriptor() 7854 flat = getset_descriptor() 7855 imag = getset_descriptor() 7856 itemsize = getset_descriptor() 7857 nbytes = getset_descriptor() 7858 ndim = getset_descriptor() 7859 def newbyteorder(self, new_order): 7860 """newbyteorder(new_order='S') 7861 7862 Return a new `dtype` with a different byte order. 7863 7864 Changes are also made in all fields and sub-arrays of the data type. 7865 7866 The `new_order` code can be any from the following: 7867 7868 * {'<', 'L'} - little endian 7869 * {'>', 'B'} - big endian 7870 * {'=', 'N'} - native order 7871 * 'S' - swap dtype from current to opposite endian 7872 * {'|', 'I'} - ignore (no change to byte order) 7873 7874 Parameters 7875 ---------- 7876 new_order : str, optional 7877 Byte order to force; a value from the byte order specifications 7878 above. The default value ('S') results in swapping the current 7879 byte order. The code does a case-insensitive check on the first 7880 letter of `new_order` for the alternatives above. For example, 7881 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 7882 7883 7884 Returns 7885 ------- 7886 new_dtype : dtype 7887 New `dtype` object with the given change to the byte order.""" 7888 return dtype() 7889 real = getset_descriptor() 7890 shape = getset_descriptor() 7891 size = getset_descriptor() 7892 strides = getset_descriptor() 7893 def datetime_as_string(): 7894 """None""" 7895 return None 7896 def datetime_data(): 7897 """None""" 7898 return None 7899 def deg2rad(x, out=None): 7900 """deg2rad(x[, out]) 7901 7902 Convert angles from degrees to radians. 7903 7904 Parameters 7905 ---------- 7906 x : array_like 7907 Angles in degrees. 7908 7909 Returns 7910 ------- 7911 y : ndarray 7912 The corresponding angle in radians. 7913 7914 See Also 7915 -------- 7916 rad2deg : Convert angles from radians to degrees. 7917 unwrap : Remove large jumps in angle by wrapping. 7918 7919 Notes 7920 ----- 7921 .. versionadded:: 1.3.0 7922 7923 ``deg2rad(x)`` is ``x * pi / 180``. 7924 7925 Examples 7926 -------- 7927 >>> np.deg2rad(180) 7928 3.1415926535897931""" 7929 return ndarray() 7930 def degrees(x, out): 7931 """degrees(x[, out]) 7932 7933 Convert angles from radians to degrees. 7934 7935 Parameters 7936 ---------- 7937 x : array_like 7938 Input array in radians. 7939 out : ndarray, optional 7940 Output array of same shape as x. 7941 7942 Returns 7943 ------- 7944 y : ndarray of floats 7945 The corresponding degree values; if `out` was supplied this is a 7946 reference to it. 7947 7948 See Also 7949 -------- 7950 rad2deg : equivalent function 7951 7952 Examples 7953 -------- 7954 Convert a radian array to degrees 7955 7956 >>> rad = np.arange(12.)*np.pi/6 7957 >>> np.degrees(rad) 7958 array([ 0., 30., 60., 90., 120., 150., 180., 210., 240., 7959 270., 300., 330.]) 7960 7961 >>> out = np.zeros((rad.shape)) 7962 >>> r = degrees(rad, out) 7963 >>> np.all(r == out) 7964 True""" 7965 return ndarray() 7966 def delete(arr, obj=None, axis=None): 7967 """ 7968 Return a new array with sub-arrays along an axis deleted. For a one 7969 dimensional array, this returns those entries not returned by `arr[obj]`. 7970 7971 Parameters 7972 ---------- 7973 arr : array_like 7974 Input array. 7975 obj : slice, int or array of ints 7976 Indicate which sub-arrays to remove. 7977 axis : int, optional 7978 The axis along which to delete the subarray defined by `obj`. 7979 If `axis` is None, `obj` is applied to the flattened array. 7980 7981 Returns 7982 ------- 7983 out : ndarray 7984 A copy of `arr` with the elements specified by `obj` removed. Note 7985 that `delete` does not occur in-place. If `axis` is None, `out` is 7986 a flattened array. 7987 7988 See Also 7989 -------- 7990 insert : Insert elements into an array. 7991 append : Append elements at the end of an array. 7992 7993 Notes 7994 ----- 7995 Often it is preferable to use a boolean mask. For example: 7996 >>> mask = np.ones(len(arr), dtype=bool) 7997 >>> mask[[0,2,4]] = False 7998 >>> result = arr[mask,...] 7999 Is equivalent to `np.delete(arr, [0,2,4], axis=0)`, but allows further 8000 use of `mask`. 8001 8002 Examples 8003 -------- 8004 >>> arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]]) 8005 >>> arr 8006 array([[ 1, 2, 3, 4], 8007 [ 5, 6, 7, 8], 8008 [ 9, 10, 11, 12]]) 8009 >>> np.delete(arr, 1, 0) 8010 array([[ 1, 2, 3, 4], 8011 [ 9, 10, 11, 12]]) 8012 8013 >>> np.delete(arr, np.s_[::2], 1) 8014 array([[ 2, 4], 8015 [ 6, 8], 8016 [10, 12]]) 8017 >>> np.delete(arr, [1,3,5], None) 8018 array([ 1, 3, 5, 7, 8, 9, 10, 11, 12]) 8019 8020 """ 8021 return ndarray() 8022 def deprecate(): 8023 """ 8024 Issues a DeprecationWarning, adds warning to `old_name`'s 8025 docstring, rebinds ``old_name.__name__`` and returns the new 8026 function object. 8027 8028 This function may also be used as a decorator. 8029 8030 Parameters 8031 ---------- 8032 func : function 8033 The function to be deprecated. 8034 old_name : str, optional 8035 The name of the function to be deprecated. Default is None, in which 8036 case the name of `func` is used. 8037 new_name : str, optional 8038 The new name for the function. Default is None, in which case 8039 the deprecation message is that `old_name` is deprecated. If given, 8040 the deprecation message is that `old_name` is deprecated and `new_name` 8041 should be used instead. 8042 message : str, optional 8043 Additional explanation of the deprecation. Displayed in the docstring 8044 after the warning. 8045 8046 Returns 8047 ------- 8048 old_func : function 8049 The deprecated function. 8050 8051 Examples 8052 -------- 8053 Note that ``olduint`` returns a value after printing Deprecation Warning: 8054 8055 >>> olduint = np.deprecate(np.uint) 8056 >>> olduint(6) 8057 /usr/lib/python2.5/site-packages/numpy/lib/utils.py:114: 8058 DeprecationWarning: uint32 is deprecated 8059 warnings.warn(str1, DeprecationWarning) 8060 6 8061 8062 """ 8063 return None 8064 def _lambda(): 8065 """None""" 8066 return None 8067 def diag(v=0, k=0): 8068 """ 8069 Extract a diagonal or construct a diagonal array. 8070 8071 See the more detailed documentation for ``numpy.diagonal`` if you use this 8072 function to extract a diagonal and wish to write to the resulting array; 8073 whether it returns a copy or a view depends on what version of numpy you 8074 are using. 8075 8076 Parameters 8077 ---------- 8078 v : array_like 8079 If `v` is a 2-D array, return a copy of its `k`-th diagonal. 8080 If `v` is a 1-D array, return a 2-D array with `v` on the `k`-th 8081 diagonal. 8082 k : int, optional 8083 Diagonal in question. The default is 0. Use `k>0` for diagonals 8084 above the main diagonal, and `k<0` for diagonals below the main 8085 diagonal. 8086 8087 Returns 8088 ------- 8089 out : ndarray 8090 The extracted diagonal or constructed diagonal array. 8091 8092 See Also 8093 -------- 8094 diagonal : Return specified diagonals. 8095 diagflat : Create a 2-D array with the flattened input as a diagonal. 8096 trace : Sum along diagonals. 8097 triu : Upper triangle of an array. 8098 tril : Lower triange of an array. 8099 8100 Examples 8101 -------- 8102 >>> x = np.arange(9).reshape((3,3)) 8103 >>> x 8104 array([[0, 1, 2], 8105 [3, 4, 5], 8106 [6, 7, 8]]) 8107 8108 >>> np.diag(x) 8109 array([0, 4, 8]) 8110 >>> np.diag(x, k=1) 8111 array([1, 5]) 8112 >>> np.diag(x, k=-1) 8113 array([3, 7]) 8114 8115 >>> np.diag(np.diag(x)) 8116 array([[0, 0, 0], 8117 [0, 4, 0], 8118 [0, 0, 8]]) 8119 8120 """ 8121 return ndarray() 8122 def diag_indices(n=2, ndim=2): 8123 """ 8124 Return the indices to access the main diagonal of an array. 8125 8126 This returns a tuple of indices that can be used to access the main 8127 diagonal of an array `a` with ``a.ndim >= 2`` dimensions and shape 8128 (n, n, ..., n). For ``a.ndim = 2`` this is the usual diagonal, for 8129 ``a.ndim > 2`` this is the set of indices to access ``a[i, i, ..., i]`` 8130 for ``i = [0..n-1]``. 8131 8132 Parameters 8133 ---------- 8134 n : int 8135 The size, along each dimension, of the arrays for which the returned 8136 indices can be used. 8137 8138 ndim : int, optional 8139 The number of dimensions. 8140 8141 See also 8142 -------- 8143 diag_indices_from 8144 8145 Notes 8146 ----- 8147 .. versionadded:: 1.4.0 8148 8149 Examples 8150 -------- 8151 Create a set of indices to access the diagonal of a (4, 4) array: 8152 8153 >>> di = np.diag_indices(4) 8154 >>> di 8155 (array([0, 1, 2, 3]), array([0, 1, 2, 3])) 8156 >>> a = np.arange(16).reshape(4, 4) 8157 >>> a 8158 array([[ 0, 1, 2, 3], 8159 [ 4, 5, 6, 7], 8160 [ 8, 9, 10, 11], 8161 [12, 13, 14, 15]]) 8162 >>> a[di] = 100 8163 >>> a 8164 array([[100, 1, 2, 3], 8165 [ 4, 100, 6, 7], 8166 [ 8, 9, 100, 11], 8167 [ 12, 13, 14, 100]]) 8168 8169 Now, we create indices to manipulate a 3-D array: 8170 8171 >>> d3 = np.diag_indices(2, 3) 8172 >>> d3 8173 (array([0, 1]), array([0, 1]), array([0, 1])) 8174 8175 And use it to set the diagonal of an array of zeros to 1: 8176 8177 >>> a = np.zeros((2, 2, 2), dtype=np.int) 8178 >>> a[d3] = 1 8179 >>> a 8180 array([[[1, 0], 8181 [0, 0]], 8182 [[0, 0], 8183 [0, 1]]]) 8184 8185 """ 8186 return None 8187 def diag_indices__from(arr): 8188 """ 8189 Return the indices to access the main diagonal of an n-dimensional array. 8190 8191 See `diag_indices` for full details. 8192 8193 Parameters 8194 ---------- 8195 arr : array, at least 2-D 8196 8197 See Also 8198 -------- 8199 diag_indices 8200 8201 Notes 8202 ----- 8203 .. versionadded:: 1.4.0 8204 8205 """ 8206 return None 8207 def diagflat(v=0, k=0): 8208 """ 8209 Create a two-dimensional array with the flattened input as a diagonal. 8210 8211 Parameters 8212 ---------- 8213 v : array_like 8214 Input data, which is flattened and set as the `k`-th 8215 diagonal of the output. 8216 k : int, optional 8217 Diagonal to set; 0, the default, corresponds to the "main" diagonal, 8218 a positive (negative) `k` giving the number of the diagonal above 8219 (below) the main. 8220 8221 Returns 8222 ------- 8223 out : ndarray 8224 The 2-D output array. 8225 8226 See Also 8227 -------- 8228 diag : MATLAB work-alike for 1-D and 2-D arrays. 8229 diagonal : Return specified diagonals. 8230 trace : Sum along diagonals. 8231 8232 Examples 8233 -------- 8234 >>> np.diagflat([[1,2], [3,4]]) 8235 array([[1, 0, 0, 0], 8236 [0, 2, 0, 0], 8237 [0, 0, 3, 0], 8238 [0, 0, 0, 4]]) 8239 8240 >>> np.diagflat([1,2], 1) 8241 array([[0, 1, 0], 8242 [0, 0, 2], 8243 [0, 0, 0]]) 8244 8245 """ 8246 return ndarray() 8247 def diagonal(a=1, offset=0, axis1=0, axis2=1): 8248 """ 8249 Return specified diagonals. 8250 8251 If `a` is 2-D, returns the diagonal of `a` with the given offset, 8252 i.e., the collection of elements of the form ``a[i, i+offset]``. If 8253 `a` has more than two dimensions, then the axes specified by `axis1` 8254 and `axis2` are used to determine the 2-D sub-array whose diagonal is 8255 returned. The shape of the resulting array can be determined by 8256 removing `axis1` and `axis2` and appending an index to the right equal 8257 to the size of the resulting diagonals. 8258 8259 In versions of NumPy prior to 1.7, this function always returned a new, 8260 independent array containing a copy of the values in the diagonal. 8261 8262 In NumPy 1.7, it continues to return a copy of the diagonal, but depending 8263 on this fact is deprecated. Writing to the resulting array continues to 8264 work as it used to, but a FutureWarning will be issued. 8265 8266 In NumPy 1.9, it will switch to returning a read-only view on the original 8267 array. Attempting to write to the resulting array will produce an error. 8268 8269 In NumPy 1.10, it will still return a view, but this view will no longer be 8270 marked read-only. Writing to the returned array will alter your original 8271 array as well. 8272 8273 If you don't write to the array returned by this function, then you can 8274 just ignore all of the above. 8275 8276 If you depend on the current behavior, then we suggest copying the 8277 returned array explicitly, i.e., use ``np.diagonal(a).copy()`` instead of 8278 just ``np.diagonal(a)``. This will work with both past and future versions 8279 of NumPy. 8280 8281 Parameters 8282 ---------- 8283 a : array_like 8284 Array from which the diagonals are taken. 8285 offset : int, optional 8286 Offset of the diagonal from the main diagonal. Can be positive or 8287 negative. Defaults to main diagonal (0). 8288 axis1 : int, optional 8289 Axis to be used as the first axis of the 2-D sub-arrays from which 8290 the diagonals should be taken. Defaults to first axis (0). 8291 axis2 : int, optional 8292 Axis to be used as the second axis of the 2-D sub-arrays from 8293 which the diagonals should be taken. Defaults to second axis (1). 8294 8295 Returns 8296 ------- 8297 array_of_diagonals : ndarray 8298 If `a` is 2-D, a 1-D array containing the diagonal is returned. 8299 If the dimension of `a` is larger, then an array of diagonals is 8300 returned, "packed" from left-most dimension to right-most (e.g., 8301 if `a` is 3-D, then the diagonals are "packed" along rows). 8302 8303 Raises 8304 ------ 8305 ValueError 8306 If the dimension of `a` is less than 2. 8307 8308 See Also 8309 -------- 8310 diag : MATLAB work-a-like for 1-D and 2-D arrays. 8311 diagflat : Create diagonal arrays. 8312 trace : Sum along diagonals. 8313 8314 Examples 8315 -------- 8316 >>> a = np.arange(4).reshape(2,2) 8317 >>> a 8318 array([[0, 1], 8319 [2, 3]]) 8320 >>> a.diagonal() 8321 array([0, 3]) 8322 >>> a.diagonal(1) 8323 array([1]) 8324 8325 A 3-D example: 8326 8327 >>> a = np.arange(8).reshape(2,2,2); a 8328 array([[[0, 1], 8329 [2, 3]], 8330 [[4, 5], 8331 [6, 7]]]) 8332 >>> a.diagonal(0, # Main diagonals of two arrays created by skipping 8333 ... 0, # across the outer(left)-most axis last and 8334 ... 1) # the "middle" (row) axis first. 8335 array([[0, 6], 8336 [1, 7]]) 8337 8338 The sub-arrays whose main diagonals we just obtained; note that each 8339 corresponds to fixing the right-most (column) axis, and that the 8340 diagonals are "packed" in rows. 8341 8342 >>> a[:,:,0] # main diagonal is [0 6] 8343 array([[0, 2], 8344 [4, 6]]) 8345 >>> a[:,:,1] # main diagonal is [1 7] 8346 array([[1, 3], 8347 [5, 7]]) 8348 8349 """ 8350 return ndarray() 8351 def diff(a=-1, n=1, axis=-1): 8352 """ 8353 Calculate the n-th order discrete difference along given axis. 8354 8355 The first order difference is given by ``out[n] = a[n+1] - a[n]`` along 8356 the given axis, higher order differences are calculated by using `diff` 8357 recursively. 8358 8359 Parameters 8360 ---------- 8361 a : array_like 8362 Input array 8363 n : int, optional 8364 The number of times values are differenced. 8365 axis : int, optional 8366 The axis along which the difference is taken, default is the last axis. 8367 8368 Returns 8369 ------- 8370 diff : ndarray 8371 The `n` order differences. The shape of the output is the same as `a` 8372 except along `axis` where the dimension is smaller by `n`. 8373 8374 See Also 8375 -------- 8376 gradient, ediff1d, cumsum 8377 8378 Examples 8379 -------- 8380 >>> x = np.array([1, 2, 4, 7, 0]) 8381 >>> np.diff(x) 8382 array([ 1, 2, 3, -7]) 8383 >>> np.diff(x, n=2) 8384 array([ 1, 1, -10]) 8385 8386 >>> x = np.array([[1, 3, 6, 10], [0, 5, 6, 8]]) 8387 >>> np.diff(x) 8388 array([[2, 3, 4], 8389 [5, 1, 2]]) 8390 >>> np.diff(x, axis=0) 8391 array([[-1, 2, 0, -2]]) 8392 8393 """ 8394 return ndarray() 8395 def digitize(x, bins, right): 8396 """digitize(x, bins, right=False) 8397 8398 Return the indices of the bins to which each value in input array belongs. 8399 8400 Each index ``i`` returned is such that ``bins[i-1] <= x < bins[i]`` if 8401 `bins` is monotonically increasing, or ``bins[i-1] > x >= bins[i]`` if 8402 `bins` is monotonically decreasing. If values in `x` are beyond the 8403 bounds of `bins`, 0 or ``len(bins)`` is returned as appropriate. If right 8404 is True, then the right bin is closed so that the index ``i`` is such 8405 that ``bins[i-1] < x <= bins[i]`` or bins[i-1] >= x > bins[i]`` if `bins` 8406 is monotonically increasing or decreasing, respectively. 8407 8408 Parameters 8409 ---------- 8410 x : array_like 8411 Input array to be binned. It has to be 1-dimensional. 8412 bins : array_like 8413 Array of bins. It has to be 1-dimensional and monotonic. 8414 right : bool, optional 8415 Indicating whether the intervals include the right or the left bin 8416 edge. Default behavior is (right==False) indicating that the interval 8417 does not include the right edge. The left bin and is open in this 8418 case. Ie., bins[i-1] <= x < bins[i] is the default behavior for 8419 monotonically increasing bins. 8420 8421 Returns 8422 ------- 8423 out : ndarray of ints 8424 Output array of indices, of same shape as `x`. 8425 8426 Raises 8427 ------ 8428 ValueError 8429 If the input is not 1-dimensional, or if `bins` is not monotonic. 8430 TypeError 8431 If the type of the input is complex. 8432 8433 See Also 8434 -------- 8435 bincount, histogram, unique 8436 8437 Notes 8438 ----- 8439 If values in `x` are such that they fall outside the bin range, 8440 attempting to index `bins` with the indices that `digitize` returns 8441 will result in an IndexError. 8442 8443 Examples 8444 -------- 8445 >>> x = np.array([0.2, 6.4, 3.0, 1.6]) 8446 >>> bins = np.array([0.0, 1.0, 2.5, 4.0, 10.0]) 8447 >>> inds = np.digitize(x, bins) 8448 >>> inds 8449 array([1, 4, 3, 2]) 8450 >>> for n in range(x.size): 8451 ... print bins[inds[n]-1], "<=", x[n], "<", bins[inds[n]] 8452 ... 8453 0.0 <= 0.2 < 1.0 8454 4.0 <= 6.4 < 10.0 8455 2.5 <= 3.0 < 4.0 8456 1.0 <= 1.6 < 2.5 8457 8458 >>> x = np.array([1.2, 10.0, 12.4, 15.5, 20.]) 8459 >>> bins = np.array([0,5,10,15,20]) 8460 >>> np.digitize(x,bins,right=True) 8461 array([1, 2, 3, 4, 4]) 8462 >>> np.digitize(x,bins,right=False) 8463 array([1, 3, 3, 4, 5])""" 8464 return ndarray() 8465 def disp(mesg=True, device=None, linefeed=True): 8466 """ 8467 Display a message on a device. 8468 8469 Parameters 8470 ---------- 8471 mesg : str 8472 Message to display. 8473 device : object 8474 Device to write message. If None, defaults to ``sys.stdout`` which is 8475 very similar to ``print``. `device` needs to have ``write()`` and 8476 ``flush()`` methods. 8477 linefeed : bool, optional 8478 Option whether to print a line feed or not. Defaults to True. 8479 8480 Raises 8481 ------ 8482 AttributeError 8483 If `device` does not have a ``write()`` or ``flush()`` method. 8484 8485 Examples 8486 -------- 8487 Besides ``sys.stdout``, a file-like object can also be used as it has 8488 both required methods: 8489 8490 >>> from StringIO import StringIO 8491 >>> buf = StringIO() 8492 >>> np.disp('"Display" in a file', device=buf) 8493 >>> buf.getvalue() 8494 '"Display" in a file\n' 8495 8496 """ 8497 return None 8498 def divide(x1, x2, out): 8499 """divide(x1, x2[, out]) 8500 8501 Divide arguments element-wise. 8502 8503 Parameters 8504 ---------- 8505 x1 : array_like 8506 Dividend array. 8507 x2 : array_like 8508 Divisor array. 8509 out : ndarray, optional 8510 Array into which the output is placed. Its type is preserved and it 8511 must be of the right shape to hold the output. See doc.ufuncs. 8512 8513 Returns 8514 ------- 8515 y : {ndarray, scalar} 8516 The quotient `x1/x2`, element-wise. Returns a scalar if 8517 both `x1` and `x2` are scalars. 8518 8519 See Also 8520 -------- 8521 seterr : Set whether to raise or warn on overflow, underflow and division 8522 by zero. 8523 8524 Notes 8525 ----- 8526 Equivalent to `x1` / `x2` in terms of array-broadcasting. 8527 8528 Behavior on division by zero can be changed using `seterr`. 8529 8530 When both `x1` and `x2` are of an integer type, `divide` will return 8531 integers and throw away the fractional part. Moreover, division by zero 8532 always yields zero in integer arithmetic. 8533 8534 Examples 8535 -------- 8536 >>> np.divide(2.0, 4.0) 8537 0.5 8538 >>> x1 = np.arange(9.0).reshape((3, 3)) 8539 >>> x2 = np.arange(3.0) 8540 >>> np.divide(x1, x2) 8541 array([[ NaN, 1. , 1. ], 8542 [ Inf, 4. , 2.5], 8543 [ Inf, 7. , 4. ]]) 8544 8545 Note the behavior with integer types: 8546 8547 >>> np.divide(2, 4) 8548 0 8549 >>> np.divide(2, 4.) 8550 0.5 8551 8552 Division by zero always yields zero in integer arithmetic, and does not 8553 raise an exception or a warning: 8554 8555 >>> np.divide(np.array([0, 1], dtype=int), np.array([0, 0], dtype=int)) 8556 array([0, 0]) 8557 8558 Division by zero can, however, be caught using `seterr`: 8559 8560 >>> old_err_state = np.seterr(divide='raise') 8561 >>> np.divide(1, 0) 8562 Traceback (most recent call last): 8563 File "<stdin>", line 1, in <module> 8564 FloatingPointError: divide by zero encountered in divide 8565 8566 >>> ignored_states = np.seterr(**old_err_state) 8567 >>> np.divide(1, 0) 8568 0""" 8569 return ndarray() 8570 division = instance() 8571 def dot(a, b, out): 8572 """dot(a, b, out=None) 8573 8574 Dot product of two arrays. 8575 8576 For 2-D arrays it is equivalent to matrix multiplication, and for 1-D 8577 arrays to inner product of vectors (without complex conjugation). For 8578 N dimensions it is a sum product over the last axis of `a` and 8579 the second-to-last of `b`:: 8580 8581 dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m]) 8582 8583 Parameters 8584 ---------- 8585 a : array_like 8586 First argument. 8587 b : array_like 8588 Second argument. 8589 out : ndarray, optional 8590 Output argument. This must have the exact kind that would be returned 8591 if it was not used. In particular, it must have the right type, must be 8592 C-contiguous, and its dtype must be the dtype that would be returned 8593 for `dot(a,b)`. This is a performance feature. Therefore, if these 8594 conditions are not met, an exception is raised, instead of attempting 8595 to be flexible. 8596 8597 Returns 8598 ------- 8599 output : ndarray 8600 Returns the dot product of `a` and `b`. If `a` and `b` are both 8601 scalars or both 1-D arrays then a scalar is returned; otherwise 8602 an array is returned. 8603 If `out` is given, then it is returned. 8604 8605 Raises 8606 ------ 8607 ValueError 8608 If the last dimension of `a` is not the same size as 8609 the second-to-last dimension of `b`. 8610 8611 See Also 8612 -------- 8613 vdot : Complex-conjugating dot product. 8614 tensordot : Sum products over arbitrary axes. 8615 einsum : Einstein summation convention. 8616 8617 Examples 8618 -------- 8619 >>> np.dot(3, 4) 8620 12 8621 8622 Neither argument is complex-conjugated: 8623 8624 >>> np.dot([2j, 3j], [2j, 3j]) 8625 (-13+0j) 8626 8627 For 2-D arrays it's the matrix product: 8628 8629 >>> a = [[1, 0], [0, 1]] 8630 >>> b = [[4, 1], [2, 2]] 8631 >>> np.dot(a, b) 8632 array([[4, 1], 8633 [2, 2]]) 8634 8635 >>> a = np.arange(3*4*5*6).reshape((3,4,5,6)) 8636 >>> b = np.arange(3*4*5*6)[::-1].reshape((5,4,6,3)) 8637 >>> np.dot(a, b)[2,3,2,1,2,2] 8638 499128 8639 >>> sum(a[2,3,2,:] * b[1,2,:,2]) 8640 499128""" 8641 return ndarray() 8642 class float64: 8643 T = getset_descriptor() 8644 __array_interface__ = getset_descriptor() 8645 __array_priority__ = getset_descriptor() 8646 __array_struct__ = getset_descriptor() 8647 __doc__ = str() 8648 def as_integer_ratio(self, _): 8649 """float.as_integer_ratio() -> (int, int) 8650 8651 Return a pair of integers, whose ratio is exactly equal to the original 8652 float and with a positive denominator. 8653 Raise OverflowError on infinities and a ValueError on NaNs. 8654 8655 >>> (10.0).as_integer_ratio() 8656 (10, 1) 8657 >>> (0.0).as_integer_ratio() 8658 (0, 1) 8659 >>> (-.25).as_integer_ratio() 8660 (-1, 4)""" 8661 return None 8662 base = getset_descriptor() 8663 def conj(self, _): 8664 """None""" 8665 return None 8666 data = getset_descriptor() 8667 dtype = getset_descriptor() 8668 flags = getset_descriptor() 8669 flat = getset_descriptor() 8670 def _fromhex(self, string): 8671 """float.fromhex(string) -> float 8672 8673 Create a floating-point number from a hexadecimal string. 8674 >>> float.fromhex('0x1.ffffp10') 8675 2047.984375 8676 >>> float.fromhex('-0x1p-1074') 8677 -4.9406564584124654e-324""" 8678 return None 8679 def hex(self, _): 8680 """float.hex() -> string 8681 8682 Return a hexadecimal representation of a floating-point number. 8683 >>> (-0.1).hex() 8684 '-0x1.999999999999ap-4' 8685 >>> 3.14159.hex() 8686 '0x1.921f9f01b866ep+1'""" 8687 return None 8688 imag = getset_descriptor() 8689 def is_integer(self, _): 8690 """Return True if the float is an integer.""" 8691 return None 8692 itemsize = getset_descriptor() 8693 nbytes = getset_descriptor() 8694 ndim = getset_descriptor() 8695 def newbyteorder(self, new_order): 8696 """newbyteorder(new_order='S') 8697 8698 Return a new `dtype` with a different byte order. 8699 8700 Changes are also made in all fields and sub-arrays of the data type. 8701 8702 The `new_order` code can be any from the following: 8703 8704 * {'<', 'L'} - little endian 8705 * {'>', 'B'} - big endian 8706 * {'=', 'N'} - native order 8707 * 'S' - swap dtype from current to opposite endian 8708 * {'|', 'I'} - ignore (no change to byte order) 8709 8710 Parameters 8711 ---------- 8712 new_order : str, optional 8713 Byte order to force; a value from the byte order specifications 8714 above. The default value ('S') results in swapping the current 8715 byte order. The code does a case-insensitive check on the first 8716 letter of `new_order` for the alternatives above. For example, 8717 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 8718 8719 8720 Returns 8721 ------- 8722 new_dtype : dtype 8723 New `dtype` object with the given change to the byte order.""" 8724 return dtype() 8725 real = getset_descriptor() 8726 shape = getset_descriptor() 8727 size = getset_descriptor() 8728 strides = getset_descriptor() 8729 def dsplit(): 8730 """ 8731 Split array into multiple sub-arrays along the 3rd axis (depth). 8732 8733 Please refer to the `split` documentation. `dsplit` is equivalent 8734 to `split` with ``axis=2``, the array is always split along the third 8735 axis provided the array dimension is greater than or equal to 3. 8736 8737 See Also 8738 -------- 8739 split : Split an array into multiple sub-arrays of equal size. 8740 8741 Examples 8742 -------- 8743 >>> x = np.arange(16.0).reshape(2, 2, 4) 8744 >>> x 8745 array([[[ 0., 1., 2., 3.], 8746 [ 4., 5., 6., 7.]], 8747 [[ 8., 9., 10., 11.], 8748 [ 12., 13., 14., 15.]]]) 8749 >>> np.dsplit(x, 2) 8750 [array([[[ 0., 1.], 8751 [ 4., 5.]], 8752 [[ 8., 9.], 8753 [ 12., 13.]]]), 8754 array([[[ 2., 3.], 8755 [ 6., 7.]], 8756 [[ 10., 11.], 8757 [ 14., 15.]]])] 8758 >>> np.dsplit(x, np.array([3, 6])) 8759 [array([[[ 0., 1., 2.], 8760 [ 4., 5., 6.]], 8761 [[ 8., 9., 10.], 8762 [ 12., 13., 14.]]]), 8763 array([[[ 3.], 8764 [ 7.]], 8765 [[ 11.], 8766 [ 15.]]]), 8767 array([], dtype=float64)] 8768 8769 """ 8770 return None 8771 def dstack(tup): 8772 """ 8773 Stack arrays in sequence depth wise (along third axis). 8774 8775 Takes a sequence of arrays and stack them along the third axis 8776 to make a single array. Rebuilds arrays divided by `dsplit`. 8777 This is a simple way to stack 2D arrays (images) into a single 8778 3D array for processing. 8779 8780 Parameters 8781 ---------- 8782 tup : sequence of arrays 8783 Arrays to stack. All of them must have the same shape along all 8784 but the third axis. 8785 8786 Returns 8787 ------- 8788 stacked : ndarray 8789 The array formed by stacking the given arrays. 8790 8791 See Also 8792 -------- 8793 vstack : Stack along first axis. 8794 hstack : Stack along second axis. 8795 concatenate : Join arrays. 8796 dsplit : Split array along third axis. 8797 8798 Notes 8799 ----- 8800 Equivalent to ``np.concatenate(tup, axis=2)``. 8801 8802 Examples 8803 -------- 8804 >>> a = np.array((1,2,3)) 8805 >>> b = np.array((2,3,4)) 8806 >>> np.dstack((a,b)) 8807 array([[[1, 2], 8808 [2, 3], 8809 [3, 4]]]) 8810 8811 >>> a = np.array([[1],[2],[3]]) 8812 >>> b = np.array([[2],[3],[4]]) 8813 >>> np.dstack((a,b)) 8814 array([[[1, 2]], 8815 [[2, 3]], 8816 [[3, 4]]]) 8817 8818 """ 8819 return ndarray() 8820 class dtype: 8821 __doc__ = str() 8822 alignment = member_descriptor() 8823 base = getset_descriptor() 8824 byteorder = member_descriptor() 8825 char = member_descriptor() 8826 descr = getset_descriptor() 8827 fields = getset_descriptor() 8828 flags = member_descriptor() 8829 hasobject = getset_descriptor() 8830 isalignedstruct = getset_descriptor() 8831 isbuiltin = getset_descriptor() 8832 isnative = getset_descriptor() 8833 itemsize = member_descriptor() 8834 kind = member_descriptor() 8835 metadata = getset_descriptor() 8836 name = getset_descriptor() 8837 names = getset_descriptor() 8838 def newbyteorder(self, new_order): 8839 """newbyteorder(new_order='S') 8840 8841 Return a new dtype with a different byte order. 8842 8843 Changes are also made in all fields and sub-arrays of the data type. 8844 8845 Parameters 8846 ---------- 8847 new_order : string, optional 8848 Byte order to force; a value from the byte order 8849 specifications below. The default value ('S') results in 8850 swapping the current byte order. 8851 `new_order` codes can be any of:: 8852 8853 * 'S' - swap dtype from current to opposite endian 8854 * {'<', 'L'} - little endian 8855 * {'>', 'B'} - big endian 8856 * {'=', 'N'} - native order 8857 * {'|', 'I'} - ignore (no change to byte order) 8858 8859 The code does a case-insensitive check on the first letter of 8860 `new_order` for these alternatives. For example, any of '>' 8861 or 'B' or 'b' or 'brian' are valid to specify big-endian. 8862 8863 Returns 8864 ------- 8865 new_dtype : dtype 8866 New dtype object with the given change to the byte order. 8867 8868 Notes 8869 ----- 8870 Changes are also made in all fields and sub-arrays of the data type. 8871 8872 Examples 8873 -------- 8874 >>> import sys 8875 >>> sys_is_le = sys.byteorder == 'little' 8876 >>> native_code = sys_is_le and '<' or '>' 8877 >>> swapped_code = sys_is_le and '>' or '<' 8878 >>> native_dt = np.dtype(native_code+'i2') 8879 >>> swapped_dt = np.dtype(swapped_code+'i2') 8880 >>> native_dt.newbyteorder('S') == swapped_dt 8881 True 8882 >>> native_dt.newbyteorder() == swapped_dt 8883 True 8884 >>> native_dt == swapped_dt.newbyteorder('S') 8885 True 8886 >>> native_dt == swapped_dt.newbyteorder('=') 8887 True 8888 >>> native_dt == swapped_dt.newbyteorder('N') 8889 True 8890 >>> native_dt == native_dt.newbyteorder('|') 8891 True 8892 >>> np.dtype('<i2') == native_dt.newbyteorder('<') 8893 True 8894 >>> np.dtype('<i2') == native_dt.newbyteorder('L') 8895 True 8896 >>> np.dtype('>i2') == native_dt.newbyteorder('>') 8897 True 8898 >>> np.dtype('>i2') == native_dt.newbyteorder('B') 8899 True""" 8900 return dtype() 8901 num = member_descriptor() 8902 shape = getset_descriptor() 8903 str = getset_descriptor() 8904 subdtype = getset_descriptor() 8905 type = member_descriptor() 8906 e = float() 8907 def ediff1d(ary=None, to_end=None, to_begin=None): 8908 """ 8909 The differences between consecutive elements of an array. 8910 8911 Parameters 8912 ---------- 8913 ary : array_like 8914 If necessary, will be flattened before the differences are taken. 8915 to_end : array_like, optional 8916 Number(s) to append at the end of the returned differences. 8917 to_begin : array_like, optional 8918 Number(s) to prepend at the beginning of the returned differences. 8919 8920 Returns 8921 ------- 8922 ediff1d : ndarray 8923 The differences. Loosely, this is ``ary.flat[1:] - ary.flat[:-1]``. 8924 8925 See Also 8926 -------- 8927 diff, gradient 8928 8929 Notes 8930 ----- 8931 When applied to masked arrays, this function drops the mask information 8932 if the `to_begin` and/or `to_end` parameters are used. 8933 8934 Examples 8935 -------- 8936 >>> x = np.array([1, 2, 4, 7, 0]) 8937 >>> np.ediff1d(x) 8938 array([ 1, 2, 3, -7]) 8939 8940 >>> np.ediff1d(x, to_begin=-99, to_end=np.array([88, 99])) 8941 array([-99, 1, 2, 3, -7, 88, 99]) 8942 8943 The returned array is always 1D. 8944 8945 >>> y = [[1, 2, 4], [1, 6, 24]] 8946 >>> np.ediff1d(y) 8947 array([ 1, 2, -3, 5, 18]) 8948 8949 """ 8950 return ndarray() 8951 def einsum(subscripts, operands, out, dtype, order, casting): 8952 """einsum(subscripts, *operands, out=None, dtype=None, order='K', casting='safe') 8953 8954 Evaluates the Einstein summation convention on the operands. 8955 8956 Using the Einstein summation convention, many common multi-dimensional 8957 array operations can be represented in a simple fashion. This function 8958 provides a way compute such summations. The best way to understand this 8959 function is to try the examples below, which show how many common NumPy 8960 functions can be implemented as calls to `einsum`. 8961 8962 Parameters 8963 ---------- 8964 subscripts : str 8965 Specifies the subscripts for summation. 8966 operands : list of array_like 8967 These are the arrays for the operation. 8968 out : ndarray, optional 8969 If provided, the calculation is done into this array. 8970 dtype : data-type, optional 8971 If provided, forces the calculation to use the data type specified. 8972 Note that you may have to also give a more liberal `casting` 8973 parameter to allow the conversions. 8974 order : {'C', 'F', 'A', 'K'}, optional 8975 Controls the memory layout of the output. 'C' means it should 8976 be C contiguous. 'F' means it should be Fortran contiguous, 8977 'A' means it should be 'F' if the inputs are all 'F', 'C' otherwise. 8978 'K' means it should be as close to the layout as the inputs as 8979 is possible, including arbitrarily permuted axes. 8980 Default is 'K'. 8981 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional 8982 Controls what kind of data casting may occur. Setting this to 8983 'unsafe' is not recommended, as it can adversely affect accumulations. 8984 8985 * 'no' means the data types should not be cast at all. 8986 * 'equiv' means only byte-order changes are allowed. 8987 * 'safe' means only casts which can preserve values are allowed. 8988 * 'same_kind' means only safe casts or casts within a kind, 8989 like float64 to float32, are allowed. 8990 * 'unsafe' means any data conversions may be done. 8991 8992 Returns 8993 ------- 8994 output : ndarray 8995 The calculation based on the Einstein summation convention. 8996 8997 See Also 8998 -------- 8999 dot, inner, outer, tensordot 9000 9001 Notes 9002 ----- 9003 .. versionadded:: 1.6.0 9004 9005 The subscripts string is a comma-separated list of subscript labels, 9006 where each label refers to a dimension of the corresponding operand. 9007 Repeated subscripts labels in one operand take the diagonal. For example, 9008 ``np.einsum('ii', a)`` is equivalent to ``np.trace(a)``. 9009 9010 Whenever a label is repeated, it is summed, so ``np.einsum('i,i', a, b)`` 9011 is equivalent to ``np.inner(a,b)``. If a label appears only once, 9012 it is not summed, so ``np.einsum('i', a)`` produces a view of ``a`` 9013 with no changes. 9014 9015 The order of labels in the output is by default alphabetical. This 9016 means that ``np.einsum('ij', a)`` doesn't affect a 2D array, while 9017 ``np.einsum('ji', a)`` takes its transpose. 9018 9019 The output can be controlled by specifying output subscript labels 9020 as well. This specifies the label order, and allows summing to 9021 be disallowed or forced when desired. The call ``np.einsum('i->', a)`` 9022 is like ``np.sum(a, axis=-1)``, and ``np.einsum('ii->i', a)`` 9023 is like ``np.diag(a)``. The difference is that `einsum` does not 9024 allow broadcasting by default. 9025 9026 To enable and control broadcasting, use an ellipsis. Default 9027 NumPy-style broadcasting is done by adding an ellipsis 9028 to the left of each term, like ``np.einsum('...ii->...i', a)``. 9029 To take the trace along the first and last axes, 9030 you can do ``np.einsum('i...i', a)``, or to do a matrix-matrix 9031 product with the left-most indices instead of rightmost, you can do 9032 ``np.einsum('ij...,jk...->ik...', a, b)``. 9033 9034 When there is only one operand, no axes are summed, and no output 9035 parameter is provided, a view into the operand is returned instead 9036 of a new array. Thus, taking the diagonal as ``np.einsum('ii->i', a)`` 9037 produces a view. 9038 9039 An alternative way to provide the subscripts and operands is as 9040 ``einsum(op0, sublist0, op1, sublist1, ..., [sublistout])``. The examples 9041 below have corresponding `einsum` calls with the two parameter methods. 9042 9043 Examples 9044 -------- 9045 >>> a = np.arange(25).reshape(5,5) 9046 >>> b = np.arange(5) 9047 >>> c = np.arange(6).reshape(2,3) 9048 9049 >>> np.einsum('ii', a) 9050 60 9051 >>> np.einsum(a, [0,0]) 9052 60 9053 >>> np.trace(a) 9054 60 9055 9056 >>> np.einsum('ii->i', a) 9057 array([ 0, 6, 12, 18, 24]) 9058 >>> np.einsum(a, [0,0], [0]) 9059 array([ 0, 6, 12, 18, 24]) 9060 >>> np.diag(a) 9061 array([ 0, 6, 12, 18, 24]) 9062 9063 >>> np.einsum('ij,j', a, b) 9064 array([ 30, 80, 130, 180, 230]) 9065 >>> np.einsum(a, [0,1], b, [1]) 9066 array([ 30, 80, 130, 180, 230]) 9067 >>> np.dot(a, b) 9068 array([ 30, 80, 130, 180, 230]) 9069 9070 >>> np.einsum('ji', c) 9071 array([[0, 3], 9072 [1, 4], 9073 [2, 5]]) 9074 >>> np.einsum(c, [1,0]) 9075 array([[0, 3], 9076 [1, 4], 9077 [2, 5]]) 9078 >>> c.T 9079 array([[0, 3], 9080 [1, 4], 9081 [2, 5]]) 9082 9083 >>> np.einsum('..., ...', 3, c) 9084 array([[ 0, 3, 6], 9085 [ 9, 12, 15]]) 9086 >>> np.einsum(3, [Ellipsis], c, [Ellipsis]) 9087 array([[ 0, 3, 6], 9088 [ 9, 12, 15]]) 9089 >>> np.multiply(3, c) 9090 array([[ 0, 3, 6], 9091 [ 9, 12, 15]]) 9092 9093 >>> np.einsum('i,i', b, b) 9094 30 9095 >>> np.einsum(b, [0], b, [0]) 9096 30 9097 >>> np.inner(b,b) 9098 30 9099 9100 >>> np.einsum('i,j', np.arange(2)+1, b) 9101 array([[0, 1, 2, 3, 4], 9102 [0, 2, 4, 6, 8]]) 9103 >>> np.einsum(np.arange(2)+1, [0], b, [1]) 9104 array([[0, 1, 2, 3, 4], 9105 [0, 2, 4, 6, 8]]) 9106 >>> np.outer(np.arange(2)+1, b) 9107 array([[0, 1, 2, 3, 4], 9108 [0, 2, 4, 6, 8]]) 9109 9110 >>> np.einsum('i...->...', a) 9111 array([50, 55, 60, 65, 70]) 9112 >>> np.einsum(a, [0,Ellipsis], [Ellipsis]) 9113 array([50, 55, 60, 65, 70]) 9114 >>> np.sum(a, axis=0) 9115 array([50, 55, 60, 65, 70]) 9116 9117 >>> a = np.arange(60.).reshape(3,4,5) 9118 >>> b = np.arange(24.).reshape(4,3,2) 9119 >>> np.einsum('ijk,jil->kl', a, b) 9120 array([[ 4400., 4730.], 9121 [ 4532., 4874.], 9122 [ 4664., 5018.], 9123 [ 4796., 5162.], 9124 [ 4928., 5306.]]) 9125 >>> np.einsum(a, [0,1,2], b, [1,0,3], [2,3]) 9126 array([[ 4400., 4730.], 9127 [ 4532., 4874.], 9128 [ 4664., 5018.], 9129 [ 4796., 5162.], 9130 [ 4928., 5306.]]) 9131 >>> np.tensordot(a,b, axes=([1,0],[0,1])) 9132 array([[ 4400., 4730.], 9133 [ 4532., 4874.], 9134 [ 4664., 5018.], 9135 [ 4796., 5162.], 9136 [ 4928., 5306.]])""" 9137 return ndarray() 9138 def empty(shape, dtype, order): 9139 """empty(shape, dtype=float, order='C') 9140 9141 Return a new array of given shape and type, without initializing entries. 9142 9143 Parameters 9144 ---------- 9145 shape : int or tuple of int 9146 Shape of the empty array 9147 dtype : data-type, optional 9148 Desired output data-type. 9149 order : {'C', 'F'}, optional 9150 Whether to store multi-dimensional data in C (row-major) or 9151 Fortran (column-major) order in memory. 9152 9153 See Also 9154 -------- 9155 empty_like, zeros, ones 9156 9157 Notes 9158 ----- 9159 `empty`, unlike `zeros`, does not set the array values to zero, 9160 and may therefore be marginally faster. On the other hand, it requires 9161 the user to manually set all the values in the array, and should be 9162 used with caution. 9163 9164 Examples 9165 -------- 9166 >>> np.empty([2, 2]) 9167 array([[ -9.74499359e+001, 6.69583040e-309], 9168 [ 2.13182611e-314, 3.06959433e-309]]) #random 9169 9170 >>> np.empty([2, 2], dtype=int) 9171 array([[-1073741821, -1067949133], 9172 [ 496041986, 19249760]]) #random""" 9173 return None 9174 def empty_like(a, dtype, order, subok): 9175 """empty_like(a, dtype=None, order='K', subok=True) 9176 9177 Return a new array with the same shape and type as a given array. 9178 9179 Parameters 9180 ---------- 9181 a : array_like 9182 The shape and data-type of `a` define these same attributes of the 9183 returned array. 9184 dtype : data-type, optional 9185 .. versionadded:: 1.6.0 9186 Overrides the data type of the result. 9187 order : {'C', 'F', 'A', or 'K'}, optional 9188 .. versionadded:: 1.6.0 9189 Overrides the memory layout of the result. 'C' means C-order, 9190 'F' means F-order, 'A' means 'F' if ``a`` is Fortran contiguous, 9191 'C' otherwise. 'K' means match the layout of ``a`` as closely 9192 as possible. 9193 subok : bool, optional. 9194 If True, then the newly created array will use the sub-class 9195 type of 'a', otherwise it will be a base-class array. Defaults 9196 to True. 9197 9198 Returns 9199 ------- 9200 out : ndarray 9201 Array of uninitialized (arbitrary) data with the same 9202 shape and type as `a`. 9203 9204 See Also 9205 -------- 9206 ones_like : Return an array of ones with shape and type of input. 9207 zeros_like : Return an array of zeros with shape and type of input. 9208 empty : Return a new uninitialized array. 9209 ones : Return a new array setting values to one. 9210 zeros : Return a new array setting values to zero. 9211 9212 Notes 9213 ----- 9214 This function does *not* initialize the returned array; to do that use 9215 `zeros_like` or `ones_like` instead. It may be marginally faster than 9216 the functions that do set the array values. 9217 9218 Examples 9219 -------- 9220 >>> a = ([1,2,3], [4,5,6]) # a is array-like 9221 >>> np.empty_like(a) 9222 array([[-1073741821, -1073741821, 3], #random 9223 [ 0, 0, -1073741821]]) 9224 >>> a = np.array([[1., 2., 3.],[4.,5.,6.]]) 9225 >>> np.empty_like(a) 9226 array([[ -2.00000715e+000, 1.48219694e-323, -2.00000572e+000],#random 9227 [ 4.38791518e-305, -2.00000715e+000, 4.17269252e-309]])""" 9228 return ndarray() 9229 def equal(x1, x2, out=None): 9230 """equal(x1, x2[, out]) 9231 9232 Return (x1 == x2) element-wise. 9233 9234 Parameters 9235 ---------- 9236 x1, x2 : array_like 9237 Input arrays of the same shape. 9238 9239 Returns 9240 ------- 9241 out : {ndarray, bool} 9242 Output array of bools, or a single bool if x1 and x2 are scalars. 9243 9244 See Also 9245 -------- 9246 not_equal, greater_equal, less_equal, greater, less 9247 9248 Examples 9249 -------- 9250 >>> np.equal([0, 1, 3], np.arange(3)) 9251 array([ True, True, False], dtype=bool) 9252 9253 What is compared are values, not types. So an int (1) and an array of 9254 length one can evaluate as True: 9255 9256 >>> np.equal(1, np.ones(1)) 9257 array([ True], dtype=bool)""" 9258 return ndarray() 9259 class errstate: 9260 __dict__ = dictproxy() 9261 __doc__ = str() 9262 __module__ = str() 9263 __weakref__ = getset_descriptor() 9264 euler_gamma = float() 9265 def exp(x, out=None): 9266 """exp(x[, out]) 9267 9268 Calculate the exponential of all elements in the input array. 9269 9270 Parameters 9271 ---------- 9272 x : array_like 9273 Input values. 9274 9275 Returns 9276 ------- 9277 out : ndarray 9278 Output array, element-wise exponential of `x`. 9279 9280 See Also 9281 -------- 9282 expm1 : Calculate ``exp(x) - 1`` for all elements in the array. 9283 exp2 : Calculate ``2**x`` for all elements in the array. 9284 9285 Notes 9286 ----- 9287 The irrational number ``e`` is also known as Euler's number. It is 9288 approximately 2.718281, and is the base of the natural logarithm, 9289 ``ln`` (this means that, if :math:`x = \ln y = \log_e y`, 9290 then :math:`e^x = y`. For real input, ``exp(x)`` is always positive. 9291 9292 For complex arguments, ``x = a + ib``, we can write 9293 :math:`e^x = e^a e^{ib}`. The first term, :math:`e^a`, is already 9294 known (it is the real argument, described above). The second term, 9295 :math:`e^{ib}`, is :math:`\cos b + i \sin b`, a function with magnitude 9296 1 and a periodic phase. 9297 9298 References 9299 ---------- 9300 .. [1] Wikipedia, "Exponential function", 9301 http://en.wikipedia.org/wiki/Exponential_function 9302 .. [2] M. Abramovitz and I. A. Stegun, "Handbook of Mathematical Functions 9303 with Formulas, Graphs, and Mathematical Tables," Dover, 1964, p. 69, 9304 http://www.math.sfu.ca/~cbm/aands/page_69.htm 9305 9306 Examples 9307 -------- 9308 Plot the magnitude and phase of ``exp(x)`` in the complex plane: 9309 9310 >>> import matplotlib.pyplot as plt 9311 9312 >>> x = np.linspace(-2*np.pi, 2*np.pi, 100) 9313 >>> xx = x + 1j * x[:, np.newaxis] # a + ib over complex plane 9314 >>> out = np.exp(xx) 9315 9316 >>> plt.subplot(121) 9317 >>> plt.imshow(np.abs(out), 9318 ... extent=[-2*np.pi, 2*np.pi, -2*np.pi, 2*np.pi]) 9319 >>> plt.title('Magnitude of exp(x)') 9320 9321 >>> plt.subplot(122) 9322 >>> plt.imshow(np.angle(out), 9323 ... extent=[-2*np.pi, 2*np.pi, -2*np.pi, 2*np.pi]) 9324 >>> plt.title('Phase (angle) of exp(x)') 9325 >>> plt.show()""" 9326 return ndarray() 9327 def exp2(x, out): 9328 """exp2(x[, out]) 9329 9330 Calculate `2**p` for all `p` in the input array. 9331 9332 Parameters 9333 ---------- 9334 x : array_like 9335 Input values. 9336 9337 out : ndarray, optional 9338 Array to insert results into. 9339 9340 Returns 9341 ------- 9342 out : ndarray 9343 Element-wise 2 to the power `x`. 9344 9345 See Also 9346 -------- 9347 power 9348 9349 Notes 9350 ----- 9351 .. versionadded:: 1.3.0 9352 9353 9354 9355 Examples 9356 -------- 9357 >>> np.exp2([2, 3]) 9358 array([ 4., 8.])""" 9359 return ndarray() 9360 def expand_dims(a, axis): 9361 """ 9362 Expand the shape of an array. 9363 9364 Insert a new axis, corresponding to a given position in the array shape. 9365 9366 Parameters 9367 ---------- 9368 a : array_like 9369 Input array. 9370 axis : int 9371 Position (amongst axes) where new axis is to be inserted. 9372 9373 Returns 9374 ------- 9375 res : ndarray 9376 Output array. The number of dimensions is one greater than that of 9377 the input array. 9378 9379 See Also 9380 -------- 9381 doc.indexing, atleast_1d, atleast_2d, atleast_3d 9382 9383 Examples 9384 -------- 9385 >>> x = np.array([1,2]) 9386 >>> x.shape 9387 (2,) 9388 9389 The following is equivalent to ``x[np.newaxis,:]`` or ``x[np.newaxis]``: 9390 9391 >>> y = np.expand_dims(x, axis=0) 9392 >>> y 9393 array([[1, 2]]) 9394 >>> y.shape 9395 (1, 2) 9396 9397 >>> y = np.expand_dims(x, axis=1) # Equivalent to x[:,newaxis] 9398 >>> y 9399 array([[1], 9400 [2]]) 9401 >>> y.shape 9402 (2, 1) 9403 9404 Note that some examples may use ``None`` instead of ``np.newaxis``. These 9405 are the same objects: 9406 9407 >>> np.newaxis is None 9408 True 9409 9410 """ 9411 return ndarray() 9412 def expm1(x, out=None): 9413 """expm1(x[, out]) 9414 9415 Calculate ``exp(x) - 1`` for all elements in the array. 9416 9417 Parameters 9418 ---------- 9419 x : array_like 9420 Input values. 9421 9422 Returns 9423 ------- 9424 out : ndarray 9425 Element-wise exponential minus one: ``out = exp(x) - 1``. 9426 9427 See Also 9428 -------- 9429 log1p : ``log(1 + x)``, the inverse of expm1. 9430 9431 9432 Notes 9433 ----- 9434 This function provides greater precision than the formula ``exp(x) - 1`` 9435 for small values of ``x``. 9436 9437 Examples 9438 -------- 9439 The true value of ``exp(1e-10) - 1`` is ``1.00000000005e-10`` to 9440 about 32 significant digits. This example shows the superiority of 9441 expm1 in this case. 9442 9443 >>> np.expm1(1e-10) 9444 1.00000000005e-10 9445 >>> np.exp(1e-10) - 1 9446 1.000000082740371e-10""" 9447 return ndarray() 9448 def extract(condition, arr): 9449 """ 9450 Return the elements of an array that satisfy some condition. 9451 9452 This is equivalent to ``np.compress(ravel(condition), ravel(arr))``. If 9453 `condition` is boolean ``np.extract`` is equivalent to ``arr[condition]``. 9454 9455 Parameters 9456 ---------- 9457 condition : array_like 9458 An array whose nonzero or True entries indicate the elements of `arr` 9459 to extract. 9460 arr : array_like 9461 Input array of the same size as `condition`. 9462 9463 Returns 9464 ------- 9465 extract : ndarray 9466 Rank 1 array of values from `arr` where `condition` is True. 9467 9468 See Also 9469 -------- 9470 take, put, copyto, compress 9471 9472 Examples 9473 -------- 9474 >>> arr = np.arange(12).reshape((3, 4)) 9475 >>> arr 9476 array([[ 0, 1, 2, 3], 9477 [ 4, 5, 6, 7], 9478 [ 8, 9, 10, 11]]) 9479 >>> condition = np.mod(arr, 3)==0 9480 >>> condition 9481 array([[ True, False, False, True], 9482 [False, False, True, False], 9483 [False, True, False, False]], dtype=bool) 9484 >>> np.extract(condition, arr) 9485 array([0, 3, 6, 9]) 9486 9487 9488 If `condition` is boolean: 9489 9490 >>> arr[condition] 9491 array([0, 3, 6, 9]) 9492 9493 """ 9494 return ndarray() 9495 def eye(N=typefloat(), M=None, k=0, dtype=typefloat()): 9496 """ 9497 Return a 2-D array with ones on the diagonal and zeros elsewhere. 9498 9499 Parameters 9500 ---------- 9501 N : int 9502 Number of rows in the output. 9503 M : int, optional 9504 Number of columns in the output. If None, defaults to `N`. 9505 k : int, optional 9506 Index of the diagonal: 0 (the default) refers to the main diagonal, 9507 a positive value refers to an upper diagonal, and a negative value 9508 to a lower diagonal. 9509 dtype : data-type, optional 9510 Data-type of the returned array. 9511 9512 Returns 9513 ------- 9514 I : ndarray of shape (N,M) 9515 An array where all elements are equal to zero, except for the `k`-th 9516 diagonal, whose values are equal to one. 9517 9518 See Also 9519 -------- 9520 identity : (almost) equivalent function 9521 diag : diagonal 2-D array from a 1-D array specified by the user. 9522 9523 Examples 9524 -------- 9525 >>> np.eye(2, dtype=int) 9526 array([[1, 0], 9527 [0, 1]]) 9528 >>> np.eye(3, k=1) 9529 array([[ 0., 1., 0.], 9530 [ 0., 0., 1.], 9531 [ 0., 0., 0.]]) 9532 9533 """ 9534 return ndarray() 9535 def fabs(x, out): 9536 """fabs(x[, out]) 9537 9538 Compute the absolute values elementwise. 9539 9540 This function returns the absolute values (positive magnitude) of the data 9541 in `x`. Complex values are not handled, use `absolute` to find the 9542 absolute values of complex data. 9543 9544 Parameters 9545 ---------- 9546 x : array_like 9547 The array of numbers for which the absolute values are required. If 9548 `x` is a scalar, the result `y` will also be a scalar. 9549 out : ndarray, optional 9550 Array into which the output is placed. Its type is preserved and it 9551 must be of the right shape to hold the output. See doc.ufuncs. 9552 9553 Returns 9554 ------- 9555 y : {ndarray, scalar} 9556 The absolute values of `x`, the returned values are always floats. 9557 9558 See Also 9559 -------- 9560 absolute : Absolute values including `complex` types. 9561 9562 Examples 9563 -------- 9564 >>> np.fabs(-1) 9565 1.0 9566 >>> np.fabs([-1.2, 1.2]) 9567 array([ 1.2, 1.2])""" 9568 return ndarray() 9569 def _fastCopyAndTranspose(a): 9570 """_fastCopyAndTranspose(a)""" 9571 return None 9572 def fill_diagonal(a, val=False, wrap=False): 9573 """Fill the main diagonal of the given array of any dimensionality. 9574 9575 For an array `a` with ``a.ndim > 2``, the diagonal is the list of 9576 locations with indices ``a[i, i, ..., i]`` all identical. This function 9577 modifies the input array in-place, it does not return a value. 9578 9579 Parameters 9580 ---------- 9581 a : array, at least 2-D. 9582 Array whose diagonal is to be filled, it gets modified in-place. 9583 9584 val : scalar 9585 Value to be written on the diagonal, its type must be compatible with 9586 that of the array a. 9587 9588 wrap : bool 9589 For tall matrices in NumPy version up to 1.6.2, the 9590 diagonal "wrapped" after N columns. You can have this behavior 9591 with this option. This affect only tall matrices. 9592 9593 See also 9594 -------- 9595 diag_indices, diag_indices_from 9596 9597 Notes 9598 ----- 9599 .. versionadded:: 1.4.0 9600 9601 This functionality can be obtained via `diag_indices`, but internally 9602 this version uses a much faster implementation that never constructs the 9603 indices and uses simple slicing. 9604 9605 Examples 9606 -------- 9607 >>> a = np.zeros((3, 3), int) 9608 >>> np.fill_diagonal(a, 5) 9609 >>> a 9610 array([[5, 0, 0], 9611 [0, 5, 0], 9612 [0, 0, 5]]) 9613 9614 The same function can operate on a 4-D array: 9615 9616 >>> a = np.zeros((3, 3, 3, 3), int) 9617 >>> np.fill_diagonal(a, 4) 9618 9619 We only show a few blocks for clarity: 9620 9621 >>> a[0, 0] 9622 array([[4, 0, 0], 9623 [0, 0, 0], 9624 [0, 0, 0]]) 9625 >>> a[1, 1] 9626 array([[0, 0, 0], 9627 [0, 4, 0], 9628 [0, 0, 0]]) 9629 >>> a[2, 2] 9630 array([[0, 0, 0], 9631 [0, 0, 0], 9632 [0, 0, 4]]) 9633 9634 # tall matrices no wrap 9635 >>> a = np.zeros((5, 3),int) 9636 >>> fill_diagonal(a, 4) 9637 array([[4, 0, 0], 9638 [0, 4, 0], 9639 [0, 0, 4], 9640 [0, 0, 0], 9641 [0, 0, 0]]) 9642 9643 # tall matrices wrap 9644 >>> a = np.zeros((5, 3),int) 9645 >>> fill_diagonal(a, 4) 9646 array([[4, 0, 0], 9647 [0, 4, 0], 9648 [0, 0, 4], 9649 [0, 0, 0], 9650 [4, 0, 0]]) 9651 9652 # wide matrices 9653 >>> a = np.zeros((3, 5),int) 9654 >>> fill_diagonal(a, 4) 9655 array([[4, 0, 0, 0, 0], 9656 [0, 4, 0, 0, 0], 9657 [0, 0, 4, 0, 0]]) 9658 9659 """ 9660 return None 9661 def find_common_type(array_types, scalar_types): 9662 """ 9663 Determine common type following standard coercion rules. 9664 9665 Parameters 9666 ---------- 9667 array_types : sequence 9668 A list of dtypes or dtype convertible objects representing arrays. 9669 scalar_types : sequence 9670 A list of dtypes or dtype convertible objects representing scalars. 9671 9672 Returns 9673 ------- 9674 datatype : dtype 9675 The common data type, which is the maximum of `array_types` ignoring 9676 `scalar_types`, unless the maximum of `scalar_types` is of a 9677 different kind (`dtype.kind`). If the kind is not understood, then 9678 None is returned. 9679 9680 See Also 9681 -------- 9682 dtype, common_type, can_cast, mintypecode 9683 9684 Examples 9685 -------- 9686 >>> np.find_common_type([], [np.int64, np.float32, np.complex]) 9687 dtype('complex128') 9688 >>> np.find_common_type([np.int64, np.float32], []) 9689 dtype('float64') 9690 9691 The standard casting rules ensure that a scalar cannot up-cast an 9692 array unless the scalar is of a fundamentally different kind of data 9693 (i.e. under a different hierarchy in the data type hierarchy) then 9694 the array: 9695 9696 >>> np.find_common_type([np.float32], [np.int64, np.float64]) 9697 dtype('float32') 9698 9699 Complex is of a different type, so it up-casts the float in the 9700 `array_types` argument: 9701 9702 >>> np.find_common_type([np.float32], [np.complex]) 9703 dtype('complex128') 9704 9705 Type specifier strings are convertible to dtypes and can therefore 9706 be used instead of dtypes: 9707 9708 >>> np.find_common_type(['f4', 'f4', 'i4'], ['c8']) 9709 dtype('complex128') 9710 9711 """ 9712 return dtype() 9713 class finfo: 9714 __dict__ = dictproxy() 9715 __doc__ = str() 9716 __module__ = str() 9717 __weakref__ = getset_descriptor() 9718 _finfo_cache = dict() 9719 def _init(self, _): 9720 """None""" 9721 return None 9722 def fix(x=None, y=None): 9723 """ 9724 Round to nearest integer towards zero. 9725 9726 Round an array of floats element-wise to nearest integer towards zero. 9727 The rounded values are returned as floats. 9728 9729 Parameters 9730 ---------- 9731 x : array_like 9732 An array of floats to be rounded 9733 y : ndarray, optional 9734 Output array 9735 9736 Returns 9737 ------- 9738 out : ndarray of floats 9739 The array of rounded numbers 9740 9741 See Also 9742 -------- 9743 trunc, floor, ceil 9744 around : Round to given number of decimals 9745 9746 Examples 9747 -------- 9748 >>> np.fix(3.14) 9749 3.0 9750 >>> np.fix(3) 9751 3.0 9752 >>> np.fix([2.1, 2.9, -2.1, -2.9]) 9753 array([ 2., 2., -2., -2.]) 9754 9755 """ 9756 return ndarray() 9757 class flatiter: 9758 __doc__ = str() 9759 base = member_descriptor() 9760 coords = getset_descriptor() 9761 def copy(self, _): 9762 """copy() 9763 9764 Get a copy of the iterator as a 1-D array. 9765 9766 Examples 9767 -------- 9768 >>> x = np.arange(6).reshape(2, 3) 9769 >>> x 9770 array([[0, 1, 2], 9771 [3, 4, 5]]) 9772 >>> fl = x.flat 9773 >>> fl.copy() 9774 array([0, 1, 2, 3, 4, 5])""" 9775 return None 9776 index = member_descriptor() 9777 def next(self, _): 9778 """x.next() -> the next value, or raise StopIteration""" 9779 return None 9780 def flatnonzero(a): 9781 """ 9782 Return indices that are non-zero in the flattened version of a. 9783 9784 This is equivalent to a.ravel().nonzero()[0]. 9785 9786 Parameters 9787 ---------- 9788 a : ndarray 9789 Input array. 9790 9791 Returns 9792 ------- 9793 res : ndarray 9794 Output array, containing the indices of the elements of `a.ravel()` 9795 that are non-zero. 9796 9797 See Also 9798 -------- 9799 nonzero : Return the indices of the non-zero elements of the input array. 9800 ravel : Return a 1-D array containing the elements of the input array. 9801 9802 Examples 9803 -------- 9804 >>> x = np.arange(-2, 3) 9805 >>> x 9806 array([-2, -1, 0, 1, 2]) 9807 >>> np.flatnonzero(x) 9808 array([0, 1, 3, 4]) 9809 9810 Use the indices of the non-zero elements as an index array to extract 9811 these elements: 9812 9813 >>> x.ravel()[np.flatnonzero(x)] 9814 array([-2, -1, 1, 2]) 9815 9816 """ 9817 return ndarray() 9818 class flexible: 9819 T = getset_descriptor() 9820 __array_interface__ = getset_descriptor() 9821 __array_priority__ = getset_descriptor() 9822 __array_struct__ = getset_descriptor() 9823 __doc__ = None 9824 base = getset_descriptor() 9825 def conj(self, _): 9826 """None""" 9827 return None 9828 data = getset_descriptor() 9829 dtype = getset_descriptor() 9830 flags = getset_descriptor() 9831 flat = getset_descriptor() 9832 imag = getset_descriptor() 9833 itemsize = getset_descriptor() 9834 nbytes = getset_descriptor() 9835 ndim = getset_descriptor() 9836 def newbyteorder(self, new_order): 9837 """newbyteorder(new_order='S') 9838 9839 Return a new `dtype` with a different byte order. 9840 9841 Changes are also made in all fields and sub-arrays of the data type. 9842 9843 The `new_order` code can be any from the following: 9844 9845 * {'<', 'L'} - little endian 9846 * {'>', 'B'} - big endian 9847 * {'=', 'N'} - native order 9848 * 'S' - swap dtype from current to opposite endian 9849 * {'|', 'I'} - ignore (no change to byte order) 9850 9851 Parameters 9852 ---------- 9853 new_order : str, optional 9854 Byte order to force; a value from the byte order specifications 9855 above. The default value ('S') results in swapping the current 9856 byte order. The code does a case-insensitive check on the first 9857 letter of `new_order` for the alternatives above. For example, 9858 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 9859 9860 9861 Returns 9862 ------- 9863 new_dtype : dtype 9864 New `dtype` object with the given change to the byte order.""" 9865 return dtype() 9866 real = getset_descriptor() 9867 shape = getset_descriptor() 9868 size = getset_descriptor() 9869 strides = getset_descriptor() 9870 def fliplr(m): 9871 """ 9872 Flip array in the left/right direction. 9873 9874 Flip the entries in each row in the left/right direction. 9875 Columns are preserved, but appear in a different order than before. 9876 9877 Parameters 9878 ---------- 9879 m : array_like 9880 Input array. 9881 9882 Returns 9883 ------- 9884 f : ndarray 9885 A view of `m` with the columns reversed. Since a view 9886 is returned, this operation is :math:`\mathcal O(1)`. 9887 9888 See Also 9889 -------- 9890 flipud : Flip array in the up/down direction. 9891 rot90 : Rotate array counterclockwise. 9892 9893 Notes 9894 ----- 9895 Equivalent to A[:,::-1]. Does not require the array to be 9896 two-dimensional. 9897 9898 Examples 9899 -------- 9900 >>> A = np.diag([1.,2.,3.]) 9901 >>> A 9902 array([[ 1., 0., 0.], 9903 [ 0., 2., 0.], 9904 [ 0., 0., 3.]]) 9905 >>> np.fliplr(A) 9906 array([[ 0., 0., 1.], 9907 [ 0., 2., 0.], 9908 [ 3., 0., 0.]]) 9909 9910 >>> A = np.random.randn(2,3,5) 9911 >>> np.all(np.fliplr(A)==A[:,::-1,...]) 9912 True 9913 9914 """ 9915 return ndarray() 9916 def flipud(m): 9917 """ 9918 Flip array in the up/down direction. 9919 9920 Flip the entries in each column in the up/down direction. 9921 Rows are preserved, but appear in a different order than before. 9922 9923 Parameters 9924 ---------- 9925 m : array_like 9926 Input array. 9927 9928 Returns 9929 ------- 9930 out : array_like 9931 A view of `m` with the rows reversed. Since a view is 9932 returned, this operation is :math:`\mathcal O(1)`. 9933 9934 See Also 9935 -------- 9936 fliplr : Flip array in the left/right direction. 9937 rot90 : Rotate array counterclockwise. 9938 9939 Notes 9940 ----- 9941 Equivalent to ``A[::-1,...]``. 9942 Does not require the array to be two-dimensional. 9943 9944 Examples 9945 -------- 9946 >>> A = np.diag([1.0, 2, 3]) 9947 >>> A 9948 array([[ 1., 0., 0.], 9949 [ 0., 2., 0.], 9950 [ 0., 0., 3.]]) 9951 >>> np.flipud(A) 9952 array([[ 0., 0., 3.], 9953 [ 0., 2., 0.], 9954 [ 1., 0., 0.]]) 9955 9956 >>> A = np.random.randn(2,3,5) 9957 >>> np.all(np.flipud(A)==A[::-1,...]) 9958 True 9959 9960 >>> np.flipud([1,2]) 9961 array([2, 1]) 9962 9963 """ 9964 return ndarray() 9965 class float: 9966 __doc__ = str() 9967 def as_integer_ratio(self, _): 9968 """float.as_integer_ratio() -> (int, int) 9969 9970 Return a pair of integers, whose ratio is exactly equal to the original 9971 float and with a positive denominator. 9972 Raise OverflowError on infinities and a ValueError on NaNs. 9973 9974 >>> (10.0).as_integer_ratio() 9975 (10, 1) 9976 >>> (0.0).as_integer_ratio() 9977 (0, 1) 9978 >>> (-.25).as_integer_ratio() 9979 (-1, 4)""" 9980 return None 9981 def conjugate(self, _): 9982 """Return self, the complex conjugate of any float.""" 9983 return None 9984 def _fromhex(self, string): 9985 """float.fromhex(string) -> float 9986 9987 Create a floating-point number from a hexadecimal string. 9988 >>> float.fromhex('0x1.ffffp10') 9989 2047.984375 9990 >>> float.fromhex('-0x1p-1074') 9991 -4.9406564584124654e-324""" 9992 return None 9993 def hex(self, _): 9994 """float.hex() -> string 9995 9996 Return a hexadecimal representation of a floating-point number. 9997 >>> (-0.1).hex() 9998 '-0x1.999999999999ap-4' 9999 >>> 3.14159.hex() 10000 '0x1.921f9f01b866ep+1'""" 10001 return None 10002 imag = getset_descriptor() 10003 def is_integer(self, _): 10004 """Return True if the float is an integer.""" 10005 return None 10006 real = getset_descriptor() 10007 class float128: 10008 T = getset_descriptor() 10009 __array_interface__ = getset_descriptor() 10010 __array_priority__ = getset_descriptor() 10011 __array_struct__ = getset_descriptor() 10012 __doc__ = str() 10013 base = getset_descriptor() 10014 def conj(self, _): 10015 """None""" 10016 return None 10017 data = getset_descriptor() 10018 dtype = getset_descriptor() 10019 flags = getset_descriptor() 10020 flat = getset_descriptor() 10021 imag = getset_descriptor() 10022 itemsize = getset_descriptor() 10023 nbytes = getset_descriptor() 10024 ndim = getset_descriptor() 10025 def newbyteorder(self, new_order): 10026 """newbyteorder(new_order='S') 10027 10028 Return a new `dtype` with a different byte order. 10029 10030 Changes are also made in all fields and sub-arrays of the data type. 10031 10032 The `new_order` code can be any from the following: 10033 10034 * {'<', 'L'} - little endian 10035 * {'>', 'B'} - big endian 10036 * {'=', 'N'} - native order 10037 * 'S' - swap dtype from current to opposite endian 10038 * {'|', 'I'} - ignore (no change to byte order) 10039 10040 Parameters 10041 ---------- 10042 new_order : str, optional 10043 Byte order to force; a value from the byte order specifications 10044 above. The default value ('S') results in swapping the current 10045 byte order. The code does a case-insensitive check on the first 10046 letter of `new_order` for the alternatives above. For example, 10047 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 10048 10049 10050 Returns 10051 ------- 10052 new_dtype : dtype 10053 New `dtype` object with the given change to the byte order.""" 10054 return dtype() 10055 real = getset_descriptor() 10056 shape = getset_descriptor() 10057 size = getset_descriptor() 10058 strides = getset_descriptor() 10059 class float16: 10060 T = getset_descriptor() 10061 __array_interface__ = getset_descriptor() 10062 __array_priority__ = getset_descriptor() 10063 __array_struct__ = getset_descriptor() 10064 __doc__ = None 10065 base = getset_descriptor() 10066 def conj(self, _): 10067 """None""" 10068 return None 10069 data = getset_descriptor() 10070 dtype = getset_descriptor() 10071 flags = getset_descriptor() 10072 flat = getset_descriptor() 10073 imag = getset_descriptor() 10074 itemsize = getset_descriptor() 10075 nbytes = getset_descriptor() 10076 ndim = getset_descriptor() 10077 def newbyteorder(self, new_order): 10078 """newbyteorder(new_order='S') 10079 10080 Return a new `dtype` with a different byte order. 10081 10082 Changes are also made in all fields and sub-arrays of the data type. 10083 10084 The `new_order` code can be any from the following: 10085 10086 * {'<', 'L'} - little endian 10087 * {'>', 'B'} - big endian 10088 * {'=', 'N'} - native order 10089 * 'S' - swap dtype from current to opposite endian 10090 * {'|', 'I'} - ignore (no change to byte order) 10091 10092 Parameters 10093 ---------- 10094 new_order : str, optional 10095 Byte order to force; a value from the byte order specifications 10096 above. The default value ('S') results in swapping the current 10097 byte order. The code does a case-insensitive check on the first 10098 letter of `new_order` for the alternatives above. For example, 10099 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 10100 10101 10102 Returns 10103 ------- 10104 new_dtype : dtype 10105 New `dtype` object with the given change to the byte order.""" 10106 return dtype() 10107 real = getset_descriptor() 10108 shape = getset_descriptor() 10109 size = getset_descriptor() 10110 strides = getset_descriptor() 10111 class float32: 10112 T = getset_descriptor() 10113 __array_interface__ = getset_descriptor() 10114 __array_priority__ = getset_descriptor() 10115 __array_struct__ = getset_descriptor() 10116 __doc__ = str() 10117 base = getset_descriptor() 10118 def conj(self, _): 10119 """None""" 10120 return None 10121 data = getset_descriptor() 10122 dtype = getset_descriptor() 10123 flags = getset_descriptor() 10124 flat = getset_descriptor() 10125 imag = getset_descriptor() 10126 itemsize = getset_descriptor() 10127 nbytes = getset_descriptor() 10128 ndim = getset_descriptor() 10129 def newbyteorder(self, new_order): 10130 """newbyteorder(new_order='S') 10131 10132 Return a new `dtype` with a different byte order. 10133 10134 Changes are also made in all fields and sub-arrays of the data type. 10135 10136 The `new_order` code can be any from the following: 10137 10138 * {'<', 'L'} - little endian 10139 * {'>', 'B'} - big endian 10140 * {'=', 'N'} - native order 10141 * 'S' - swap dtype from current to opposite endian 10142 * {'|', 'I'} - ignore (no change to byte order) 10143 10144 Parameters 10145 ---------- 10146 new_order : str, optional 10147 Byte order to force; a value from the byte order specifications 10148 above. The default value ('S') results in swapping the current 10149 byte order. The code does a case-insensitive check on the first 10150 letter of `new_order` for the alternatives above. For example, 10151 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 10152 10153 10154 Returns 10155 ------- 10156 new_dtype : dtype 10157 New `dtype` object with the given change to the byte order.""" 10158 return dtype() 10159 real = getset_descriptor() 10160 shape = getset_descriptor() 10161 size = getset_descriptor() 10162 strides = getset_descriptor() 10163 class float64: 10164 T = getset_descriptor() 10165 __array_interface__ = getset_descriptor() 10166 __array_priority__ = getset_descriptor() 10167 __array_struct__ = getset_descriptor() 10168 __doc__ = str() 10169 def as_integer_ratio(self, _): 10170 """float.as_integer_ratio() -> (int, int) 10171 10172 Return a pair of integers, whose ratio is exactly equal to the original 10173 float and with a positive denominator. 10174 Raise OverflowError on infinities and a ValueError on NaNs. 10175 10176 >>> (10.0).as_integer_ratio() 10177 (10, 1) 10178 >>> (0.0).as_integer_ratio() 10179 (0, 1) 10180 >>> (-.25).as_integer_ratio() 10181 (-1, 4)""" 10182 return None 10183 base = getset_descriptor() 10184 def conj(self, _): 10185 """None""" 10186 return None 10187 data = getset_descriptor() 10188 dtype = getset_descriptor() 10189 flags = getset_descriptor() 10190 flat = getset_descriptor() 10191 def _fromhex(self, string): 10192 """float.fromhex(string) -> float 10193 10194 Create a floating-point number from a hexadecimal string. 10195 >>> float.fromhex('0x1.ffffp10') 10196 2047.984375 10197 >>> float.fromhex('-0x1p-1074') 10198 -4.9406564584124654e-324""" 10199 return None 10200 def hex(self, _): 10201 """float.hex() -> string 10202 10203 Return a hexadecimal representation of a floating-point number. 10204 >>> (-0.1).hex() 10205 '-0x1.999999999999ap-4' 10206 >>> 3.14159.hex() 10207 '0x1.921f9f01b866ep+1'""" 10208 return None 10209 imag = getset_descriptor() 10210 def is_integer(self, _): 10211 """Return True if the float is an integer.""" 10212 return None 10213 itemsize = getset_descriptor() 10214 nbytes = getset_descriptor() 10215 ndim = getset_descriptor() 10216 def newbyteorder(self, new_order): 10217 """newbyteorder(new_order='S') 10218 10219 Return a new `dtype` with a different byte order. 10220 10221 Changes are also made in all fields and sub-arrays of the data type. 10222 10223 The `new_order` code can be any from the following: 10224 10225 * {'<', 'L'} - little endian 10226 * {'>', 'B'} - big endian 10227 * {'=', 'N'} - native order 10228 * 'S' - swap dtype from current to opposite endian 10229 * {'|', 'I'} - ignore (no change to byte order) 10230 10231 Parameters 10232 ---------- 10233 new_order : str, optional 10234 Byte order to force; a value from the byte order specifications 10235 above. The default value ('S') results in swapping the current 10236 byte order. The code does a case-insensitive check on the first 10237 letter of `new_order` for the alternatives above. For example, 10238 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 10239 10240 10241 Returns 10242 ------- 10243 new_dtype : dtype 10244 New `dtype` object with the given change to the byte order.""" 10245 return dtype() 10246 real = getset_descriptor() 10247 shape = getset_descriptor() 10248 size = getset_descriptor() 10249 strides = getset_descriptor() 10250 class float64: 10251 T = getset_descriptor() 10252 __array_interface__ = getset_descriptor() 10253 __array_priority__ = getset_descriptor() 10254 __array_struct__ = getset_descriptor() 10255 __doc__ = str() 10256 def as_integer_ratio(self, _): 10257 """float.as_integer_ratio() -> (int, int) 10258 10259 Return a pair of integers, whose ratio is exactly equal to the original 10260 float and with a positive denominator. 10261 Raise OverflowError on infinities and a ValueError on NaNs. 10262 10263 >>> (10.0).as_integer_ratio() 10264 (10, 1) 10265 >>> (0.0).as_integer_ratio() 10266 (0, 1) 10267 >>> (-.25).as_integer_ratio() 10268 (-1, 4)""" 10269 return None 10270 base = getset_descriptor() 10271 def conj(self, _): 10272 """None""" 10273 return None 10274 data = getset_descriptor() 10275 dtype = getset_descriptor() 10276 flags = getset_descriptor() 10277 flat = getset_descriptor() 10278 def _fromhex(self, string): 10279 """float.fromhex(string) -> float 10280 10281 Create a floating-point number from a hexadecimal string. 10282 >>> float.fromhex('0x1.ffffp10') 10283 2047.984375 10284 >>> float.fromhex('-0x1p-1074') 10285 -4.9406564584124654e-324""" 10286 return None 10287 def hex(self, _): 10288 """float.hex() -> string 10289 10290 Return a hexadecimal representation of a floating-point number. 10291 >>> (-0.1).hex() 10292 '-0x1.999999999999ap-4' 10293 >>> 3.14159.hex() 10294 '0x1.921f9f01b866ep+1'""" 10295 return None 10296 imag = getset_descriptor() 10297 def is_integer(self, _): 10298 """Return True if the float is an integer.""" 10299 return None 10300 itemsize = getset_descriptor() 10301 nbytes = getset_descriptor() 10302 ndim = getset_descriptor() 10303 def newbyteorder(self, new_order): 10304 """newbyteorder(new_order='S') 10305 10306 Return a new `dtype` with a different byte order. 10307 10308 Changes are also made in all fields and sub-arrays of the data type. 10309 10310 The `new_order` code can be any from the following: 10311 10312 * {'<', 'L'} - little endian 10313 * {'>', 'B'} - big endian 10314 * {'=', 'N'} - native order 10315 * 'S' - swap dtype from current to opposite endian 10316 * {'|', 'I'} - ignore (no change to byte order) 10317 10318 Parameters 10319 ---------- 10320 new_order : str, optional 10321 Byte order to force; a value from the byte order specifications 10322 above. The default value ('S') results in swapping the current 10323 byte order. The code does a case-insensitive check on the first 10324 letter of `new_order` for the alternatives above. For example, 10325 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 10326 10327 10328 Returns 10329 ------- 10330 new_dtype : dtype 10331 New `dtype` object with the given change to the byte order.""" 10332 return dtype() 10333 real = getset_descriptor() 10334 shape = getset_descriptor() 10335 size = getset_descriptor() 10336 strides = getset_descriptor() 10337 class floating: 10338 T = getset_descriptor() 10339 __array_interface__ = getset_descriptor() 10340 __array_priority__ = getset_descriptor() 10341 __array_struct__ = getset_descriptor() 10342 __doc__ = None 10343 base = getset_descriptor() 10344 def conj(self, _): 10345 """None""" 10346 return None 10347 data = getset_descriptor() 10348 dtype = getset_descriptor() 10349 flags = getset_descriptor() 10350 flat = getset_descriptor() 10351 imag = getset_descriptor() 10352 itemsize = getset_descriptor() 10353 nbytes = getset_descriptor() 10354 ndim = getset_descriptor() 10355 def newbyteorder(self, new_order): 10356 """newbyteorder(new_order='S') 10357 10358 Return a new `dtype` with a different byte order. 10359 10360 Changes are also made in all fields and sub-arrays of the data type. 10361 10362 The `new_order` code can be any from the following: 10363 10364 * {'<', 'L'} - little endian 10365 * {'>', 'B'} - big endian 10366 * {'=', 'N'} - native order 10367 * 'S' - swap dtype from current to opposite endian 10368 * {'|', 'I'} - ignore (no change to byte order) 10369 10370 Parameters 10371 ---------- 10372 new_order : str, optional 10373 Byte order to force; a value from the byte order specifications 10374 above. The default value ('S') results in swapping the current 10375 byte order. The code does a case-insensitive check on the first 10376 letter of `new_order` for the alternatives above. For example, 10377 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 10378 10379 10380 Returns 10381 ------- 10382 new_dtype : dtype 10383 New `dtype` object with the given change to the byte order.""" 10384 return dtype() 10385 real = getset_descriptor() 10386 shape = getset_descriptor() 10387 size = getset_descriptor() 10388 strides = getset_descriptor() 10389 def floor(x, out=None): 10390 """floor(x[, out]) 10391 10392 Return the floor of the input, element-wise. 10393 10394 The floor of the scalar `x` is the largest integer `i`, such that 10395 `i <= x`. It is often denoted as :math:`\lfloor x \rfloor`. 10396 10397 Parameters 10398 ---------- 10399 x : array_like 10400 Input data. 10401 10402 Returns 10403 ------- 10404 y : {ndarray, scalar} 10405 The floor of each element in `x`. 10406 10407 See Also 10408 -------- 10409 ceil, trunc, rint 10410 10411 Notes 10412 ----- 10413 Some spreadsheet programs calculate the "floor-towards-zero", in other 10414 words ``floor(-2.5) == -2``. NumPy, however, uses the a definition of 10415 `floor` such that `floor(-2.5) == -3`. 10416 10417 Examples 10418 -------- 10419 >>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) 10420 >>> np.floor(a) 10421 array([-2., -2., -1., 0., 1., 1., 2.])""" 10422 return ndarray() 10423 def floor_divide(x1, x2, out=None): 10424 """floor_divide(x1, x2[, out]) 10425 10426 Return the largest integer smaller or equal to the division of the inputs. 10427 10428 Parameters 10429 ---------- 10430 x1 : array_like 10431 Numerator. 10432 x2 : array_like 10433 Denominator. 10434 10435 Returns 10436 ------- 10437 y : ndarray 10438 y = floor(`x1`/`x2`) 10439 10440 10441 See Also 10442 -------- 10443 divide : Standard division. 10444 floor : Round a number to the nearest integer toward minus infinity. 10445 ceil : Round a number to the nearest integer toward infinity. 10446 10447 Examples 10448 -------- 10449 >>> np.floor_divide(7,3) 10450 2 10451 >>> np.floor_divide([1., 2., 3., 4.], 2.5) 10452 array([ 0., 0., 1., 1.])""" 10453 return ndarray() 10454 def fmax(x1, x2, out=None): 10455 """fmax(x1, x2[, out]) 10456 10457 Element-wise maximum of array elements. 10458 10459 Compare two arrays and returns a new array containing the element-wise 10460 maxima. If one of the elements being compared is a nan, then the non-nan 10461 element is returned. If both elements are nans then the first is returned. 10462 The latter distinction is important for complex nans, which are defined as 10463 at least one of the real or imaginary parts being a nan. The net effect is 10464 that nans are ignored when possible. 10465 10466 Parameters 10467 ---------- 10468 x1, x2 : array_like 10469 The arrays holding the elements to be compared. They must have 10470 the same shape. 10471 10472 Returns 10473 ------- 10474 y : {ndarray, scalar} 10475 The minimum of `x1` and `x2`, element-wise. Returns scalar if 10476 both `x1` and `x2` are scalars. 10477 10478 See Also 10479 -------- 10480 fmin : 10481 Element-wise minimum of two arrays, ignoring any NaNs. 10482 maximum : 10483 Element-wise maximum of two arrays, propagating any NaNs. 10484 amax : 10485 The maximum value of an array along a given axis, propagating any NaNs. 10486 nanmax : 10487 The maximum value of an array along a given axis, ignoring any NaNs. 10488 10489 minimum, amin, nanmin 10490 10491 Notes 10492 ----- 10493 .. versionadded:: 1.3.0 10494 10495 The fmax is equivalent to ``np.where(x1 >= x2, x1, x2)`` when neither 10496 x1 nor x2 are nans, but it is faster and does proper broadcasting. 10497 10498 Examples 10499 -------- 10500 >>> np.fmax([2, 3, 4], [1, 5, 2]) 10501 array([ 2., 5., 4.]) 10502 10503 >>> np.fmax(np.eye(2), [0.5, 2]) 10504 array([[ 1. , 2. ], 10505 [ 0.5, 2. ]]) 10506 10507 >>> np.fmax([np.nan, 0, np.nan],[0, np.nan, np.nan]) 10508 array([ 0., 0., NaN])""" 10509 return ndarray() 10510 def fmin(x1, x2, out=None): 10511 """fmin(x1, x2[, out]) 10512 10513 Element-wise minimum of array elements. 10514 10515 Compare two arrays and returns a new array containing the element-wise 10516 minima. If one of the elements being compared is a nan, then the non-nan 10517 element is returned. If both elements are nans then the first is returned. 10518 The latter distinction is important for complex nans, which are defined as 10519 at least one of the real or imaginary parts being a nan. The net effect is 10520 that nans are ignored when possible. 10521 10522 Parameters 10523 ---------- 10524 x1, x2 : array_like 10525 The arrays holding the elements to be compared. They must have 10526 the same shape. 10527 10528 Returns 10529 ------- 10530 y : {ndarray, scalar} 10531 The minimum of `x1` and `x2`, element-wise. Returns scalar if 10532 both `x1` and `x2` are scalars. 10533 10534 See Also 10535 -------- 10536 fmax : 10537 Element-wise maximum of two arrays, ignoring any NaNs. 10538 minimum : 10539 Element-wise minimum of two arrays, propagating any NaNs. 10540 amin : 10541 The minimum value of an array along a given axis, propagating any NaNs. 10542 nanmin : 10543 The minimum value of an array along a given axis, ignoring any NaNs. 10544 10545 maximum, amax, nanmax 10546 10547 Notes 10548 ----- 10549 .. versionadded:: 1.3.0 10550 10551 The fmin is equivalent to ``np.where(x1 <= x2, x1, x2)`` when neither 10552 x1 nor x2 are nans, but it is faster and does proper broadcasting. 10553 10554 Examples 10555 -------- 10556 >>> np.fmin([2, 3, 4], [1, 5, 2]) 10557 array([2, 5, 4]) 10558 10559 >>> np.fmin(np.eye(2), [0.5, 2]) 10560 array([[ 1. , 2. ], 10561 [ 0.5, 2. ]]) 10562 10563 >>> np.fmin([np.nan, 0, np.nan],[0, np.nan, np.nan]) 10564 array([ 0., 0., NaN])""" 10565 return ndarray() 10566 def fmod(x1, x2, out=None): 10567 """fmod(x1, x2[, out]) 10568 10569 Return the element-wise remainder of division. 10570 10571 This is the NumPy implementation of the Python modulo operator `%`. 10572 10573 Parameters 10574 ---------- 10575 x1 : array_like 10576 Dividend. 10577 x2 : array_like 10578 Divisor. 10579 10580 Returns 10581 ------- 10582 y : array_like 10583 The remainder of the division of `x1` by `x2`. 10584 10585 See Also 10586 -------- 10587 remainder : Modulo operation where the quotient is `floor(x1/x2)`. 10588 divide 10589 10590 Notes 10591 ----- 10592 The result of the modulo operation for negative dividend and divisors is 10593 bound by conventions. In `fmod`, the sign of the remainder is the sign of 10594 the dividend. In `remainder`, the sign of the divisor does not affect the 10595 sign of the result. 10596 10597 Examples 10598 -------- 10599 >>> np.fmod([-3, -2, -1, 1, 2, 3], 2) 10600 array([-1, 0, -1, 1, 0, 1]) 10601 >>> np.remainder([-3, -2, -1, 1, 2, 3], 2) 10602 array([1, 0, 1, 1, 0, 1]) 10603 10604 >>> np.fmod([5, 3], [2, 2.]) 10605 array([ 1., 1.]) 10606 >>> a = np.arange(-3, 3).reshape(3, 2) 10607 >>> a 10608 array([[-3, -2], 10609 [-1, 0], 10610 [ 1, 2]]) 10611 >>> np.fmod(a, [2,2]) 10612 array([[-1, 0], 10613 [-1, 0], 10614 [ 1, 0]])""" 10615 return ndarray() 10616 class format_parser: 10617 __doc__ = str() 10618 __module__ = str() 10619 def _createdescr(self, _): 10620 """None""" 10621 return None 10622 def _parseFormats(self, formats=0, aligned=0): 10623 """ Parse the field formats """ 10624 return None 10625 def _setfieldnames(self, _): 10626 """convert input field names into a list and assign to the _names 10627 attribute """ 10628 return None 10629 def frexp(x, out1, out2): 10630 """frexp(x[, out1, out2]) 10631 10632 Split the number, x, into a normalized fraction (y1) and exponent (y2)""" 10633 return None 10634 def _frombuffer(buffer, dtype, count, offset): 10635 """frombuffer(buffer, dtype=float, count=-1, offset=0) 10636 10637 Interpret a buffer as a 1-dimensional array. 10638 10639 Parameters 10640 ---------- 10641 buffer : buffer_like 10642 An object that exposes the buffer interface. 10643 dtype : data-type, optional 10644 Data-type of the returned array; default: float. 10645 count : int, optional 10646 Number of items to read. ``-1`` means all data in the buffer. 10647 offset : int, optional 10648 Start reading the buffer from this offset; default: 0. 10649 10650 Notes 10651 ----- 10652 If the buffer has data that is not in machine byte-order, this should 10653 be specified as part of the data-type, e.g.:: 10654 10655 >>> dt = np.dtype(int) 10656 >>> dt = dt.newbyteorder('>') 10657 >>> np.frombuffer(buf, dtype=dt) 10658 10659 The data of the resulting array will not be byteswapped, but will be 10660 interpreted correctly. 10661 10662 Examples 10663 -------- 10664 >>> s = 'hello world' 10665 >>> np.frombuffer(s, dtype='S1', count=5, offset=6) 10666 array(['w', 'o', 'r', 'l', 'd'], 10667 dtype='|S1')""" 10668 return None 10669 def _fromfile(file, dtype, count, sep): 10670 """fromfile(file, dtype=float, count=-1, sep='') 10671 10672 Construct an array from data in a text or binary file. 10673 10674 A highly efficient way of reading binary data with a known data-type, 10675 as well as parsing simply formatted text files. Data written using the 10676 `tofile` method can be read using this function. 10677 10678 Parameters 10679 ---------- 10680 file : file or str 10681 Open file object or filename. 10682 dtype : data-type 10683 Data type of the returned array. 10684 For binary files, it is used to determine the size and byte-order 10685 of the items in the file. 10686 count : int 10687 Number of items to read. ``-1`` means all items (i.e., the complete 10688 file). 10689 sep : str 10690 Separator between items if file is a text file. 10691 Empty ("") separator means the file should be treated as binary. 10692 Spaces (" ") in the separator match zero or more whitespace characters. 10693 A separator consisting only of spaces must match at least one 10694 whitespace. 10695 10696 See also 10697 -------- 10698 load, save 10699 ndarray.tofile 10700 loadtxt : More flexible way of loading data from a text file. 10701 10702 Notes 10703 ----- 10704 Do not rely on the combination of `tofile` and `fromfile` for 10705 data storage, as the binary files generated are are not platform 10706 independent. In particular, no byte-order or data-type information is 10707 saved. Data can be stored in the platform independent ``.npy`` format 10708 using `save` and `load` instead. 10709 10710 Examples 10711 -------- 10712 Construct an ndarray: 10713 10714 >>> dt = np.dtype([('time', [('min', int), ('sec', int)]), 10715 ... ('temp', float)]) 10716 >>> x = np.zeros((1,), dtype=dt) 10717 >>> x['time']['min'] = 10; x['temp'] = 98.25 10718 >>> x 10719 array([((10, 0), 98.25)], 10720 dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')]) 10721 10722 Save the raw data to disk: 10723 10724 >>> import os 10725 >>> fname = os.tmpnam() 10726 >>> x.tofile(fname) 10727 10728 Read the raw data from disk: 10729 10730 >>> np.fromfile(fname, dtype=dt) 10731 array([((10, 0), 98.25)], 10732 dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')]) 10733 10734 The recommended way to store and load data: 10735 10736 >>> np.save(fname, x) 10737 >>> np.load(fname + '.npy') 10738 array([((10, 0), 98.25)], 10739 dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')])""" 10740 return None 10741 def _fromfunction(function, shape, dtype): 10742 """ 10743 Construct an array by executing a function over each coordinate. 10744 10745 The resulting array therefore has a value ``fn(x, y, z)`` at 10746 coordinate ``(x, y, z)``. 10747 10748 Parameters 10749 ---------- 10750 function : callable 10751 The function is called with N parameters, where N is the rank of 10752 `shape`. Each parameter represents the coordinates of the array 10753 varying along a specific axis. For example, if `shape` 10754 were ``(2, 2)``, then the parameters in turn be (0, 0), (0, 1), 10755 (1, 0), (1, 1). 10756 shape : (N,) tuple of ints 10757 Shape of the output array, which also determines the shape of 10758 the coordinate arrays passed to `function`. 10759 dtype : data-type, optional 10760 Data-type of the coordinate arrays passed to `function`. 10761 By default, `dtype` is float. 10762 10763 Returns 10764 ------- 10765 fromfunction : any 10766 The result of the call to `function` is passed back directly. 10767 Therefore the shape of `fromfunction` is completely determined by 10768 `function`. If `function` returns a scalar value, the shape of 10769 `fromfunction` would match the `shape` parameter. 10770 10771 See Also 10772 -------- 10773 indices, meshgrid 10774 10775 Notes 10776 ----- 10777 Keywords other than `dtype` are passed to `function`. 10778 10779 Examples 10780 -------- 10781 >>> np.fromfunction(lambda i, j: i == j, (3, 3), dtype=int) 10782 array([[ True, False, False], 10783 [False, True, False], 10784 [False, False, True]], dtype=bool) 10785 10786 >>> np.fromfunction(lambda i, j: i + j, (3, 3), dtype=int) 10787 array([[0, 1, 2], 10788 [1, 2, 3], 10789 [2, 3, 4]]) 10790 10791 """ 10792 return any() 10793 def _fromiter(iterable, dtype, count): 10794 """fromiter(iterable, dtype, count=-1) 10795 10796 Create a new 1-dimensional array from an iterable object. 10797 10798 Parameters 10799 ---------- 10800 iterable : iterable object 10801 An iterable object providing data for the array. 10802 dtype : data-type 10803 The data-type of the returned array. 10804 count : int, optional 10805 The number of items to read from *iterable*. The default is -1, 10806 which means all data is read. 10807 10808 Returns 10809 ------- 10810 out : ndarray 10811 The output array. 10812 10813 Notes 10814 ----- 10815 Specify `count` to improve performance. It allows ``fromiter`` to 10816 pre-allocate the output array, instead of resizing it on demand. 10817 10818 Examples 10819 -------- 10820 >>> iterable = (x*x for x in range(5)) 10821 >>> np.fromiter(iterable, np.float) 10822 array([ 0., 1., 4., 9., 16.])""" 10823 return ndarray() 10824 def _frompyfunc(func, nin, nout): 10825 """frompyfunc(func, nin, nout) 10826 10827 Takes an arbitrary Python function and returns a Numpy ufunc. 10828 10829 Can be used, for example, to add broadcasting to a built-in Python 10830 function (see Examples section). 10831 10832 Parameters 10833 ---------- 10834 func : Python function object 10835 An arbitrary Python function. 10836 nin : int 10837 The number of input arguments. 10838 nout : int 10839 The number of objects returned by `func`. 10840 10841 Returns 10842 ------- 10843 out : ufunc 10844 Returns a Numpy universal function (``ufunc``) object. 10845 10846 Notes 10847 ----- 10848 The returned ufunc always returns PyObject arrays. 10849 10850 Examples 10851 -------- 10852 Use frompyfunc to add broadcasting to the Python function ``oct``: 10853 10854 >>> oct_array = np.frompyfunc(oct, 1, 1) 10855 >>> oct_array(np.array((10, 30, 100))) 10856 array([012, 036, 0144], dtype=object) 10857 >>> np.array((oct(10), oct(30), oct(100))) # for comparison 10858 array(['012', '036', '0144'], 10859 dtype='|S4')""" 10860 return ufunc() 10861 def _fromregex(file, regexp, dtype): 10862 """ 10863 Construct an array from a text file, using regular expression parsing. 10864 10865 The returned array is always a structured array, and is constructed from 10866 all matches of the regular expression in the file. Groups in the regular 10867 expression are converted to fields of the structured array. 10868 10869 Parameters 10870 ---------- 10871 file : str or file 10872 File name or file object to read. 10873 regexp : str or regexp 10874 Regular expression used to parse the file. 10875 Groups in the regular expression correspond to fields in the dtype. 10876 dtype : dtype or list of dtypes 10877 Dtype for the structured array. 10878 10879 Returns 10880 ------- 10881 output : ndarray 10882 The output array, containing the part of the content of `file` that 10883 was matched by `regexp`. `output` is always a structured array. 10884 10885 Raises 10886 ------ 10887 TypeError 10888 When `dtype` is not a valid dtype for a structured array. 10889 10890 See Also 10891 -------- 10892 fromstring, loadtxt 10893 10894 Notes 10895 ----- 10896 Dtypes for structured arrays can be specified in several forms, but all 10897 forms specify at least the data type and field name. For details see 10898 `doc.structured_arrays`. 10899 10900 Examples 10901 -------- 10902 >>> f = open('test.dat', 'w') 10903 >>> f.write("1312 foo\n1534 bar\n444 qux") 10904 >>> f.close() 10905 10906 >>> regexp = r"(\d+)\s+(...)" # match [digits, whitespace, anything] 10907 >>> output = np.fromregex('test.dat', regexp, 10908 ... [('num', np.int64), ('key', 'S3')]) 10909 >>> output 10910 array([(1312L, 'foo'), (1534L, 'bar'), (444L, 'qux')], 10911 dtype=[('num', '<i8'), ('key', '|S3')]) 10912 >>> output['num'] 10913 array([1312, 1534, 444], dtype=int64) 10914 10915 """ 10916 return ndarray() 10917 def _fromstring(string, dtype, count, sep): 10918 """fromstring(string, dtype=float, count=-1, sep='') 10919 10920 A new 1-D array initialized from raw binary or text data in a string. 10921 10922 Parameters 10923 ---------- 10924 string : str 10925 A string containing the data. 10926 dtype : data-type, optional 10927 The data type of the array; default: float. For binary input data, 10928 the data must be in exactly this format. 10929 count : int, optional 10930 Read this number of `dtype` elements from the data. If this is 10931 negative (the default), the count will be determined from the 10932 length of the data. 10933 sep : str, optional 10934 If not provided or, equivalently, the empty string, the data will 10935 be interpreted as binary data; otherwise, as ASCII text with 10936 decimal numbers. Also in this latter case, this argument is 10937 interpreted as the string separating numbers in the data; extra 10938 whitespace between elements is also ignored. 10939 10940 Returns 10941 ------- 10942 arr : ndarray 10943 The constructed array. 10944 10945 Raises 10946 ------ 10947 ValueError 10948 If the string is not the correct size to satisfy the requested 10949 `dtype` and `count`. 10950 10951 See Also 10952 -------- 10953 frombuffer, fromfile, fromiter 10954 10955 Examples 10956 -------- 10957 >>> np.fromstring('\x01\x02', dtype=np.uint8) 10958 array([1, 2], dtype=uint8) 10959 >>> np.fromstring('1 2', dtype=int, sep=' ') 10960 array([1, 2]) 10961 >>> np.fromstring('1, 2', dtype=int, sep=',') 10962 array([1, 2]) 10963 >>> np.fromstring('\x01\x02\x03\x04\x05', dtype=np.uint8, count=3) 10964 array([1, 2, 3], dtype=uint8)""" 10965 return ndarray() 10966 def full(shape, fill_value="C", dtype=None, order="C"): 10967 """ 10968 Return a new array of given shape and type, filled with `fill_value`. 10969 10970 Parameters 10971 ---------- 10972 shape : int or sequence of ints 10973 Shape of the new array, e.g., ``(2, 3)`` or ``2``. 10974 fill_value : scalar 10975 Fill value. 10976 dtype : data-type, optional 10977 The desired data-type for the array, e.g., `numpy.int8`. Default is 10978 is chosen as `np.array(fill_value).dtype`. 10979 order : {'C', 'F'}, optional 10980 Whether to store multidimensional data in C- or Fortran-contiguous 10981 (row- or column-wise) order in memory. 10982 10983 Returns 10984 ------- 10985 out : ndarray 10986 Array of `fill_value` with the given shape, dtype, and order. 10987 10988 See Also 10989 -------- 10990 zeros_like : Return an array of zeros with shape and type of input. 10991 ones_like : Return an array of ones with shape and type of input. 10992 empty_like : Return an empty array with shape and type of input. 10993 full_like : Fill an array with shape and type of input. 10994 zeros : Return a new array setting values to zero. 10995 ones : Return a new array setting values to one. 10996 empty : Return a new uninitialized array. 10997 10998 Examples 10999 -------- 11000 >>> np.full((2, 2), np.inf) 11001 array([[ inf, inf], 11002 [ inf, inf]]) 11003 >>> np.full((2, 2), 10, dtype=np.int) 11004 array([[10, 10], 11005 [10, 10]]) 11006 11007 """ 11008 return ndarray() 11009 def full_like(a, fill_value=True, dtype=None, order="K", subok=True): 11010 """ 11011 Return a full array with the same shape and type as a given array. 11012 11013 Parameters 11014 ---------- 11015 a : array_like 11016 The shape and data-type of `a` define these same attributes of 11017 the returned array. 11018 fill_value : scalar 11019 Fill value. 11020 dtype : data-type, optional 11021 Overrides the data type of the result. 11022 order : {'C', 'F', 'A', or 'K'}, optional 11023 Overrides the memory layout of the result. 'C' means C-order, 11024 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, 11025 'C' otherwise. 'K' means match the layout of `a` as closely 11026 as possible. 11027 subok : bool, optional. 11028 If True, then the newly created array will use the sub-class 11029 type of 'a', otherwise it will be a base-class array. Defaults 11030 to True. 11031 11032 Returns 11033 ------- 11034 out : ndarray 11035 Array of `fill_value` with the same shape and type as `a`. 11036 11037 See Also 11038 -------- 11039 zeros_like : Return an array of zeros with shape and type of input. 11040 ones_like : Return an array of ones with shape and type of input. 11041 empty_like : Return an empty array with shape and type of input. 11042 zeros : Return a new array setting values to zero. 11043 ones : Return a new array setting values to one. 11044 empty : Return a new uninitialized array. 11045 full : Fill a new array. 11046 11047 Examples 11048 -------- 11049 >>> x = np.arange(6, dtype=np.int) 11050 >>> np.full_like(x, 1) 11051 array([1, 1, 1, 1, 1, 1]) 11052 >>> np.full_like(x, 0.1) 11053 array([0, 0, 0, 0, 0, 0]) 11054 >>> np.full_like(x, 0.1, dtype=np.double) 11055 array([ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]) 11056 >>> np.full_like(x, np.nan, dtype=np.double) 11057 array([ nan, nan, nan, nan, nan, nan]) 11058 11059 >>> y = np.arange(6, dtype=np.double) 11060 >>> np.full_like(y, 0.1) 11061 array([ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]) 11062 11063 """ 11064 return ndarray() 11065 def fv(rate, nper, pmt, pv="end", when="end"): 11066 """ 11067 Compute the future value. 11068 11069 Given: 11070 * a present value, `pv` 11071 * an interest `rate` compounded once per period, of which 11072 there are 11073 * `nper` total 11074 * a (fixed) payment, `pmt`, paid either 11075 * at the beginning (`when` = {'begin', 1}) or the end 11076 (`when` = {'end', 0}) of each period 11077 11078 Return: 11079 the value at the end of the `nper` periods 11080 11081 Parameters 11082 ---------- 11083 rate : scalar or array_like of shape(M, ) 11084 Rate of interest as decimal (not per cent) per period 11085 nper : scalar or array_like of shape(M, ) 11086 Number of compounding periods 11087 pmt : scalar or array_like of shape(M, ) 11088 Payment 11089 pv : scalar or array_like of shape(M, ) 11090 Present value 11091 when : {{'begin', 1}, {'end', 0}}, {string, int}, optional 11092 When payments are due ('begin' (1) or 'end' (0)). 11093 Defaults to {'end', 0}. 11094 11095 Returns 11096 ------- 11097 out : ndarray 11098 Future values. If all input is scalar, returns a scalar float. If 11099 any input is array_like, returns future values for each input element. 11100 If multiple inputs are array_like, they all must have the same shape. 11101 11102 Notes 11103 ----- 11104 The future value is computed by solving the equation:: 11105 11106 fv + 11107 pv*(1+rate)**nper + 11108 pmt*(1 + rate*when)/rate*((1 + rate)**nper - 1) == 0 11109 11110 or, when ``rate == 0``:: 11111 11112 fv + pv + pmt * nper == 0 11113 11114 References 11115 ---------- 11116 .. [WRW] Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May). 11117 Open Document Format for Office Applications (OpenDocument)v1.2, 11118 Part 2: Recalculated Formula (OpenFormula) Format - Annotated Version, 11119 Pre-Draft 12. Organization for the Advancement of Structured Information 11120 Standards (OASIS). Billerica, MA, USA. [ODT Document]. 11121 Available: 11122 http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formula 11123 OpenDocument-formula-20090508.odt 11124 11125 Examples 11126 -------- 11127 What is the future value after 10 years of saving $100 now, with 11128 an additional monthly savings of $100. Assume the interest rate is 11129 5% (annually) compounded monthly? 11130 11131 >>> np.fv(0.05/12, 10*12, -100, -100) 11132 15692.928894335748 11133 11134 By convention, the negative sign represents cash flow out (i.e. money not 11135 available today). Thus, saving $100 a month at 5% annual interest leads 11136 to $15,692.93 available to spend in 10 years. 11137 11138 If any input is array_like, returns an array of equal shape. Let's 11139 compare different interest rates from the example above. 11140 11141 >>> a = np.array((0.05, 0.06, 0.07))/12 11142 >>> np.fv(a, 10*12, -100, -100) 11143 array([ 15692.92889434, 16569.87435405, 17509.44688102]) 11144 11145 """ 11146 return ndarray() 11147 class generic: 11148 T = getset_descriptor() 11149 __array_interface__ = getset_descriptor() 11150 __array_priority__ = getset_descriptor() 11151 __array_struct__ = getset_descriptor() 11152 __doc__ = str() 11153 base = getset_descriptor() 11154 def conj(self, _): 11155 """None""" 11156 return None 11157 data = getset_descriptor() 11158 dtype = getset_descriptor() 11159 flags = getset_descriptor() 11160 flat = getset_descriptor() 11161 imag = getset_descriptor() 11162 itemsize = getset_descriptor() 11163 nbytes = getset_descriptor() 11164 ndim = getset_descriptor() 11165 def newbyteorder(self, new_order): 11166 """newbyteorder(new_order='S') 11167 11168 Return a new `dtype` with a different byte order. 11169 11170 Changes are also made in all fields and sub-arrays of the data type. 11171 11172 The `new_order` code can be any from the following: 11173 11174 * {'<', 'L'} - little endian 11175 * {'>', 'B'} - big endian 11176 * {'=', 'N'} - native order 11177 * 'S' - swap dtype from current to opposite endian 11178 * {'|', 'I'} - ignore (no change to byte order) 11179 11180 Parameters 11181 ---------- 11182 new_order : str, optional 11183 Byte order to force; a value from the byte order specifications 11184 above. The default value ('S') results in swapping the current 11185 byte order. The code does a case-insensitive check on the first 11186 letter of `new_order` for the alternatives above. For example, 11187 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 11188 11189 11190 Returns 11191 ------- 11192 new_dtype : dtype 11193 New `dtype` object with the given change to the byte order.""" 11194 return dtype() 11195 real = getset_descriptor() 11196 shape = getset_descriptor() 11197 size = getset_descriptor() 11198 strides = getset_descriptor() 11199 def gen_fromtxt(fname=True, dtype=typefloat(), comments="#", delimiter=None, skiprows=0, skip_header=0, skip_footer=0, converters=None, missing="", missing_values=None, filling_values=None, usecols=None, names=None, excludelist=None, deletechars=None, replace_space="_", autostrip=False, case_sensitive=True, defaultfmt="f%i", unpack=None, usemask=False, loose=True, invalid_raise=True): 11200 """ 11201 Load data from a text file, with missing values handled as specified. 11202 11203 Each line past the first `skip_header` lines is split at the `delimiter` 11204 character, and characters following the `comments` character are discarded. 11205 11206 Parameters 11207 ---------- 11208 fname : file or str 11209 File, filename, or generator to read. If the filename extension is 11210 `.gz` or `.bz2`, the file is first decompressed. Note that 11211 generators must return byte strings in Python 3k. 11212 dtype : dtype, optional 11213 Data type of the resulting array. 11214 If None, the dtypes will be determined by the contents of each 11215 column, individually. 11216 comments : str, optional 11217 The character used to indicate the start of a comment. 11218 All the characters occurring on a line after a comment are discarded 11219 delimiter : str, int, or sequence, optional 11220 The string used to separate values. By default, any consecutive 11221 whitespaces act as delimiter. An integer or sequence of integers 11222 can also be provided as width(s) of each field. 11223 skip_header : int, optional 11224 The numbers of lines to skip at the beginning of the file. 11225 skip_footer : int, optional 11226 The numbers of lines to skip at the end of the file 11227 converters : variable, optional 11228 The set of functions that convert the data of a column to a value. 11229 The converters can also be used to provide a default value 11230 for missing data: ``converters = {3: lambda s: float(s or 0)}``. 11231 missing_values : variable, optional 11232 The set of strings corresponding to missing data. 11233 filling_values : variable, optional 11234 The set of values to be used as default when the data are missing. 11235 usecols : sequence, optional 11236 Which columns to read, with 0 being the first. For example, 11237 ``usecols = (1, 4, 5)`` will extract the 2nd, 5th and 6th columns. 11238 names : {None, True, str, sequence}, optional 11239 If `names` is True, the field names are read from the first valid line 11240 after the first `skip_header` lines. 11241 If `names` is a sequence or a single-string of comma-separated names, 11242 the names will be used to define the field names in a structured dtype. 11243 If `names` is None, the names of the dtype fields will be used, if any. 11244 excludelist : sequence, optional 11245 A list of names to exclude. This list is appended to the default list 11246 ['return','file','print']. Excluded names are appended an underscore: 11247 for example, `file` would become `file_`. 11248 deletechars : str, optional 11249 A string combining invalid characters that must be deleted from the 11250 names. 11251 defaultfmt : str, optional 11252 A format used to define default field names, such as "f%i" or "f_%02i". 11253 autostrip : bool, optional 11254 Whether to automatically strip white spaces from the variables. 11255 replace_space : char, optional 11256 Character(s) used in replacement of white spaces in the variables 11257 names. By default, use a '_'. 11258 case_sensitive : {True, False, 'upper', 'lower'}, optional 11259 If True, field names are case sensitive. 11260 If False or 'upper', field names are converted to upper case. 11261 If 'lower', field names are converted to lower case. 11262 unpack : bool, optional 11263 If True, the returned array is transposed, so that arguments may be 11264 unpacked using ``x, y, z = loadtxt(...)`` 11265 usemask : bool, optional 11266 If True, return a masked array. 11267 If False, return a regular array. 11268 invalid_raise : bool, optional 11269 If True, an exception is raised if an inconsistency is detected in the 11270 number of columns. 11271 If False, a warning is emitted and the offending lines are skipped. 11272 11273 Returns 11274 ------- 11275 out : ndarray 11276 Data read from the text file. If `usemask` is True, this is a 11277 masked array. 11278 11279 See Also 11280 -------- 11281 numpy.loadtxt : equivalent function when no data is missing. 11282 11283 Notes 11284 ----- 11285 * When spaces are used as delimiters, or when no delimiter has been given 11286 as input, there should not be any missing data between two fields. 11287 * When the variables are named (either by a flexible dtype or with `names`, 11288 there must not be any header in the file (else a ValueError 11289 exception is raised). 11290 * Individual values are not stripped of spaces by default. 11291 When using a custom converter, make sure the function does remove spaces. 11292 11293 References 11294 ---------- 11295 .. [1] Numpy User Guide, section `I/O with Numpy 11296 <http://docs.scipy.org/doc/numpy/user/basics.io.genfromtxt.html>`_. 11297 11298 Examples 11299 --------- 11300 >>> from StringIO import StringIO 11301 >>> import numpy as np 11302 11303 Comma delimited file with mixed dtype 11304 11305 >>> s = StringIO("1,1.3,abcde") 11306 >>> data = np.genfromtxt(s, dtype=[('myint','i8'),('myfloat','f8'), 11307 ... ('mystring','S5')], delimiter=",") 11308 >>> data 11309 array((1, 1.3, 'abcde'), 11310 dtype=[('myint', '<i8'), ('myfloat', '<f8'), ('mystring', '|S5')]) 11311 11312 Using dtype = None 11313 11314 >>> s.seek(0) # needed for StringIO example only 11315 >>> data = np.genfromtxt(s, dtype=None, 11316 ... names = ['myint','myfloat','mystring'], delimiter=",") 11317 >>> data 11318 array((1, 1.3, 'abcde'), 11319 dtype=[('myint', '<i8'), ('myfloat', '<f8'), ('mystring', '|S5')]) 11320 11321 Specifying dtype and names 11322 11323 >>> s.seek(0) 11324 >>> data = np.genfromtxt(s, dtype="i8,f8,S5", 11325 ... names=['myint','myfloat','mystring'], delimiter=",") 11326 >>> data 11327 array((1, 1.3, 'abcde'), 11328 dtype=[('myint', '<i8'), ('myfloat', '<f8'), ('mystring', '|S5')]) 11329 11330 An example with fixed-width columns 11331 11332 >>> s = StringIO("11.3abcde") 11333 >>> data = np.genfromtxt(s, dtype=None, names=['intvar','fltvar','strvar'], 11334 ... delimiter=[1,3,5]) 11335 >>> data 11336 array((1, 1.3, 'abcde'), 11337 dtype=[('intvar', '<i8'), ('fltvar', '<f8'), ('strvar', '|S5')]) 11338 11339 """ 11340 return ndarray() 11341 def get_array_wrap(): 11342 """Find the wrapper for the array with the highest priority. 11343 11344 In case of ties, leftmost wins. If no wrapper is found, return None 11345 """ 11346 return None 11347 def get_include(): 11348 """ 11349 Return the directory that contains the NumPy \*.h header files. 11350 11351 Extension modules that need to compile against NumPy should use this 11352 function to locate the appropriate include directory. 11353 11354 Notes 11355 ----- 11356 When using ``distutils``, for example in ``setup.py``. 11357 :: 11358 11359 import numpy as np 11360 ... 11361 Extension('extension_name', ... 11362 include_dirs=[np.get_include()]) 11363 ... 11364 11365 """ 11366 return None 11367 def get_numarray_include(type=None): 11368 """ 11369 Return the directory that contains the numarray \*.h header files. 11370 11371 Extension modules that need to compile against numarray should use this 11372 function to locate the appropriate include directory. 11373 11374 Parameters 11375 ---------- 11376 type : any, optional 11377 If `type` is not None, the location of the NumPy headers is returned 11378 as well. 11379 11380 Returns 11381 ------- 11382 dirs : str or list of str 11383 If `type` is None, `dirs` is a string containing the path to the 11384 numarray headers. 11385 If `type` is not None, `dirs` is a list of strings with first the 11386 path(s) to the numarray headers, followed by the path to the NumPy 11387 headers. 11388 11389 Notes 11390 ----- 11391 Useful when using ``distutils``, for example in ``setup.py``. 11392 :: 11393 11394 import numpy as np 11395 ... 11396 Extension('extension_name', ... 11397 include_dirs=[np.get_numarray_include()]) 11398 ... 11399 11400 """ 11401 return str() if False else list() 11402 def get_printoptions(): 11403 """ 11404 Return the current print options. 11405 11406 Returns 11407 ------- 11408 print_opts : dict 11409 Dictionary of current print options with keys 11410 11411 - precision : int 11412 - threshold : int 11413 - edgeitems : int 11414 - linewidth : int 11415 - suppress : bool 11416 - nanstr : str 11417 - infstr : str 11418 - formatter : dict of callables 11419 11420 For a full description of these options, see `set_printoptions`. 11421 11422 See Also 11423 -------- 11424 set_printoptions, set_string_function 11425 11426 """ 11427 return None 11428 def getbuffer(obj, offset, size): 11429 """getbuffer(obj [,offset[, size]]) 11430 11431 Create a buffer object from the given object referencing a slice of 11432 length size starting at offset. 11433 11434 Default is the entire buffer. A read-write buffer is attempted followed 11435 by a read-only buffer. 11436 11437 Parameters 11438 ---------- 11439 obj : object 11440 11441 offset : int, optional 11442 11443 size : int, optional 11444 11445 Returns 11446 ------- 11447 buffer_obj : buffer 11448 11449 Examples 11450 -------- 11451 >>> buf = np.getbuffer(np.ones(5), 1, 3) 11452 >>> len(buf) 11453 3 11454 >>> buf[0] 11455 '\x00' 11456 >>> buf 11457 <read-write buffer for 0x8af1e70, size 3, offset 1 at 0x8ba4ec0>""" 11458 return buffer() 11459 def getbufsize(): 11460 """ 11461 Return the size of the buffer used in ufuncs. 11462 11463 Returns 11464 ------- 11465 getbufsize : int 11466 Size of ufunc buffer in bytes. 11467 11468 """ 11469 return None 11470 def geterr(): 11471 """ 11472 Get the current way of handling floating-point errors. 11473 11474 Returns 11475 ------- 11476 res : dict 11477 A dictionary with keys "divide", "over", "under", and "invalid", 11478 whose values are from the strings "ignore", "print", "log", "warn", 11479 "raise", and "call". The keys represent possible floating-point 11480 exceptions, and the values define how these exceptions are handled. 11481 11482 See Also 11483 -------- 11484 geterrcall, seterr, seterrcall 11485 11486 Notes 11487 ----- 11488 For complete documentation of the types of floating-point exceptions and 11489 treatment options, see `seterr`. 11490 11491 Examples 11492 -------- 11493 >>> np.geterr() 11494 {'over': 'warn', 'divide': 'warn', 'invalid': 'warn', 11495 'under': 'ignore'} 11496 >>> np.arange(3.) / np.arange(3.) 11497 array([ NaN, 1., 1.]) 11498 11499 >>> oldsettings = np.seterr(all='warn', over='raise') 11500 >>> np.geterr() 11501 {'over': 'raise', 'divide': 'warn', 'invalid': 'warn', 'under': 'warn'} 11502 >>> np.arange(3.) / np.arange(3.) 11503 __main__:1: RuntimeWarning: invalid value encountered in divide 11504 array([ NaN, 1., 1.]) 11505 11506 """ 11507 return None 11508 def geterrcall(): 11509 """ 11510 Return the current callback function used on floating-point errors. 11511 11512 When the error handling for a floating-point error (one of "divide", 11513 "over", "under", or "invalid") is set to 'call' or 'log', the function 11514 that is called or the log instance that is written to is returned by 11515 `geterrcall`. This function or log instance has been set with 11516 `seterrcall`. 11517 11518 Returns 11519 ------- 11520 errobj : callable, log instance or None 11521 The current error handler. If no handler was set through `seterrcall`, 11522 ``None`` is returned. 11523 11524 See Also 11525 -------- 11526 seterrcall, seterr, geterr 11527 11528 Notes 11529 ----- 11530 For complete documentation of the types of floating-point exceptions and 11531 treatment options, see `seterr`. 11532 11533 Examples 11534 -------- 11535 >>> np.geterrcall() # we did not yet set a handler, returns None 11536 11537 >>> oldsettings = np.seterr(all='call') 11538 >>> def err_handler(type, flag): 11539 ... print "Floating point error (%s), with flag %s" % (type, flag) 11540 >>> oldhandler = np.seterrcall(err_handler) 11541 >>> np.array([1, 2, 3]) / 0.0 11542 Floating point error (divide by zero), with flag 1 11543 array([ Inf, Inf, Inf]) 11544 11545 >>> cur_handler = np.geterrcall() 11546 >>> cur_handler is err_handler 11547 True 11548 11549 """ 11550 return None 11551 def geterrobj(_): 11552 """geterrobj() 11553 11554 Return the current object that defines floating-point error handling. 11555 11556 The error object contains all information that defines the error handling 11557 behavior in Numpy. `geterrobj` is used internally by the other 11558 functions that get and set error handling behavior (`geterr`, `seterr`, 11559 `geterrcall`, `seterrcall`). 11560 11561 Returns 11562 ------- 11563 errobj : list 11564 The error object, a list containing three elements: 11565 [internal numpy buffer size, error mask, error callback function]. 11566 11567 The error mask is a single integer that holds the treatment information 11568 on all four floating point errors. The information for each error type 11569 is contained in three bits of the integer. If we print it in base 8, we 11570 can see what treatment is set for "invalid", "under", "over", and 11571 "divide" (in that order). The printed string can be interpreted with 11572 11573 * 0 : 'ignore' 11574 * 1 : 'warn' 11575 * 2 : 'raise' 11576 * 3 : 'call' 11577 * 4 : 'print' 11578 * 5 : 'log' 11579 11580 See Also 11581 -------- 11582 seterrobj, seterr, geterr, seterrcall, geterrcall 11583 getbufsize, setbufsize 11584 11585 Notes 11586 ----- 11587 For complete documentation of the types of floating-point exceptions and 11588 treatment options, see `seterr`. 11589 11590 Examples 11591 -------- 11592 >>> np.geterrobj() # first get the defaults 11593 [10000, 0, None] 11594 11595 >>> def err_handler(type, flag): 11596 ... print "Floating point error (%s), with flag %s" % (type, flag) 11597 ... 11598 >>> old_bufsize = np.setbufsize(20000) 11599 >>> old_err = np.seterr(divide='raise') 11600 >>> old_handler = np.seterrcall(err_handler) 11601 >>> np.geterrobj() 11602 [20000, 2, <function err_handler at 0x91dcaac>] 11603 11604 >>> old_err = np.seterr(all='ignore') 11605 >>> np.base_repr(np.geterrobj()[1], 8) 11606 '0' 11607 >>> old_err = np.seterr(divide='warn', over='log', under='call', 11608 invalid='print') 11609 >>> np.base_repr(np.geterrobj()[1], 8) 11610 '4351'""" 11611 return None 11612 def gradient(f, varargs): 11613 """ 11614 Return the gradient of an N-dimensional array. 11615 11616 The gradient is computed using central differences in the interior 11617 and first differences at the boundaries. The returned gradient hence has 11618 the same shape as the input array. 11619 11620 Parameters 11621 ---------- 11622 f : array_like 11623 An N-dimensional array containing samples of a scalar function. 11624 `*varargs` : scalars 11625 0, 1, or N scalars specifying the sample distances in each direction, 11626 that is: `dx`, `dy`, `dz`, ... The default distance is 1. 11627 11628 11629 Returns 11630 ------- 11631 gradient : ndarray 11632 N arrays of the same shape as `f` giving the derivative of `f` with 11633 respect to each dimension. 11634 11635 Examples 11636 -------- 11637 >>> x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float) 11638 >>> np.gradient(x) 11639 array([ 1. , 1.5, 2.5, 3.5, 4.5, 5. ]) 11640 >>> np.gradient(x, 2) 11641 array([ 0.5 , 0.75, 1.25, 1.75, 2.25, 2.5 ]) 11642 11643 >>> np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float)) 11644 [array([[ 2., 2., -1.], 11645 [ 2., 2., -1.]]), 11646 array([[ 1. , 2.5, 4. ], 11647 [ 1. , 1. , 1. ]])] 11648 11649 """ 11650 return ndarray() 11651 def greater(x1, x2, out=None): 11652 """greater(x1, x2[, out]) 11653 11654 Return the truth value of (x1 > x2) element-wise. 11655 11656 Parameters 11657 ---------- 11658 x1, x2 : array_like 11659 Input arrays. If ``x1.shape != x2.shape``, they must be 11660 broadcastable to a common shape (which may be the shape of one or 11661 the other). 11662 11663 Returns 11664 ------- 11665 out : bool or ndarray of bool 11666 Array of bools, or a single bool if `x1` and `x2` are scalars. 11667 11668 11669 See Also 11670 -------- 11671 greater_equal, less, less_equal, equal, not_equal 11672 11673 Examples 11674 -------- 11675 >>> np.greater([4,2],[2,2]) 11676 array([ True, False], dtype=bool) 11677 11678 If the inputs are ndarrays, then np.greater is equivalent to '>'. 11679 11680 >>> a = np.array([4,2]) 11681 >>> b = np.array([2,2]) 11682 >>> a > b 11683 array([ True, False], dtype=bool)""" 11684 return bool() if False else ndarray() 11685 def greater_equal(x1, x2, out=None): 11686 """greater_equal(x1, x2[, out]) 11687 11688 Return the truth value of (x1 >= x2) element-wise. 11689 11690 Parameters 11691 ---------- 11692 x1, x2 : array_like 11693 Input arrays. If ``x1.shape != x2.shape``, they must be 11694 broadcastable to a common shape (which may be the shape of one or 11695 the other). 11696 11697 Returns 11698 ------- 11699 out : bool or ndarray of bool 11700 Array of bools, or a single bool if `x1` and `x2` are scalars. 11701 11702 See Also 11703 -------- 11704 greater, less, less_equal, equal, not_equal 11705 11706 Examples 11707 -------- 11708 >>> np.greater_equal([4, 2, 1], [2, 2, 2]) 11709 array([ True, True, False], dtype=bool)""" 11710 return bool() if False else ndarray() 11711 class float16: 11712 T = getset_descriptor() 11713 __array_interface__ = getset_descriptor() 11714 __array_priority__ = getset_descriptor() 11715 __array_struct__ = getset_descriptor() 11716 __doc__ = None 11717 base = getset_descriptor() 11718 def conj(self, _): 11719 """None""" 11720 return None 11721 data = getset_descriptor() 11722 dtype = getset_descriptor() 11723 flags = getset_descriptor() 11724 flat = getset_descriptor() 11725 imag = getset_descriptor() 11726 itemsize = getset_descriptor() 11727 nbytes = getset_descriptor() 11728 ndim = getset_descriptor() 11729 def newbyteorder(self, new_order): 11730 """newbyteorder(new_order='S') 11731 11732 Return a new `dtype` with a different byte order. 11733 11734 Changes are also made in all fields and sub-arrays of the data type. 11735 11736 The `new_order` code can be any from the following: 11737 11738 * {'<', 'L'} - little endian 11739 * {'>', 'B'} - big endian 11740 * {'=', 'N'} - native order 11741 * 'S' - swap dtype from current to opposite endian 11742 * {'|', 'I'} - ignore (no change to byte order) 11743 11744 Parameters 11745 ---------- 11746 new_order : str, optional 11747 Byte order to force; a value from the byte order specifications 11748 above. The default value ('S') results in swapping the current 11749 byte order. The code does a case-insensitive check on the first 11750 letter of `new_order` for the alternatives above. For example, 11751 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 11752 11753 11754 Returns 11755 ------- 11756 new_dtype : dtype 11757 New `dtype` object with the given change to the byte order.""" 11758 return dtype() 11759 real = getset_descriptor() 11760 shape = getset_descriptor() 11761 size = getset_descriptor() 11762 strides = getset_descriptor() 11763 def hamming(M): 11764 """ 11765 Return the Hamming window. 11766 11767 The Hamming window is a taper formed by using a weighted cosine. 11768 11769 Parameters 11770 ---------- 11771 M : int 11772 Number of points in the output window. If zero or less, an 11773 empty array is returned. 11774 11775 Returns 11776 ------- 11777 out : ndarray 11778 The window, with the maximum value normalized to one (the value 11779 one appears only if the number of samples is odd). 11780 11781 See Also 11782 -------- 11783 bartlett, blackman, hanning, kaiser 11784 11785 Notes 11786 ----- 11787 The Hamming window is defined as 11788 11789 .. math:: w(n) = 0.54 - 0.46cos\left(\frac{2\pi{n}}{M-1}\right) 11790 \qquad 0 \leq n \leq M-1 11791 11792 The Hamming was named for R. W. Hamming, an associate of J. W. Tukey and 11793 is described in Blackman and Tukey. It was recommended for smoothing the 11794 truncated autocovariance function in the time domain. 11795 Most references to the Hamming window come from the signal processing 11796 literature, where it is used as one of many windowing functions for 11797 smoothing values. It is also known as an apodization (which means 11798 "removing the foot", i.e. smoothing discontinuities at the beginning 11799 and end of the sampled signal) or tapering function. 11800 11801 References 11802 ---------- 11803 .. [1] Blackman, R.B. and Tukey, J.W., (1958) The measurement of power 11804 spectra, Dover Publications, New York. 11805 .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics", The 11806 University of Alberta Press, 1975, pp. 109-110. 11807 .. [3] Wikipedia, "Window function", 11808 http://en.wikipedia.org/wiki/Window_function 11809 .. [4] W.H. Press, B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling, 11810 "Numerical Recipes", Cambridge University Press, 1986, page 425. 11811 11812 Examples 11813 -------- 11814 >>> np.hamming(12) 11815 array([ 0.08 , 0.15302337, 0.34890909, 0.60546483, 0.84123594, 11816 0.98136677, 0.98136677, 0.84123594, 0.60546483, 0.34890909, 11817 0.15302337, 0.08 ]) 11818 11819 Plot the window and the frequency response: 11820 11821 >>> from numpy.fft import fft, fftshift 11822 >>> window = np.hamming(51) 11823 >>> plt.plot(window) 11824 [<matplotlib.lines.Line2D object at 0x...>] 11825 >>> plt.title("Hamming window") 11826 <matplotlib.text.Text object at 0x...> 11827 >>> plt.ylabel("Amplitude") 11828 <matplotlib.text.Text object at 0x...> 11829 >>> plt.xlabel("Sample") 11830 <matplotlib.text.Text object at 0x...> 11831 >>> plt.show() 11832 11833 >>> plt.figure() 11834 <matplotlib.figure.Figure object at 0x...> 11835 >>> A = fft(window, 2048) / 25.5 11836 >>> mag = np.abs(fftshift(A)) 11837 >>> freq = np.linspace(-0.5, 0.5, len(A)) 11838 >>> response = 20 * np.log10(mag) 11839 >>> response = np.clip(response, -100, 100) 11840 >>> plt.plot(freq, response) 11841 [<matplotlib.lines.Line2D object at 0x...>] 11842 >>> plt.title("Frequency response of Hamming window") 11843 <matplotlib.text.Text object at 0x...> 11844 >>> plt.ylabel("Magnitude [dB]") 11845 <matplotlib.text.Text object at 0x...> 11846 >>> plt.xlabel("Normalized frequency [cycles per sample]") 11847 <matplotlib.text.Text object at 0x...> 11848 >>> plt.axis('tight') 11849 (-0.5, 0.5, -100.0, ...) 11850 >>> plt.show() 11851 11852 """ 11853 return ndarray() 11854 def hanning(M): 11855 """ 11856 Return the Hanning window. 11857 11858 The Hanning window is a taper formed by using a weighted cosine. 11859 11860 Parameters 11861 ---------- 11862 M : int 11863 Number of points in the output window. If zero or less, an 11864 empty array is returned. 11865 11866 Returns 11867 ------- 11868 out : ndarray, shape(M,) 11869 The window, with the maximum value normalized to one (the value 11870 one appears only if `M` is odd). 11871 11872 See Also 11873 -------- 11874 bartlett, blackman, hamming, kaiser 11875 11876 Notes 11877 ----- 11878 The Hanning window is defined as 11879 11880 .. math:: w(n) = 0.5 - 0.5cos\left(\frac{2\pi{n}}{M-1}\right) 11881 \qquad 0 \leq n \leq M-1 11882 11883 The Hanning was named for Julius van Hann, an Austrian meterologist. It is 11884 also known as the Cosine Bell. Some authors prefer that it be called a 11885 Hann window, to help avoid confusion with the very similar Hamming window. 11886 11887 Most references to the Hanning window come from the signal processing 11888 literature, where it is used as one of many windowing functions for 11889 smoothing values. It is also known as an apodization (which means 11890 "removing the foot", i.e. smoothing discontinuities at the beginning 11891 and end of the sampled signal) or tapering function. 11892 11893 References 11894 ---------- 11895 .. [1] Blackman, R.B. and Tukey, J.W., (1958) The measurement of power 11896 spectra, Dover Publications, New York. 11897 .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics", 11898 The University of Alberta Press, 1975, pp. 106-108. 11899 .. [3] Wikipedia, "Window function", 11900 http://en.wikipedia.org/wiki/Window_function 11901 .. [4] W.H. Press, B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling, 11902 "Numerical Recipes", Cambridge University Press, 1986, page 425. 11903 11904 Examples 11905 -------- 11906 >>> np.hanning(12) 11907 array([ 0. , 0.07937323, 0.29229249, 0.57115742, 0.82743037, 11908 0.97974649, 0.97974649, 0.82743037, 0.57115742, 0.29229249, 11909 0.07937323, 0. ]) 11910 11911 Plot the window and its frequency response: 11912 11913 >>> from numpy.fft import fft, fftshift 11914 >>> window = np.hanning(51) 11915 >>> plt.plot(window) 11916 [<matplotlib.lines.Line2D object at 0x...>] 11917 >>> plt.title("Hann window") 11918 <matplotlib.text.Text object at 0x...> 11919 >>> plt.ylabel("Amplitude") 11920 <matplotlib.text.Text object at 0x...> 11921 >>> plt.xlabel("Sample") 11922 <matplotlib.text.Text object at 0x...> 11923 >>> plt.show() 11924 11925 >>> plt.figure() 11926 <matplotlib.figure.Figure object at 0x...> 11927 >>> A = fft(window, 2048) / 25.5 11928 >>> mag = np.abs(fftshift(A)) 11929 >>> freq = np.linspace(-0.5, 0.5, len(A)) 11930 >>> response = 20 * np.log10(mag) 11931 >>> response = np.clip(response, -100, 100) 11932 >>> plt.plot(freq, response) 11933 [<matplotlib.lines.Line2D object at 0x...>] 11934 >>> plt.title("Frequency response of the Hann window") 11935 <matplotlib.text.Text object at 0x...> 11936 >>> plt.ylabel("Magnitude [dB]") 11937 <matplotlib.text.Text object at 0x...> 11938 >>> plt.xlabel("Normalized frequency [cycles per sample]") 11939 <matplotlib.text.Text object at 0x...> 11940 >>> plt.axis('tight') 11941 (-0.5, 0.5, -100.0, ...) 11942 >>> plt.show() 11943 11944 """ 11945 return ndarray() 11946 def histogram(a=None, bins=10, range=None, normed=False, weights=None, density=None): 11947 """ 11948 Compute the histogram of a set of data. 11949 11950 Parameters 11951 ---------- 11952 a : array_like 11953 Input data. The histogram is computed over the flattened array. 11954 bins : int or sequence of scalars, optional 11955 If `bins` is an int, it defines the number of equal-width 11956 bins in the given range (10, by default). If `bins` is a sequence, 11957 it defines the bin edges, including the rightmost edge, allowing 11958 for non-uniform bin widths. 11959 range : (float, float), optional 11960 The lower and upper range of the bins. If not provided, range 11961 is simply ``(a.min(), a.max())``. Values outside the range are 11962 ignored. 11963 normed : bool, optional 11964 This keyword is deprecated in Numpy 1.6 due to confusing/buggy 11965 behavior. It will be removed in Numpy 2.0. Use the density keyword 11966 instead. 11967 If False, the result will contain the number of samples 11968 in each bin. If True, the result is the value of the 11969 probability *density* function at the bin, normalized such that 11970 the *integral* over the range is 1. Note that this latter behavior is 11971 known to be buggy with unequal bin widths; use `density` instead. 11972 weights : array_like, optional 11973 An array of weights, of the same shape as `a`. Each value in `a` 11974 only contributes its associated weight towards the bin count 11975 (instead of 1). If `normed` is True, the weights are normalized, 11976 so that the integral of the density over the range remains 1 11977 density : bool, optional 11978 If False, the result will contain the number of samples 11979 in each bin. If True, the result is the value of the 11980 probability *density* function at the bin, normalized such that 11981 the *integral* over the range is 1. Note that the sum of the 11982 histogram values will not be equal to 1 unless bins of unity 11983 width are chosen; it is not a probability *mass* function. 11984 Overrides the `normed` keyword if given. 11985 11986 Returns 11987 ------- 11988 hist : array 11989 The values of the histogram. See `normed` and `weights` for a 11990 description of the possible semantics. 11991 bin_edges : array of dtype float 11992 Return the bin edges ``(length(hist)+1)``. 11993 11994 11995 See Also 11996 -------- 11997 histogramdd, bincount, searchsorted, digitize 11998 11999 Notes 12000 ----- 12001 All but the last (righthand-most) bin is half-open. In other words, if 12002 `bins` is:: 12003 12004 [1, 2, 3, 4] 12005 12006 then the first bin is ``[1, 2)`` (including 1, but excluding 2) and the 12007 second ``[2, 3)``. The last bin, however, is ``[3, 4]``, which *includes* 12008 4. 12009 12010 Examples 12011 -------- 12012 >>> np.histogram([1, 2, 1], bins=[0, 1, 2, 3]) 12013 (array([0, 2, 1]), array([0, 1, 2, 3])) 12014 >>> np.histogram(np.arange(4), bins=np.arange(5), density=True) 12015 (array([ 0.25, 0.25, 0.25, 0.25]), array([0, 1, 2, 3, 4])) 12016 >>> np.histogram([[1, 2, 1], [1, 0, 1]], bins=[0,1,2,3]) 12017 (array([1, 4, 1]), array([0, 1, 2, 3])) 12018 12019 >>> a = np.arange(5) 12020 >>> hist, bin_edges = np.histogram(a, density=True) 12021 >>> hist 12022 array([ 0.5, 0. , 0.5, 0. , 0. , 0.5, 0. , 0.5, 0. , 0.5]) 12023 >>> hist.sum() 12024 2.4999999999999996 12025 >>> np.sum(hist*np.diff(bin_edges)) 12026 1.0 12027 12028 """ 12029 return array() 12030 def histogram2d(x, y=None, bins=10, range=None, normed=False, weights=None): 12031 """ 12032 Compute the bi-dimensional histogram of two data samples. 12033 12034 Parameters 12035 ---------- 12036 x : array_like, shape (N,) 12037 An array containing the x coordinates of the points to be histogrammed. 12038 y : array_like, shape (N,) 12039 An array containing the y coordinates of the points to be histogrammed. 12040 bins : int or [int, int] or array_like or [array, array], optional 12041 The bin specification: 12042 12043 * If int, the number of bins for the two dimensions (nx=ny=bins). 12044 * If [int, int], the number of bins in each dimension (nx, ny = bins). 12045 * If array_like, the bin edges for the two dimensions 12046 (x_edges=y_edges=bins). 12047 * If [array, array], the bin edges in each dimension 12048 (x_edges, y_edges = bins). 12049 12050 range : array_like, shape(2,2), optional 12051 The leftmost and rightmost edges of the bins along each dimension 12052 (if not specified explicitly in the `bins` parameters): 12053 ``[[xmin, xmax], [ymin, ymax]]``. All values outside of this range 12054 will be considered outliers and not tallied in the histogram. 12055 normed : bool, optional 12056 If False, returns the number of samples in each bin. If True, returns 12057 the bin density, i.e. the bin count divided by the bin area. 12058 weights : array_like, shape(N,), optional 12059 An array of values ``w_i`` weighing each sample ``(x_i, y_i)``. Weights 12060 are normalized to 1 if `normed` is True. If `normed` is False, the 12061 values of the returned histogram are equal to the sum of the weights 12062 belonging to the samples falling into each bin. 12063 12064 Returns 12065 ------- 12066 H : ndarray, shape(nx, ny) 12067 The bi-dimensional histogram of samples `x` and `y`. Values in `x` 12068 are histogrammed along the first dimension and values in `y` are 12069 histogrammed along the second dimension. 12070 xedges : ndarray, shape(nx,) 12071 The bin edges along the first dimension. 12072 yedges : ndarray, shape(ny,) 12073 The bin edges along the second dimension. 12074 12075 See Also 12076 -------- 12077 histogram : 1D histogram 12078 histogramdd : Multidimensional histogram 12079 12080 Notes 12081 ----- 12082 When `normed` is True, then the returned histogram is the sample density, 12083 defined such that: 12084 12085 .. math:: 12086 \sum_{i=0}^{nx-1} \sum_{j=0}^{ny-1} H_{i,j} \Delta x_i \Delta y_j = 1 12087 12088 where `H` is the histogram array and :math:`\Delta x_i \Delta y_i` 12089 the area of bin ``{i,j}``. 12090 12091 Please note that the histogram does not follow the Cartesian convention 12092 where `x` values are on the abcissa and `y` values on the ordinate axis. 12093 Rather, `x` is histogrammed along the first dimension of the array 12094 (vertical), and `y` along the second dimension of the array (horizontal). 12095 This ensures compatibility with `histogramdd`. 12096 12097 Examples 12098 -------- 12099 >>> import matplotlib as mpl 12100 >>> import matplotlib.pyplot as plt 12101 12102 Construct a 2D-histogram with variable bin width. First define the bin 12103 edges: 12104 12105 >>> xedges = [0, 1, 1.5, 3, 5] 12106 >>> yedges = [0, 2, 3, 4, 6] 12107 12108 Next we create a histogram H with random bin content: 12109 12110 >>> x = np.random.normal(3, 1, 100) 12111 >>> y = np.random.normal(1, 1, 100) 12112 >>> H, xedges, yedges = np.histogram2d(y, x, bins=(xedges, yedges)) 12113 12114 Or we fill the histogram H with a determined bin content: 12115 12116 >>> H = np.ones((4, 4)).cumsum().reshape(4, 4) 12117 >>> print H[::-1] # This shows the bin content in the order as plotted 12118 [[ 13. 14. 15. 16.] 12119 [ 9. 10. 11. 12.] 12120 [ 5. 6. 7. 8.] 12121 [ 1. 2. 3. 4.]] 12122 12123 Imshow can only do an equidistant representation of bins: 12124 12125 >>> fig = plt.figure(figsize=(7, 3)) 12126 >>> ax = fig.add_subplot(131) 12127 >>> ax.set_title('imshow: 12128 equidistant') 12129 >>> im = plt.imshow(H, interpolation='nearest', origin='low', 12130 extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]]) 12131 12132 pcolormesh can displaying exact bin edges: 12133 12134 >>> ax = fig.add_subplot(132) 12135 >>> ax.set_title('pcolormesh: 12136 exact bin edges') 12137 >>> X, Y = np.meshgrid(xedges, yedges) 12138 >>> ax.pcolormesh(X, Y, H) 12139 >>> ax.set_aspect('equal') 12140 12141 NonUniformImage displays exact bin edges with interpolation: 12142 12143 >>> ax = fig.add_subplot(133) 12144 >>> ax.set_title('NonUniformImage: 12145 interpolated') 12146 >>> im = mpl.image.NonUniformImage(ax, interpolation='bilinear') 12147 >>> xcenters = xedges[:-1] + 0.5 * (xedges[1:] - xedges[:-1]) 12148 >>> ycenters = yedges[:-1] + 0.5 * (yedges[1:] - yedges[:-1]) 12149 >>> im.set_data(xcenters, ycenters, H) 12150 >>> ax.images.append(im) 12151 >>> ax.set_xlim(xedges[0], xedges[-1]) 12152 >>> ax.set_ylim(yedges[0], yedges[-1]) 12153 >>> ax.set_aspect('equal') 12154 >>> plt.show() 12155 12156 """ 12157 return ndarray() 12158 def histogramdd(sample=None, bins=10, range=None, normed=False, weights=None): 12159 """ 12160 Compute the multidimensional histogram of some data. 12161 12162 Parameters 12163 ---------- 12164 sample : array_like 12165 The data to be histogrammed. It must be an (N,D) array or data 12166 that can be converted to such. The rows of the resulting array 12167 are the coordinates of points in a D dimensional polytope. 12168 bins : sequence or int, optional 12169 The bin specification: 12170 12171 * A sequence of arrays describing the bin edges along each dimension. 12172 * The number of bins for each dimension (nx, ny, ... =bins) 12173 * The number of bins for all dimensions (nx=ny=...=bins). 12174 12175 range : sequence, optional 12176 A sequence of lower and upper bin edges to be used if the edges are 12177 not given explicitely in `bins`. Defaults to the minimum and maximum 12178 values along each dimension. 12179 normed : bool, optional 12180 If False, returns the number of samples in each bin. If True, returns 12181 the bin density, ie, the bin count divided by the bin hypervolume. 12182 weights : array_like (N,), optional 12183 An array of values `w_i` weighing each sample `(x_i, y_i, z_i, ...)`. 12184 Weights are normalized to 1 if normed is True. If normed is False, the 12185 values of the returned histogram are equal to the sum of the weights 12186 belonging to the samples falling into each bin. 12187 12188 Returns 12189 ------- 12190 H : ndarray 12191 The multidimensional histogram of sample x. See normed and weights for 12192 the different possible semantics. 12193 edges : list 12194 A list of D arrays describing the bin edges for each dimension. 12195 12196 See Also 12197 -------- 12198 histogram: 1-D histogram 12199 histogram2d: 2-D histogram 12200 12201 Examples 12202 -------- 12203 >>> r = np.random.randn(100,3) 12204 >>> H, edges = np.histogramdd(r, bins = (5, 8, 4)) 12205 >>> H.shape, edges[0].size, edges[1].size, edges[2].size 12206 ((5, 8, 4), 6, 9, 5) 12207 12208 """ 12209 return ndarray() 12210 def hsplit(): 12211 """ 12212 Split an array into multiple sub-arrays horizontally (column-wise). 12213 12214 Please refer to the `split` documentation. `hsplit` is equivalent 12215 to `split` with ``axis=1``, the array is always split along the second 12216 axis regardless of the array dimension. 12217 12218 See Also 12219 -------- 12220 split : Split an array into multiple sub-arrays of equal size. 12221 12222 Examples 12223 -------- 12224 >>> x = np.arange(16.0).reshape(4, 4) 12225 >>> x 12226 array([[ 0., 1., 2., 3.], 12227 [ 4., 5., 6., 7.], 12228 [ 8., 9., 10., 11.], 12229 [ 12., 13., 14., 15.]]) 12230 >>> np.hsplit(x, 2) 12231 [array([[ 0., 1.], 12232 [ 4., 5.], 12233 [ 8., 9.], 12234 [ 12., 13.]]), 12235 array([[ 2., 3.], 12236 [ 6., 7.], 12237 [ 10., 11.], 12238 [ 14., 15.]])] 12239 >>> np.hsplit(x, np.array([3, 6])) 12240 [array([[ 0., 1., 2.], 12241 [ 4., 5., 6.], 12242 [ 8., 9., 10.], 12243 [ 12., 13., 14.]]), 12244 array([[ 3.], 12245 [ 7.], 12246 [ 11.], 12247 [ 15.]]), 12248 array([], dtype=float64)] 12249 12250 With a higher dimensional array the split is still along the second axis. 12251 12252 >>> x = np.arange(8.0).reshape(2, 2, 2) 12253 >>> x 12254 array([[[ 0., 1.], 12255 [ 2., 3.]], 12256 [[ 4., 5.], 12257 [ 6., 7.]]]) 12258 >>> np.hsplit(x, 2) 12259 [array([[[ 0., 1.]], 12260 [[ 4., 5.]]]), 12261 array([[[ 2., 3.]], 12262 [[ 6., 7.]]])] 12263 12264 """ 12265 return None 12266 def hstack(tup): 12267 """ 12268 Stack arrays in sequence horizontally (column wise). 12269 12270 Take a sequence of arrays and stack them horizontally to make 12271 a single array. Rebuild arrays divided by `hsplit`. 12272 12273 Parameters 12274 ---------- 12275 tup : sequence of ndarrays 12276 All arrays must have the same shape along all but the second axis. 12277 12278 Returns 12279 ------- 12280 stacked : ndarray 12281 The array formed by stacking the given arrays. 12282 12283 See Also 12284 -------- 12285 vstack : Stack arrays in sequence vertically (row wise). 12286 dstack : Stack arrays in sequence depth wise (along third axis). 12287 concatenate : Join a sequence of arrays together. 12288 hsplit : Split array along second axis. 12289 12290 Notes 12291 ----- 12292 Equivalent to ``np.concatenate(tup, axis=1)`` 12293 12294 Examples 12295 -------- 12296 >>> a = np.array((1,2,3)) 12297 >>> b = np.array((2,3,4)) 12298 >>> np.hstack((a,b)) 12299 array([1, 2, 3, 2, 3, 4]) 12300 >>> a = np.array([[1],[2],[3]]) 12301 >>> b = np.array([[2],[3],[4]]) 12302 >>> np.hstack((a,b)) 12303 array([[1, 2], 12304 [2, 3], 12305 [3, 4]]) 12306 12307 """ 12308 return ndarray() 12309 def hypot(x1, x2, out=None): 12310 """hypot(x1, x2[, out]) 12311 12312 Given the "legs" of a right triangle, return its hypotenuse. 12313 12314 Equivalent to ``sqrt(x1**2 + x2**2)``, element-wise. If `x1` or 12315 `x2` is scalar_like (i.e., unambiguously cast-able to a scalar type), 12316 it is broadcast for use with each element of the other argument. 12317 (See Examples) 12318 12319 Parameters 12320 ---------- 12321 x1, x2 : array_like 12322 Leg of the triangle(s). 12323 out : ndarray, optional 12324 Array into which the output is placed. Its type is preserved and it 12325 must be of the right shape to hold the output. See doc.ufuncs. 12326 12327 Returns 12328 ------- 12329 z : ndarray 12330 The hypotenuse of the triangle(s). 12331 12332 Examples 12333 -------- 12334 >>> np.hypot(3*np.ones((3, 3)), 4*np.ones((3, 3))) 12335 array([[ 5., 5., 5.], 12336 [ 5., 5., 5.], 12337 [ 5., 5., 5.]]) 12338 12339 Example showing broadcast of scalar_like argument: 12340 12341 >>> np.hypot(3*np.ones((3, 3)), [4]) 12342 array([[ 5., 5., 5.], 12343 [ 5., 5., 5.], 12344 [ 5., 5., 5.]])""" 12345 return ndarray() 12346 def i0(x): 12347 """ 12348 Modified Bessel function of the first kind, order 0. 12349 12350 Usually denoted :math:`I_0`. This function does broadcast, but will *not* 12351 "up-cast" int dtype arguments unless accompanied by at least one float or 12352 complex dtype argument (see Raises below). 12353 12354 Parameters 12355 ---------- 12356 x : array_like, dtype float or complex 12357 Argument of the Bessel function. 12358 12359 Returns 12360 ------- 12361 out : ndarray, shape = x.shape, dtype = x.dtype 12362 The modified Bessel function evaluated at each of the elements of `x`. 12363 12364 Raises 12365 ------ 12366 TypeError: array cannot be safely cast to required type 12367 If argument consists exclusively of int dtypes. 12368 12369 See Also 12370 -------- 12371 scipy.special.iv, scipy.special.ive 12372 12373 Notes 12374 ----- 12375 We use the algorithm published by Clenshaw [1]_ and referenced by 12376 Abramowitz and Stegun [2]_, for which the function domain is partitioned 12377 into the two intervals [0,8] and (8,inf), and Chebyshev polynomial 12378 expansions are employed in each interval. Relative error on the domain 12379 [0,30] using IEEE arithmetic is documented [3]_ as having a peak of 5.8e-16 12380 with an rms of 1.4e-16 (n = 30000). 12381 12382 References 12383 ---------- 12384 .. [1] C. W. Clenshaw, "Chebyshev series for mathematical functions", in 12385 *National Physical Laboratory Mathematical Tables*, vol. 5, London: 12386 Her Majesty's Stationery Office, 1962. 12387 .. [2] M. Abramowitz and I. A. Stegun, *Handbook of Mathematical 12388 Functions*, 10th printing, New York: Dover, 1964, pp. 379. 12389 http://www.math.sfu.ca/~cbm/aands/page_379.htm 12390 .. [3] http://kobesearch.cpan.org/htdocs/Math-Cephes/Math/Cephes.html 12391 12392 Examples 12393 -------- 12394 >>> np.i0([0.]) 12395 array(1.0) 12396 >>> np.i0([0., 1. + 2j]) 12397 array([ 1.00000000+0.j , 0.18785373+0.64616944j]) 12398 12399 """ 12400 return ndarray() 12401 def identity(n=None, dtype=None): 12402 """ 12403 Return the identity array. 12404 12405 The identity array is a square array with ones on 12406 the main diagonal. 12407 12408 Parameters 12409 ---------- 12410 n : int 12411 Number of rows (and columns) in `n` x `n` output. 12412 dtype : data-type, optional 12413 Data-type of the output. Defaults to ``float``. 12414 12415 Returns 12416 ------- 12417 out : ndarray 12418 `n` x `n` array with its main diagonal set to one, 12419 and all other elements 0. 12420 12421 Examples 12422 -------- 12423 >>> np.identity(3) 12424 array([[ 1., 0., 0.], 12425 [ 0., 1., 0.], 12426 [ 0., 0., 1.]]) 12427 12428 """ 12429 return ndarray() 12430 class iinfo: 12431 __dict__ = dictproxy() 12432 __doc__ = str() 12433 __module__ = str() 12434 __weakref__ = getset_descriptor() 12435 _max_vals = dict() 12436 _min_vals = dict() 12437 max = property() 12438 min = property() 12439 def imag(val): 12440 """ 12441 Return the imaginary part of the elements of the array. 12442 12443 Parameters 12444 ---------- 12445 val : array_like 12446 Input array. 12447 12448 Returns 12449 ------- 12450 out : ndarray 12451 Output array. If `val` is real, the type of `val` is used for the 12452 output. If `val` has complex elements, the returned type is float. 12453 12454 See Also 12455 -------- 12456 real, angle, real_if_close 12457 12458 Examples 12459 -------- 12460 >>> a = np.array([1+2j, 3+4j, 5+6j]) 12461 >>> a.imag 12462 array([ 2., 4., 6.]) 12463 >>> a.imag = np.array([8, 10, 12]) 12464 >>> a 12465 array([ 1. +8.j, 3.+10.j, 5.+12.j]) 12466 12467 """ 12468 return ndarray() 12469 def in1d(ar1, ar2=False, assume_unique=False, invert=False): 12470 """ 12471 Test whether each element of a 1-D array is also present in a second array. 12472 12473 Returns a boolean array the same length as `ar1` that is True 12474 where an element of `ar1` is in `ar2` and False otherwise. 12475 12476 Parameters 12477 ---------- 12478 ar1 : (M,) array_like 12479 Input array. 12480 ar2 : array_like 12481 The values against which to test each value of `ar1`. 12482 assume_unique : bool, optional 12483 If True, the input arrays are both assumed to be unique, which 12484 can speed up the calculation. Default is False. 12485 invert : bool, optional 12486 If True, the values in the returned array are inverted (that is, 12487 False where an element of `ar1` is in `ar2` and True otherwise). 12488 Default is False. ``np.in1d(a, b, invert=True)`` is equivalent 12489 to (but is faster than) ``np.invert(in1d(a, b))``. 12490 12491 .. versionadded:: 1.8.0 12492 12493 Returns 12494 ------- 12495 in1d : (M,) ndarray, bool 12496 The values `ar1[in1d]` are in `ar2`. 12497 12498 See Also 12499 -------- 12500 numpy.lib.arraysetops : Module with a number of other functions for 12501 performing set operations on arrays. 12502 12503 Notes 12504 ----- 12505 `in1d` can be considered as an element-wise function version of the 12506 python keyword `in`, for 1-D sequences. ``in1d(a, b)`` is roughly 12507 equivalent to ``np.array([item in b for item in a])``. 12508 12509 .. versionadded:: 1.4.0 12510 12511 Examples 12512 -------- 12513 >>> test = np.array([0, 1, 2, 5, 0]) 12514 >>> states = [0, 2] 12515 >>> mask = np.in1d(test, states) 12516 >>> mask 12517 array([ True, False, True, False, True], dtype=bool) 12518 >>> test[mask] 12519 array([0, 2, 0]) 12520 >>> mask = np.in1d(test, states, invert=True) 12521 >>> mask 12522 array([False, True, False, True, False], dtype=bool) 12523 >>> test[mask] 12524 array([1, 5]) 12525 """ 12526 return M() 12527 index_exp = IndexExpression() 12528 def indices(dimensions=typeint(), dtype=typeint()): 12529 """ 12530 Return an array representing the indices of a grid. 12531 12532 Compute an array where the subarrays contain index values 0,1,... 12533 varying only along the corresponding axis. 12534 12535 Parameters 12536 ---------- 12537 dimensions : sequence of ints 12538 The shape of the grid. 12539 dtype : dtype, optional 12540 Data type of the result. 12541 12542 Returns 12543 ------- 12544 grid : ndarray 12545 The array of grid indices, 12546 ``grid.shape = (len(dimensions),) + tuple(dimensions)``. 12547 12548 See Also 12549 -------- 12550 mgrid, meshgrid 12551 12552 Notes 12553 ----- 12554 The output shape is obtained by prepending the number of dimensions 12555 in front of the tuple of dimensions, i.e. if `dimensions` is a tuple 12556 ``(r0, ..., rN-1)`` of length ``N``, the output shape is 12557 ``(N,r0,...,rN-1)``. 12558 12559 The subarrays ``grid[k]`` contains the N-D array of indices along the 12560 ``k-th`` axis. Explicitly:: 12561 12562 grid[k,i0,i1,...,iN-1] = ik 12563 12564 Examples 12565 -------- 12566 >>> grid = np.indices((2, 3)) 12567 >>> grid.shape 12568 (2, 2, 3) 12569 >>> grid[0] # row indices 12570 array([[0, 0, 0], 12571 [1, 1, 1]]) 12572 >>> grid[1] # column indices 12573 array([[0, 1, 2], 12574 [0, 1, 2]]) 12575 12576 The indices can be used as an index into an array. 12577 12578 >>> x = np.arange(20).reshape(5, 4) 12579 >>> row, col = np.indices((2, 3)) 12580 >>> x[row, col] 12581 array([[0, 1, 2], 12582 [4, 5, 6]]) 12583 12584 Note that it would be more straightforward in the above example to 12585 extract the required elements directly with ``x[:2, :3]``. 12586 12587 """ 12588 return ndarray() 12589 class inexact: 12590 T = getset_descriptor() 12591 __array_interface__ = getset_descriptor() 12592 __array_priority__ = getset_descriptor() 12593 __array_struct__ = getset_descriptor() 12594 __doc__ = None 12595 base = getset_descriptor() 12596 def conj(self, _): 12597 """None""" 12598 return None 12599 data = getset_descriptor() 12600 dtype = getset_descriptor() 12601 flags = getset_descriptor() 12602 flat = getset_descriptor() 12603 imag = getset_descriptor() 12604 itemsize = getset_descriptor() 12605 nbytes = getset_descriptor() 12606 ndim = getset_descriptor() 12607 def newbyteorder(self, new_order): 12608 """newbyteorder(new_order='S') 12609 12610 Return a new `dtype` with a different byte order. 12611 12612 Changes are also made in all fields and sub-arrays of the data type. 12613 12614 The `new_order` code can be any from the following: 12615 12616 * {'<', 'L'} - little endian 12617 * {'>', 'B'} - big endian 12618 * {'=', 'N'} - native order 12619 * 'S' - swap dtype from current to opposite endian 12620 * {'|', 'I'} - ignore (no change to byte order) 12621 12622 Parameters 12623 ---------- 12624 new_order : str, optional 12625 Byte order to force; a value from the byte order specifications 12626 above. The default value ('S') results in swapping the current 12627 byte order. The code does a case-insensitive check on the first 12628 letter of `new_order` for the alternatives above. For example, 12629 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 12630 12631 12632 Returns 12633 ------- 12634 new_dtype : dtype 12635 New `dtype` object with the given change to the byte order.""" 12636 return dtype() 12637 real = getset_descriptor() 12638 shape = getset_descriptor() 12639 size = getset_descriptor() 12640 strides = getset_descriptor() 12641 inf = float() 12642 def info(object=None, maxwidth=76, output="<open file '../../documentation_files/numpy.py', mode 'w' at 0x7ff32be959c0>", toplevel="numpy"): 12643 """ 12644 Get help information for a function, class, or module. 12645 12646 Parameters 12647 ---------- 12648 object : object or str, optional 12649 Input object or name to get information about. If `object` is a 12650 numpy object, its docstring is given. If it is a string, available 12651 modules are searched for matching objects. 12652 If None, information about `info` itself is returned. 12653 maxwidth : int, optional 12654 Printing width. 12655 output : file like object, optional 12656 File like object that the output is written to, default is ``stdout``. 12657 The object has to be opened in 'w' or 'a' mode. 12658 toplevel : str, optional 12659 Start search at this level. 12660 12661 See Also 12662 -------- 12663 source, lookfor 12664 12665 Notes 12666 ----- 12667 When used interactively with an object, ``np.info(obj)`` is equivalent to 12668 ``help(obj)`` on the Python prompt or ``obj?`` on the IPython prompt. 12669 12670 Examples 12671 -------- 12672 >>> np.info(np.polyval) # doctest: +SKIP 12673 polyval(p, x) 12674 Evaluate the polynomial p at x. 12675 ... 12676 12677 When using a string for `object` it is possible to get multiple results. 12678 12679 >>> np.info('fft') # doctest: +SKIP 12680 *** Found in numpy *** 12681 Core FFT routines 12682 ... 12683 *** Found in numpy.fft *** 12684 fft(a, n=None, axis=-1) 12685 ... 12686 *** Repeat reference found in numpy.fft.fftpack *** 12687 *** Total of 3 references found. *** 12688 12689 """ 12690 return None 12691 infty = float() 12692 def inner(a, b): 12693 """inner(a, b) 12694 12695 Inner product of two arrays. 12696 12697 Ordinary inner product of vectors for 1-D arrays (without complex 12698 conjugation), in higher dimensions a sum product over the last axes. 12699 12700 Parameters 12701 ---------- 12702 a, b : array_like 12703 If `a` and `b` are nonscalar, their last dimensions of must match. 12704 12705 Returns 12706 ------- 12707 out : ndarray 12708 `out.shape = a.shape[:-1] + b.shape[:-1]` 12709 12710 Raises 12711 ------ 12712 ValueError 12713 If the last dimension of `a` and `b` has different size. 12714 12715 See Also 12716 -------- 12717 tensordot : Sum products over arbitrary axes. 12718 dot : Generalised matrix product, using second last dimension of `b`. 12719 einsum : Einstein summation convention. 12720 12721 Notes 12722 ----- 12723 For vectors (1-D arrays) it computes the ordinary inner-product:: 12724 12725 np.inner(a, b) = sum(a[:]*b[:]) 12726 12727 More generally, if `ndim(a) = r > 0` and `ndim(b) = s > 0`:: 12728 12729 np.inner(a, b) = np.tensordot(a, b, axes=(-1,-1)) 12730 12731 or explicitly:: 12732 12733 np.inner(a, b)[i0,...,ir-1,j0,...,js-1] 12734 = sum(a[i0,...,ir-1,:]*b[j0,...,js-1,:]) 12735 12736 In addition `a` or `b` may be scalars, in which case:: 12737 12738 np.inner(a,b) = a*b 12739 12740 Examples 12741 -------- 12742 Ordinary inner product for vectors: 12743 12744 >>> a = np.array([1,2,3]) 12745 >>> b = np.array([0,1,0]) 12746 >>> np.inner(a, b) 12747 2 12748 12749 A multidimensional example: 12750 12751 >>> a = np.arange(24).reshape((2,3,4)) 12752 >>> b = np.arange(4) 12753 >>> np.inner(a, b) 12754 array([[ 14, 38, 62], 12755 [ 86, 110, 134]]) 12756 12757 An example where `b` is a scalar: 12758 12759 >>> np.inner(np.eye(2), 7) 12760 array([[ 7., 0.], 12761 [ 0., 7.]])""" 12762 return ndarray() 12763 def insert(arr, obj, values=None, axis=None): 12764 """ 12765 Insert values along the given axis before the given indices. 12766 12767 Parameters 12768 ---------- 12769 arr : array_like 12770 Input array. 12771 obj : int, slice or sequence of ints 12772 Object that defines the index or indices before which `values` is 12773 inserted. 12774 12775 .. versionadded:: 1.8.0 12776 12777 Support for multiple insertions when `obj` is a single scalar or a 12778 sequence with one element (similar to calling insert multiple times). 12779 values : array_like 12780 Values to insert into `arr`. If the type of `values` is different 12781 from that of `arr`, `values` is converted to the type of `arr`. 12782 `values` should be shaped so that ``arr[...,obj,...] = values`` 12783 is legal. 12784 axis : int, optional 12785 Axis along which to insert `values`. If `axis` is None then `arr` 12786 is flattened first. 12787 12788 Returns 12789 ------- 12790 out : ndarray 12791 A copy of `arr` with `values` inserted. Note that `insert` 12792 does not occur in-place: a new array is returned. If 12793 `axis` is None, `out` is a flattened array. 12794 12795 See Also 12796 -------- 12797 append : Append elements at the end of an array. 12798 concatenate : Join a sequence of arrays together. 12799 delete : Delete elements from an array. 12800 12801 Notes 12802 ----- 12803 Note that for higher dimensional inserts `obj=0` behaves very different 12804 from `obj=[0]` just like `arr[:,0,:] = values` is different from 12805 `arr[:,[0],:] = values`. 12806 12807 Examples 12808 -------- 12809 >>> a = np.array([[1, 1], [2, 2], [3, 3]]) 12810 >>> a 12811 array([[1, 1], 12812 [2, 2], 12813 [3, 3]]) 12814 >>> np.insert(a, 1, 5) 12815 array([1, 5, 1, 2, 2, 3, 3]) 12816 >>> np.insert(a, 1, 5, axis=1) 12817 array([[1, 5, 1], 12818 [2, 5, 2], 12819 [3, 5, 3]]) 12820 12821 Difference between sequence and scalars: 12822 >>> np.insert(a, [1], [[1],[2],[3]], axis=1) 12823 array([[1, 1, 1], 12824 [2, 2, 2], 12825 [3, 3, 3]]) 12826 >>> np.array_equal(np.insert(a, 1, [1, 2, 3], axis=1), 12827 ... np.insert(a, [1], [[1],[2],[3]], axis=1)) 12828 True 12829 12830 >>> b = a.flatten() 12831 >>> b 12832 array([1, 1, 2, 2, 3, 3]) 12833 >>> np.insert(b, [2, 2], [5, 6]) 12834 array([1, 1, 5, 6, 2, 2, 3, 3]) 12835 12836 >>> np.insert(b, slice(2, 4), [5, 6]) 12837 array([1, 1, 5, 2, 6, 2, 3, 3]) 12838 12839 >>> np.insert(b, [2, 2], [7.13, False]) # type casting 12840 array([1, 1, 7, 0, 2, 2, 3, 3]) 12841 12842 >>> x = np.arange(8).reshape(2, 4) 12843 >>> idx = (1, 3) 12844 >>> np.insert(x, idx, 999, axis=1) 12845 array([[ 0, 999, 1, 2, 999, 3], 12846 [ 4, 999, 5, 6, 999, 7]]) 12847 12848 """ 12849 return ndarray() 12850 class int: 12851 __doc__ = str() 12852 def bit_length(self, _): 12853 """int.bit_length() -> int 12854 12855 Number of bits necessary to represent self in binary. 12856 >>> bin(37) 12857 '0b100101' 12858 >>> (37).bit_length() 12859 6""" 12860 return None 12861 def conjugate(self, _): 12862 """Returns self, the complex conjugate of any int.""" 12863 return None 12864 denominator = getset_descriptor() 12865 imag = getset_descriptor() 12866 numerator = getset_descriptor() 12867 real = getset_descriptor() 12868 class int64: 12869 T = getset_descriptor() 12870 __array_interface__ = getset_descriptor() 12871 __array_priority__ = getset_descriptor() 12872 __array_struct__ = getset_descriptor() 12873 __doc__ = str() 12874 base = getset_descriptor() 12875 def bit_length(self, _): 12876 """int.bit_length() -> int 12877 12878 Number of bits necessary to represent self in binary. 12879 >>> bin(37) 12880 '0b100101' 12881 >>> (37).bit_length() 12882 6""" 12883 return None 12884 def conj(self, _): 12885 """None""" 12886 return None 12887 data = getset_descriptor() 12888 denominator = getset_descriptor() 12889 dtype = getset_descriptor() 12890 flags = getset_descriptor() 12891 flat = getset_descriptor() 12892 imag = getset_descriptor() 12893 itemsize = getset_descriptor() 12894 nbytes = getset_descriptor() 12895 ndim = getset_descriptor() 12896 def newbyteorder(self, new_order): 12897 """newbyteorder(new_order='S') 12898 12899 Return a new `dtype` with a different byte order. 12900 12901 Changes are also made in all fields and sub-arrays of the data type. 12902 12903 The `new_order` code can be any from the following: 12904 12905 * {'<', 'L'} - little endian 12906 * {'>', 'B'} - big endian 12907 * {'=', 'N'} - native order 12908 * 'S' - swap dtype from current to opposite endian 12909 * {'|', 'I'} - ignore (no change to byte order) 12910 12911 Parameters 12912 ---------- 12913 new_order : str, optional 12914 Byte order to force; a value from the byte order specifications 12915 above. The default value ('S') results in swapping the current 12916 byte order. The code does a case-insensitive check on the first 12917 letter of `new_order` for the alternatives above. For example, 12918 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 12919 12920 12921 Returns 12922 ------- 12923 new_dtype : dtype 12924 New `dtype` object with the given change to the byte order.""" 12925 return dtype() 12926 numerator = getset_descriptor() 12927 real = getset_descriptor() 12928 shape = getset_descriptor() 12929 size = getset_descriptor() 12930 strides = getset_descriptor() 12931 class int16: 12932 T = getset_descriptor() 12933 __array_interface__ = getset_descriptor() 12934 __array_priority__ = getset_descriptor() 12935 __array_struct__ = getset_descriptor() 12936 __doc__ = str() 12937 base = getset_descriptor() 12938 def conj(self, _): 12939 """None""" 12940 return None 12941 data = getset_descriptor() 12942 dtype = getset_descriptor() 12943 flags = getset_descriptor() 12944 flat = getset_descriptor() 12945 imag = getset_descriptor() 12946 itemsize = getset_descriptor() 12947 nbytes = getset_descriptor() 12948 ndim = getset_descriptor() 12949 def newbyteorder(self, new_order): 12950 """newbyteorder(new_order='S') 12951 12952 Return a new `dtype` with a different byte order. 12953 12954 Changes are also made in all fields and sub-arrays of the data type. 12955 12956 The `new_order` code can be any from the following: 12957 12958 * {'<', 'L'} - little endian 12959 * {'>', 'B'} - big endian 12960 * {'=', 'N'} - native order 12961 * 'S' - swap dtype from current to opposite endian 12962 * {'|', 'I'} - ignore (no change to byte order) 12963 12964 Parameters 12965 ---------- 12966 new_order : str, optional 12967 Byte order to force; a value from the byte order specifications 12968 above. The default value ('S') results in swapping the current 12969 byte order. The code does a case-insensitive check on the first 12970 letter of `new_order` for the alternatives above. For example, 12971 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 12972 12973 12974 Returns 12975 ------- 12976 new_dtype : dtype 12977 New `dtype` object with the given change to the byte order.""" 12978 return dtype() 12979 real = getset_descriptor() 12980 shape = getset_descriptor() 12981 size = getset_descriptor() 12982 strides = getset_descriptor() 12983 class int32: 12984 T = getset_descriptor() 12985 __array_interface__ = getset_descriptor() 12986 __array_priority__ = getset_descriptor() 12987 __array_struct__ = getset_descriptor() 12988 __doc__ = str() 12989 base = getset_descriptor() 12990 def conj(self, _): 12991 """None""" 12992 return None 12993 data = getset_descriptor() 12994 dtype = getset_descriptor() 12995 flags = getset_descriptor() 12996 flat = getset_descriptor() 12997 imag = getset_descriptor() 12998 itemsize = getset_descriptor() 12999 nbytes = getset_descriptor() 13000 ndim = getset_descriptor() 13001 def newbyteorder(self, new_order): 13002 """newbyteorder(new_order='S') 13003 13004 Return a new `dtype` with a different byte order. 13005 13006 Changes are also made in all fields and sub-arrays of the data type. 13007 13008 The `new_order` code can be any from the following: 13009 13010 * {'<', 'L'} - little endian 13011 * {'>', 'B'} - big endian 13012 * {'=', 'N'} - native order 13013 * 'S' - swap dtype from current to opposite endian 13014 * {'|', 'I'} - ignore (no change to byte order) 13015 13016 Parameters 13017 ---------- 13018 new_order : str, optional 13019 Byte order to force; a value from the byte order specifications 13020 above. The default value ('S') results in swapping the current 13021 byte order. The code does a case-insensitive check on the first 13022 letter of `new_order` for the alternatives above. For example, 13023 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 13024 13025 13026 Returns 13027 ------- 13028 new_dtype : dtype 13029 New `dtype` object with the given change to the byte order.""" 13030 return dtype() 13031 real = getset_descriptor() 13032 shape = getset_descriptor() 13033 size = getset_descriptor() 13034 strides = getset_descriptor() 13035 class int64: 13036 T = getset_descriptor() 13037 __array_interface__ = getset_descriptor() 13038 __array_priority__ = getset_descriptor() 13039 __array_struct__ = getset_descriptor() 13040 __doc__ = str() 13041 base = getset_descriptor() 13042 def bit_length(self, _): 13043 """int.bit_length() -> int 13044 13045 Number of bits necessary to represent self in binary. 13046 >>> bin(37) 13047 '0b100101' 13048 >>> (37).bit_length() 13049 6""" 13050 return None 13051 def conj(self, _): 13052 """None""" 13053 return None 13054 data = getset_descriptor() 13055 denominator = getset_descriptor() 13056 dtype = getset_descriptor() 13057 flags = getset_descriptor() 13058 flat = getset_descriptor() 13059 imag = getset_descriptor() 13060 itemsize = getset_descriptor() 13061 nbytes = getset_descriptor() 13062 ndim = getset_descriptor() 13063 def newbyteorder(self, new_order): 13064 """newbyteorder(new_order='S') 13065 13066 Return a new `dtype` with a different byte order. 13067 13068 Changes are also made in all fields and sub-arrays of the data type. 13069 13070 The `new_order` code can be any from the following: 13071 13072 * {'<', 'L'} - little endian 13073 * {'>', 'B'} - big endian 13074 * {'=', 'N'} - native order 13075 * 'S' - swap dtype from current to opposite endian 13076 * {'|', 'I'} - ignore (no change to byte order) 13077 13078 Parameters 13079 ---------- 13080 new_order : str, optional 13081 Byte order to force; a value from the byte order specifications 13082 above. The default value ('S') results in swapping the current 13083 byte order. The code does a case-insensitive check on the first 13084 letter of `new_order` for the alternatives above. For example, 13085 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 13086 13087 13088 Returns 13089 ------- 13090 new_dtype : dtype 13091 New `dtype` object with the given change to the byte order.""" 13092 return dtype() 13093 numerator = getset_descriptor() 13094 real = getset_descriptor() 13095 shape = getset_descriptor() 13096 size = getset_descriptor() 13097 strides = getset_descriptor() 13098 class int8: 13099 T = getset_descriptor() 13100 __array_interface__ = getset_descriptor() 13101 __array_priority__ = getset_descriptor() 13102 __array_struct__ = getset_descriptor() 13103 __doc__ = str() 13104 base = getset_descriptor() 13105 def conj(self, _): 13106 """None""" 13107 return None 13108 data = getset_descriptor() 13109 dtype = getset_descriptor() 13110 flags = getset_descriptor() 13111 flat = getset_descriptor() 13112 imag = getset_descriptor() 13113 itemsize = getset_descriptor() 13114 nbytes = getset_descriptor() 13115 ndim = getset_descriptor() 13116 def newbyteorder(self, new_order): 13117 """newbyteorder(new_order='S') 13118 13119 Return a new `dtype` with a different byte order. 13120 13121 Changes are also made in all fields and sub-arrays of the data type. 13122 13123 The `new_order` code can be any from the following: 13124 13125 * {'<', 'L'} - little endian 13126 * {'>', 'B'} - big endian 13127 * {'=', 'N'} - native order 13128 * 'S' - swap dtype from current to opposite endian 13129 * {'|', 'I'} - ignore (no change to byte order) 13130 13131 Parameters 13132 ---------- 13133 new_order : str, optional 13134 Byte order to force; a value from the byte order specifications 13135 above. The default value ('S') results in swapping the current 13136 byte order. The code does a case-insensitive check on the first 13137 letter of `new_order` for the alternatives above. For example, 13138 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 13139 13140 13141 Returns 13142 ------- 13143 new_dtype : dtype 13144 New `dtype` object with the given change to the byte order.""" 13145 return dtype() 13146 real = getset_descriptor() 13147 shape = getset_descriptor() 13148 size = getset_descriptor() 13149 strides = getset_descriptor() 13150 class int64: 13151 T = getset_descriptor() 13152 __array_interface__ = getset_descriptor() 13153 __array_priority__ = getset_descriptor() 13154 __array_struct__ = getset_descriptor() 13155 __doc__ = str() 13156 base = getset_descriptor() 13157 def bit_length(self, _): 13158 """int.bit_length() -> int 13159 13160 Number of bits necessary to represent self in binary. 13161 >>> bin(37) 13162 '0b100101' 13163 >>> (37).bit_length() 13164 6""" 13165 return None 13166 def conj(self, _): 13167 """None""" 13168 return None 13169 data = getset_descriptor() 13170 denominator = getset_descriptor() 13171 dtype = getset_descriptor() 13172 flags = getset_descriptor() 13173 flat = getset_descriptor() 13174 imag = getset_descriptor() 13175 itemsize = getset_descriptor() 13176 nbytes = getset_descriptor() 13177 ndim = getset_descriptor() 13178 def newbyteorder(self, new_order): 13179 """newbyteorder(new_order='S') 13180 13181 Return a new `dtype` with a different byte order. 13182 13183 Changes are also made in all fields and sub-arrays of the data type. 13184 13185 The `new_order` code can be any from the following: 13186 13187 * {'<', 'L'} - little endian 13188 * {'>', 'B'} - big endian 13189 * {'=', 'N'} - native order 13190 * 'S' - swap dtype from current to opposite endian 13191 * {'|', 'I'} - ignore (no change to byte order) 13192 13193 Parameters 13194 ---------- 13195 new_order : str, optional 13196 Byte order to force; a value from the byte order specifications 13197 above. The default value ('S') results in swapping the current 13198 byte order. The code does a case-insensitive check on the first 13199 letter of `new_order` for the alternatives above. For example, 13200 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 13201 13202 13203 Returns 13204 ------- 13205 new_dtype : dtype 13206 New `dtype` object with the given change to the byte order.""" 13207 return dtype() 13208 numerator = getset_descriptor() 13209 real = getset_descriptor() 13210 shape = getset_descriptor() 13211 size = getset_descriptor() 13212 strides = getset_descriptor() 13213 def int_asbuffer(): 13214 """None""" 13215 return None 13216 class int32: 13217 T = getset_descriptor() 13218 __array_interface__ = getset_descriptor() 13219 __array_priority__ = getset_descriptor() 13220 __array_struct__ = getset_descriptor() 13221 __doc__ = str() 13222 base = getset_descriptor() 13223 def conj(self, _): 13224 """None""" 13225 return None 13226 data = getset_descriptor() 13227 dtype = getset_descriptor() 13228 flags = getset_descriptor() 13229 flat = getset_descriptor() 13230 imag = getset_descriptor() 13231 itemsize = getset_descriptor() 13232 nbytes = getset_descriptor() 13233 ndim = getset_descriptor() 13234 def newbyteorder(self, new_order): 13235 """newbyteorder(new_order='S') 13236 13237 Return a new `dtype` with a different byte order. 13238 13239 Changes are also made in all fields and sub-arrays of the data type. 13240 13241 The `new_order` code can be any from the following: 13242 13243 * {'<', 'L'} - little endian 13244 * {'>', 'B'} - big endian 13245 * {'=', 'N'} - native order 13246 * 'S' - swap dtype from current to opposite endian 13247 * {'|', 'I'} - ignore (no change to byte order) 13248 13249 Parameters 13250 ---------- 13251 new_order : str, optional 13252 Byte order to force; a value from the byte order specifications 13253 above. The default value ('S') results in swapping the current 13254 byte order. The code does a case-insensitive check on the first 13255 letter of `new_order` for the alternatives above. For example, 13256 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 13257 13258 13259 Returns 13260 ------- 13261 new_dtype : dtype 13262 New `dtype` object with the given change to the byte order.""" 13263 return dtype() 13264 real = getset_descriptor() 13265 shape = getset_descriptor() 13266 size = getset_descriptor() 13267 strides = getset_descriptor() 13268 class integer: 13269 T = getset_descriptor() 13270 __array_interface__ = getset_descriptor() 13271 __array_priority__ = getset_descriptor() 13272 __array_struct__ = getset_descriptor() 13273 __doc__ = None 13274 base = getset_descriptor() 13275 def conj(self, _): 13276 """None""" 13277 return None 13278 data = getset_descriptor() 13279 dtype = getset_descriptor() 13280 flags = getset_descriptor() 13281 flat = getset_descriptor() 13282 imag = getset_descriptor() 13283 itemsize = getset_descriptor() 13284 nbytes = getset_descriptor() 13285 ndim = getset_descriptor() 13286 def newbyteorder(self, new_order): 13287 """newbyteorder(new_order='S') 13288 13289 Return a new `dtype` with a different byte order. 13290 13291 Changes are also made in all fields and sub-arrays of the data type. 13292 13293 The `new_order` code can be any from the following: 13294 13295 * {'<', 'L'} - little endian 13296 * {'>', 'B'} - big endian 13297 * {'=', 'N'} - native order 13298 * 'S' - swap dtype from current to opposite endian 13299 * {'|', 'I'} - ignore (no change to byte order) 13300 13301 Parameters 13302 ---------- 13303 new_order : str, optional 13304 Byte order to force; a value from the byte order specifications 13305 above. The default value ('S') results in swapping the current 13306 byte order. The code does a case-insensitive check on the first 13307 letter of `new_order` for the alternatives above. For example, 13308 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 13309 13310 13311 Returns 13312 ------- 13313 new_dtype : dtype 13314 New `dtype` object with the given change to the byte order.""" 13315 return dtype() 13316 real = getset_descriptor() 13317 shape = getset_descriptor() 13318 size = getset_descriptor() 13319 strides = getset_descriptor() 13320 def interp(x, xp, fp=None, left=None, right=None): 13321 """ 13322 One-dimensional linear interpolation. 13323 13324 Returns the one-dimensional piecewise linear interpolant to a function 13325 with given values at discrete data-points. 13326 13327 Parameters 13328 ---------- 13329 x : array_like 13330 The x-coordinates of the interpolated values. 13331 13332 xp : 1-D sequence of floats 13333 The x-coordinates of the data points, must be increasing. 13334 13335 fp : 1-D sequence of floats 13336 The y-coordinates of the data points, same length as `xp`. 13337 13338 left : float, optional 13339 Value to return for `x < xp[0]`, default is `fp[0]`. 13340 13341 right : float, optional 13342 Value to return for `x > xp[-1]`, defaults is `fp[-1]`. 13343 13344 Returns 13345 ------- 13346 y : {float, ndarray} 13347 The interpolated values, same shape as `x`. 13348 13349 Raises 13350 ------ 13351 ValueError 13352 If `xp` and `fp` have different length 13353 13354 Notes 13355 ----- 13356 Does not check that the x-coordinate sequence `xp` is increasing. 13357 If `xp` is not increasing, the results are nonsense. 13358 A simple check for increasingness is:: 13359 13360 np.all(np.diff(xp) > 0) 13361 13362 13363 Examples 13364 -------- 13365 >>> xp = [1, 2, 3] 13366 >>> fp = [3, 2, 0] 13367 >>> np.interp(2.5, xp, fp) 13368 1.0 13369 >>> np.interp([0, 1, 1.5, 2.72, 3.14], xp, fp) 13370 array([ 3. , 3. , 2.5 , 0.56, 0. ]) 13371 >>> UNDEF = -99.0 13372 >>> np.interp(3.14, xp, fp, right=UNDEF) 13373 -99.0 13374 13375 Plot an interpolant to the sine function: 13376 13377 >>> x = np.linspace(0, 2*np.pi, 10) 13378 >>> y = np.sin(x) 13379 >>> xvals = np.linspace(0, 2*np.pi, 50) 13380 >>> yinterp = np.interp(xvals, x, y) 13381 >>> import matplotlib.pyplot as plt 13382 >>> plt.plot(x, y, 'o') 13383 [<matplotlib.lines.Line2D object at 0x...>] 13384 >>> plt.plot(xvals, yinterp, '-x') 13385 [<matplotlib.lines.Line2D object at 0x...>] 13386 >>> plt.show() 13387 13388 """ 13389 return float() 13390 def intersect1d(ar1, ar2=False, assume_unique=False): 13391 """ 13392 Find the intersection of two arrays. 13393 13394 Return the sorted, unique values that are in both of the input arrays. 13395 13396 Parameters 13397 ---------- 13398 ar1, ar2 : array_like 13399 Input arrays. 13400 assume_unique : bool 13401 If True, the input arrays are both assumed to be unique, which 13402 can speed up the calculation. Default is False. 13403 13404 Returns 13405 ------- 13406 intersect1d : ndarray 13407 Sorted 1D array of common and unique elements. 13408 13409 See Also 13410 -------- 13411 numpy.lib.arraysetops : Module with a number of other functions for 13412 performing set operations on arrays. 13413 13414 Examples 13415 -------- 13416 >>> np.intersect1d([1, 3, 4, 3], [3, 1, 2, 1]) 13417 array([1, 3]) 13418 13419 """ 13420 return ndarray() 13421 class int64: 13422 T = getset_descriptor() 13423 __array_interface__ = getset_descriptor() 13424 __array_priority__ = getset_descriptor() 13425 __array_struct__ = getset_descriptor() 13426 __doc__ = str() 13427 base = getset_descriptor() 13428 def bit_length(self, _): 13429 """int.bit_length() -> int 13430 13431 Number of bits necessary to represent self in binary. 13432 >>> bin(37) 13433 '0b100101' 13434 >>> (37).bit_length() 13435 6""" 13436 return None 13437 def conj(self, _): 13438 """None""" 13439 return None 13440 data = getset_descriptor() 13441 denominator = getset_descriptor() 13442 dtype = getset_descriptor() 13443 flags = getset_descriptor() 13444 flat = getset_descriptor() 13445 imag = getset_descriptor() 13446 itemsize = getset_descriptor() 13447 nbytes = getset_descriptor() 13448 ndim = getset_descriptor() 13449 def newbyteorder(self, new_order): 13450 """newbyteorder(new_order='S') 13451 13452 Return a new `dtype` with a different byte order. 13453 13454 Changes are also made in all fields and sub-arrays of the data type. 13455 13456 The `new_order` code can be any from the following: 13457 13458 * {'<', 'L'} - little endian 13459 * {'>', 'B'} - big endian 13460 * {'=', 'N'} - native order 13461 * 'S' - swap dtype from current to opposite endian 13462 * {'|', 'I'} - ignore (no change to byte order) 13463 13464 Parameters 13465 ---------- 13466 new_order : str, optional 13467 Byte order to force; a value from the byte order specifications 13468 above. The default value ('S') results in swapping the current 13469 byte order. The code does a case-insensitive check on the first 13470 letter of `new_order` for the alternatives above. For example, 13471 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 13472 13473 13474 Returns 13475 ------- 13476 new_dtype : dtype 13477 New `dtype` object with the given change to the byte order.""" 13478 return dtype() 13479 numerator = getset_descriptor() 13480 real = getset_descriptor() 13481 shape = getset_descriptor() 13482 size = getset_descriptor() 13483 strides = getset_descriptor() 13484 def invert(x, out=None): 13485 """invert(x[, out]) 13486 13487 Compute bit-wise inversion, or bit-wise NOT, element-wise. 13488 13489 Computes the bit-wise NOT of the underlying binary representation of 13490 the integers in the input arrays. This ufunc implements the C/Python 13491 operator ``~``. 13492 13493 For signed integer inputs, the two's complement is returned. 13494 In a two's-complement system negative numbers are represented by the two's 13495 complement of the absolute value. This is the most common method of 13496 representing signed integers on computers [1]_. A N-bit two's-complement 13497 system can represent every integer in the range 13498 :math:`-2^{N-1}` to :math:`+2^{N-1}-1`. 13499 13500 Parameters 13501 ---------- 13502 x1 : array_like 13503 Only integer types are handled (including booleans). 13504 13505 Returns 13506 ------- 13507 out : array_like 13508 Result. 13509 13510 See Also 13511 -------- 13512 bitwise_and, bitwise_or, bitwise_xor 13513 logical_not 13514 binary_repr : 13515 Return the binary representation of the input number as a string. 13516 13517 Notes 13518 ----- 13519 `bitwise_not` is an alias for `invert`: 13520 13521 >>> np.bitwise_not is np.invert 13522 True 13523 13524 References 13525 ---------- 13526 .. [1] Wikipedia, "Two's complement", 13527 http://en.wikipedia.org/wiki/Two's_complement 13528 13529 Examples 13530 -------- 13531 We've seen that 13 is represented by ``00001101``. 13532 The invert or bit-wise NOT of 13 is then: 13533 13534 >>> np.invert(np.array([13], dtype=uint8)) 13535 array([242], dtype=uint8) 13536 >>> np.binary_repr(x, width=8) 13537 '00001101' 13538 >>> np.binary_repr(242, width=8) 13539 '11110010' 13540 13541 The result depends on the bit-width: 13542 13543 >>> np.invert(np.array([13], dtype=uint16)) 13544 array([65522], dtype=uint16) 13545 >>> np.binary_repr(x, width=16) 13546 '0000000000001101' 13547 >>> np.binary_repr(65522, width=16) 13548 '1111111111110010' 13549 13550 When using signed integer types the result is the two's complement of 13551 the result for the unsigned type: 13552 13553 >>> np.invert(np.array([13], dtype=int8)) 13554 array([-14], dtype=int8) 13555 >>> np.binary_repr(-14, width=8) 13556 '11110010' 13557 13558 Booleans are accepted as well: 13559 13560 >>> np.invert(array([True, False])) 13561 array([False, True], dtype=bool)""" 13562 return ndarray() 13563 def ipmt(rate, per, nper, pv="end", fv=0.0, when="end"): 13564 """ 13565 Compute the interest portion of a payment. 13566 13567 Parameters 13568 ---------- 13569 rate : scalar or array_like of shape(M, ) 13570 Rate of interest as decimal (not per cent) per period 13571 per : scalar or array_like of shape(M, ) 13572 Interest paid against the loan changes during the life or the loan. 13573 The `per` is the payment period to calculate the interest amount. 13574 nper : scalar or array_like of shape(M, ) 13575 Number of compounding periods 13576 pv : scalar or array_like of shape(M, ) 13577 Present value 13578 fv : scalar or array_like of shape(M, ), optional 13579 Future value 13580 when : {{'begin', 1}, {'end', 0}}, {string, int}, optional 13581 When payments are due ('begin' (1) or 'end' (0)). 13582 Defaults to {'end', 0}. 13583 13584 Returns 13585 ------- 13586 out : ndarray 13587 Interest portion of payment. If all input is scalar, returns a scalar 13588 float. If any input is array_like, returns interest payment for each 13589 input element. If multiple inputs are array_like, they all must have 13590 the same shape. 13591 13592 See Also 13593 -------- 13594 ppmt, pmt, pv 13595 13596 Notes 13597 ----- 13598 The total payment is made up of payment against principal plus interest. 13599 13600 ``pmt = ppmt + ipmt`` 13601 13602 Examples 13603 -------- 13604 What is the amortization schedule for a 1 year loan of $2500 at 13605 8.24% interest per year compounded monthly? 13606 13607 >>> principal = 2500.00 13608 13609 The 'per' variable represents the periods of the loan. Remember that 13610 financial equations start the period count at 1! 13611 13612 >>> per = np.arange(1*12) + 1 13613 >>> ipmt = np.ipmt(0.0824/12, per, 1*12, principal) 13614 >>> ppmt = np.ppmt(0.0824/12, per, 1*12, principal) 13615 13616 Each element of the sum of the 'ipmt' and 'ppmt' arrays should equal 13617 'pmt'. 13618 13619 >>> pmt = np.pmt(0.0824/12, 1*12, principal) 13620 >>> np.allclose(ipmt + ppmt, pmt) 13621 True 13622 13623 >>> fmt = '{0:2d} {1:8.2f} {2:8.2f} {3:8.2f}' 13624 >>> for payment in per: 13625 ... index = payment - 1 13626 ... principal = principal + ppmt[index] 13627 ... print fmt.format(payment, ppmt[index], ipmt[index], principal) 13628 1 -200.58 -17.17 2299.42 13629 2 -201.96 -15.79 2097.46 13630 3 -203.35 -14.40 1894.11 13631 4 -204.74 -13.01 1689.37 13632 5 -206.15 -11.60 1483.22 13633 6 -207.56 -10.18 1275.66 13634 7 -208.99 -8.76 1066.67 13635 8 -210.42 -7.32 856.25 13636 9 -211.87 -5.88 644.38 13637 10 -213.32 -4.42 431.05 13638 11 -214.79 -2.96 216.26 13639 12 -216.26 -1.49 -0.00 13640 13641 >>> interestpd = np.sum(ipmt) 13642 >>> np.round(interestpd, 2) 13643 -112.98 13644 13645 """ 13646 return ndarray() 13647 def irr(values): 13648 """ 13649 Return the Internal Rate of Return (IRR). 13650 13651 This is the "average" periodically compounded rate of return 13652 that gives a net present value of 0.0; for a more complete explanation, 13653 see Notes below. 13654 13655 Parameters 13656 ---------- 13657 values : array_like, shape(N,) 13658 Input cash flows per time period. By convention, net "deposits" 13659 are negative and net "withdrawals" are positive. Thus, for example, 13660 at least the first element of `values`, which represents the initial 13661 investment, will typically be negative. 13662 13663 Returns 13664 ------- 13665 out : float 13666 Internal Rate of Return for periodic input values. 13667 13668 Notes 13669 ----- 13670 The IRR is perhaps best understood through an example (illustrated 13671 using np.irr in the Examples section below). Suppose one invests 13672 100 units and then makes the following withdrawals at regular 13673 (fixed) intervals: 39, 59, 55, 20. Assuming the ending value is 0, 13674 one's 100 unit investment yields 173 units; however, due to the 13675 combination of compounding and the periodic withdrawals, the 13676 "average" rate of return is neither simply 0.73/4 nor (1.73)^0.25-1. 13677 Rather, it is the solution (for :math:`r`) of the equation: 13678 13679 .. math:: -100 + \frac{39}{1+r} + \frac{59}{(1+r)^2} 13680 + \frac{55}{(1+r)^3} + \frac{20}{(1+r)^4} = 0 13681 13682 In general, for `values` :math:`= [v_0, v_1, ... v_M]`, 13683 irr is the solution of the equation: [G]_ 13684 13685 .. math:: \sum_{t=0}^M{\frac{v_t}{(1+irr)^{t}}} = 0 13686 13687 References 13688 ---------- 13689 .. [G] L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed., 13690 Addison-Wesley, 2003, pg. 348. 13691 13692 Examples 13693 -------- 13694 >>> print round(np.irr([-100, 39, 59, 55, 20]), 5) 13695 0.28095 13696 13697 (Compare with the Example given for numpy.lib.financial.npv) 13698 13699 """ 13700 return float() 13701 def is_busday(dates, weekmask, holidays, busdaycal, out): 13702 """is_busday(dates, weekmask='1111100', holidays=None, busdaycal=None, out=None) 13703 13704 Calculates which of the given dates are valid days, and which are not. 13705 13706 .. versionadded:: 1.7.0 13707 13708 Parameters 13709 ---------- 13710 dates : array_like of datetime64[D] 13711 The array of dates to process. 13712 weekmask : str or array_like of bool, optional 13713 A seven-element array indicating which of Monday through Sunday are 13714 valid days. May be specified as a length-seven list or array, like 13715 [1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string 13716 like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for 13717 weekdays, optionally separated by white space. Valid abbreviations 13718 are: Mon Tue Wed Thu Fri Sat Sun 13719 holidays : array_like of datetime64[D], optional 13720 An array of dates to consider as invalid dates. They may be 13721 specified in any order, and NaT (not-a-time) dates are ignored. 13722 This list is saved in a normalized form that is suited for 13723 fast calculations of valid days. 13724 busdaycal : busdaycalendar, optional 13725 A `busdaycalendar` object which specifies the valid days. If this 13726 parameter is provided, neither weekmask nor holidays may be 13727 provided. 13728 out : array of bool, optional 13729 If provided, this array is filled with the result. 13730 13731 Returns 13732 ------- 13733 out : array of bool 13734 An array with the same shape as ``dates``, containing True for 13735 each valid day, and False for each invalid day. 13736 13737 See Also 13738 -------- 13739 busdaycalendar: An object that specifies a custom set of valid days. 13740 busday_offset : Applies an offset counted in valid days. 13741 busday_count : Counts how many valid days are in a half-open date range. 13742 13743 Examples 13744 -------- 13745 >>> # The weekdays are Friday, Saturday, and Monday 13746 ... np.is_busday(['2011-07-01', '2011-07-02', '2011-07-18'], 13747 ... holidays=['2011-07-01', '2011-07-04', '2011-07-17']) 13748 array([False, False, True], dtype='bool')""" 13749 return array() 13750 def isclose(a, b=False, rtol=1e-05, atol=1e-08, equal_nan=False): 13751 """ 13752 Returns a boolean array where two arrays are element-wise equal within a 13753 tolerance. 13754 13755 The tolerance values are positive, typically very small numbers. The 13756 relative difference (`rtol` * abs(`b`)) and the absolute difference 13757 `atol` are added together to compare against the absolute difference 13758 between `a` and `b`. 13759 13760 Parameters 13761 ---------- 13762 a, b : array_like 13763 Input arrays to compare. 13764 rtol : float 13765 The relative tolerance parameter (see Notes). 13766 atol : float 13767 The absolute tolerance parameter (see Notes). 13768 equal_nan : bool 13769 Whether to compare NaN's as equal. If True, NaN's in `a` will be 13770 considered equal to NaN's in `b` in the output array. 13771 13772 Returns 13773 ------- 13774 y : array_like 13775 Returns a boolean array of where `a` and `b` are equal within the 13776 given tolerance. If both `a` and `b` are scalars, returns a single 13777 boolean value. 13778 13779 See Also 13780 -------- 13781 allclose 13782 13783 Notes 13784 ----- 13785 .. versionadded:: 1.7.0 13786 13787 For finite values, isclose uses the following equation to test whether 13788 two floating point values are equivalent. 13789 13790 absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`)) 13791 13792 The above equation is not symmetric in `a` and `b`, so that 13793 `isclose(a, b)` might be different from `isclose(b, a)` in 13794 some rare cases. 13795 13796 Examples 13797 -------- 13798 >>> np.isclose([1e10,1e-7], [1.00001e10,1e-8]) 13799 array([True, False]) 13800 >>> np.isclose([1e10,1e-8], [1.00001e10,1e-9]) 13801 array([True, True]) 13802 >>> np.isclose([1e10,1e-8], [1.0001e10,1e-9]) 13803 array([False, True]) 13804 >>> np.isclose([1.0, np.nan], [1.0, np.nan]) 13805 array([True, False]) 13806 >>> np.isclose([1.0, np.nan], [1.0, np.nan], equal_nan=True) 13807 array([True, True]) 13808 """ 13809 return ndarray() 13810 def iscomplex(x): 13811 """ 13812 Returns a bool array, where True if input element is complex. 13813 13814 What is tested is whether the input has a non-zero imaginary part, not if 13815 the input type is complex. 13816 13817 Parameters 13818 ---------- 13819 x : array_like 13820 Input array. 13821 13822 Returns 13823 ------- 13824 out : ndarray of bools 13825 Output array. 13826 13827 See Also 13828 -------- 13829 isreal 13830 iscomplexobj : Return True if x is a complex type or an array of complex 13831 numbers. 13832 13833 Examples 13834 -------- 13835 >>> np.iscomplex([1+1j, 1+0j, 4.5, 3, 2, 2j]) 13836 array([ True, False, False, False, False, True], dtype=bool) 13837 13838 """ 13839 return ndarray() 13840 def iscomplexobj(x): 13841 """ 13842 Check for a complex type or an array of complex numbers. 13843 13844 The type of the input is checked, not the value. Even if the input 13845 has an imaginary part equal to zero, `iscomplexobj` evaluates to True. 13846 13847 Parameters 13848 ---------- 13849 x : any 13850 The input can be of any type and shape. 13851 13852 Returns 13853 ------- 13854 iscomplexobj : bool 13855 The return value, True if `x` is of a complex type or has at least 13856 one complex element. 13857 13858 See Also 13859 -------- 13860 isrealobj, iscomplex 13861 13862 Examples 13863 -------- 13864 >>> np.iscomplexobj(1) 13865 False 13866 >>> np.iscomplexobj(1+0j) 13867 True 13868 >>> np.iscomplexobj([3, 1+0j, True]) 13869 True 13870 13871 """ 13872 return bool() 13873 def isfinite(x, out): 13874 """isfinite(x[, out]) 13875 13876 Test element-wise for finite-ness (not infinity or not Not a Number). 13877 13878 The result is returned as a boolean array. 13879 13880 Parameters 13881 ---------- 13882 x : array_like 13883 Input values. 13884 out : ndarray, optional 13885 Array into which the output is placed. Its type is preserved and it 13886 must be of the right shape to hold the output. See `doc.ufuncs`. 13887 13888 Returns 13889 ------- 13890 y : ndarray, bool 13891 For scalar input, the result is a new boolean with value True 13892 if the input is finite; otherwise the value is False (input is 13893 either positive infinity, negative infinity or Not a Number). 13894 13895 For array input, the result is a boolean array with the same 13896 dimensions as the input and the values are True if the corresponding 13897 element of the input is finite; otherwise the values are False (element 13898 is either positive infinity, negative infinity or Not a Number). 13899 13900 See Also 13901 -------- 13902 isinf, isneginf, isposinf, isnan 13903 13904 Notes 13905 ----- 13906 Not a Number, positive infinity and negative infinity are considered 13907 to be non-finite. 13908 13909 Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic 13910 (IEEE 754). This means that Not a Number is not equivalent to infinity. 13911 Also that positive infinity is not equivalent to negative infinity. But 13912 infinity is equivalent to positive infinity. 13913 Errors result if the second argument is also supplied when `x` is a scalar 13914 input, or if first and second arguments have different shapes. 13915 13916 Examples 13917 -------- 13918 >>> np.isfinite(1) 13919 True 13920 >>> np.isfinite(0) 13921 True 13922 >>> np.isfinite(np.nan) 13923 False 13924 >>> np.isfinite(np.inf) 13925 False 13926 >>> np.isfinite(np.NINF) 13927 False 13928 >>> np.isfinite([np.log(-1.),1.,np.log(0)]) 13929 array([False, True, False], dtype=bool) 13930 13931 >>> x = np.array([-np.inf, 0., np.inf]) 13932 >>> y = np.array([2, 2, 2]) 13933 >>> np.isfinite(x, y) 13934 array([0, 1, 0]) 13935 >>> y 13936 array([0, 1, 0])""" 13937 return ndarray() 13938 def isfortran(a): 13939 """ 13940 Returns True if array is arranged in Fortran-order in memory 13941 and not C-order. 13942 13943 Parameters 13944 ---------- 13945 a : ndarray 13946 Input array. 13947 13948 13949 Examples 13950 -------- 13951 13952 np.array allows to specify whether the array is written in C-contiguous 13953 order (last index varies the fastest), or FORTRAN-contiguous order in 13954 memory (first index varies the fastest). 13955 13956 >>> a = np.array([[1, 2, 3], [4, 5, 6]], order='C') 13957 >>> a 13958 array([[1, 2, 3], 13959 [4, 5, 6]]) 13960 >>> np.isfortran(a) 13961 False 13962 13963 >>> b = np.array([[1, 2, 3], [4, 5, 6]], order='FORTRAN') 13964 >>> b 13965 array([[1, 2, 3], 13966 [4, 5, 6]]) 13967 >>> np.isfortran(b) 13968 True 13969 13970 13971 The transpose of a C-ordered array is a FORTRAN-ordered array. 13972 13973 >>> a = np.array([[1, 2, 3], [4, 5, 6]], order='C') 13974 >>> a 13975 array([[1, 2, 3], 13976 [4, 5, 6]]) 13977 >>> np.isfortran(a) 13978 False 13979 >>> b = a.T 13980 >>> b 13981 array([[1, 4], 13982 [2, 5], 13983 [3, 6]]) 13984 >>> np.isfortran(b) 13985 True 13986 13987 C-ordered arrays evaluate as False even if they are also FORTRAN-ordered. 13988 13989 >>> np.isfortran(np.array([1, 2], order='FORTRAN')) 13990 False 13991 13992 """ 13993 return bool() 13994 def isinf(x, out): 13995 """isinf(x[, out]) 13996 13997 Test element-wise for positive or negative infinity. 13998 13999 Return a bool-type array, the same shape as `x`, True where ``x == 14000 +/-inf``, False everywhere else. 14001 14002 Parameters 14003 ---------- 14004 x : array_like 14005 Input values 14006 out : array_like, optional 14007 An array with the same shape as `x` to store the result. 14008 14009 Returns 14010 ------- 14011 y : bool (scalar) or bool-type ndarray 14012 For scalar input, the result is a new boolean with value True 14013 if the input is positive or negative infinity; otherwise the value 14014 is False. 14015 14016 For array input, the result is a boolean array with the same 14017 shape as the input and the values are True where the 14018 corresponding element of the input is positive or negative 14019 infinity; elsewhere the values are False. If a second argument 14020 was supplied the result is stored there. If the type of that array 14021 is a numeric type the result is represented as zeros and ones, if 14022 the type is boolean then as False and True, respectively. 14023 The return value `y` is then a reference to that array. 14024 14025 See Also 14026 -------- 14027 isneginf, isposinf, isnan, isfinite 14028 14029 Notes 14030 ----- 14031 Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic 14032 (IEEE 754). 14033 14034 Errors result if the second argument is supplied when the first 14035 argument is a scalar, or if the first and second arguments have 14036 different shapes. 14037 14038 Examples 14039 -------- 14040 >>> np.isinf(np.inf) 14041 True 14042 >>> np.isinf(np.nan) 14043 False 14044 >>> np.isinf(np.NINF) 14045 True 14046 >>> np.isinf([np.inf, -np.inf, 1.0, np.nan]) 14047 array([ True, True, False, False], dtype=bool) 14048 14049 >>> x = np.array([-np.inf, 0., np.inf]) 14050 >>> y = np.array([2, 2, 2]) 14051 >>> np.isinf(x, y) 14052 array([1, 0, 1]) 14053 >>> y 14054 array([1, 0, 1])""" 14055 return bool() if False else bool_type() 14056 def isnan(x, out=None): 14057 """isnan(x[, out]) 14058 14059 Test element-wise for Not a Number (NaN), return result as a bool array. 14060 14061 Parameters 14062 ---------- 14063 x : array_like 14064 Input array. 14065 14066 Returns 14067 ------- 14068 y : {ndarray, bool} 14069 For scalar input, the result is a new boolean with value True 14070 if the input is NaN; otherwise the value is False. 14071 14072 For array input, the result is a boolean array with the same 14073 dimensions as the input and the values are True if the corresponding 14074 element of the input is NaN; otherwise the values are False. 14075 14076 See Also 14077 -------- 14078 isinf, isneginf, isposinf, isfinite 14079 14080 Notes 14081 ----- 14082 Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic 14083 (IEEE 754). This means that Not a Number is not equivalent to infinity. 14084 14085 Examples 14086 -------- 14087 >>> np.isnan(np.nan) 14088 True 14089 >>> np.isnan(np.inf) 14090 False 14091 >>> np.isnan([np.log(-1.),1.,np.log(0)]) 14092 array([ True, False, False], dtype=bool)""" 14093 return ndarray() 14094 def isneginf(x=None, y=None): 14095 """ 14096 Test element-wise for negative infinity, return result as bool array. 14097 14098 Parameters 14099 ---------- 14100 x : array_like 14101 The input array. 14102 y : array_like, optional 14103 A boolean array with the same shape and type as `x` to store the 14104 result. 14105 14106 Returns 14107 ------- 14108 y : ndarray 14109 A boolean array with the same dimensions as the input. 14110 If second argument is not supplied then a numpy boolean array is 14111 returned with values True where the corresponding element of the 14112 input is negative infinity and values False where the element of 14113 the input is not negative infinity. 14114 14115 If a second argument is supplied the result is stored there. If the 14116 type of that array is a numeric type the result is represented as 14117 zeros and ones, if the type is boolean then as False and True. The 14118 return value `y` is then a reference to that array. 14119 14120 See Also 14121 -------- 14122 isinf, isposinf, isnan, isfinite 14123 14124 Notes 14125 ----- 14126 Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic 14127 (IEEE 754). 14128 14129 Errors result if the second argument is also supplied when x is a scalar 14130 input, or if first and second arguments have different shapes. 14131 14132 Examples 14133 -------- 14134 >>> np.isneginf(np.NINF) 14135 array(True, dtype=bool) 14136 >>> np.isneginf(np.inf) 14137 array(False, dtype=bool) 14138 >>> np.isneginf(np.PINF) 14139 array(False, dtype=bool) 14140 >>> np.isneginf([-np.inf, 0., np.inf]) 14141 array([ True, False, False], dtype=bool) 14142 14143 >>> x = np.array([-np.inf, 0., np.inf]) 14144 >>> y = np.array([2, 2, 2]) 14145 >>> np.isneginf(x, y) 14146 array([1, 0, 0]) 14147 >>> y 14148 array([1, 0, 0]) 14149 14150 """ 14151 return ndarray() 14152 def isposinf(x=None, y=None): 14153 """ 14154 Test element-wise for positive infinity, return result as bool array. 14155 14156 Parameters 14157 ---------- 14158 x : array_like 14159 The input array. 14160 y : array_like, optional 14161 A boolean array with the same shape as `x` to store the result. 14162 14163 Returns 14164 ------- 14165 y : ndarray 14166 A boolean array with the same dimensions as the input. 14167 If second argument is not supplied then a boolean array is returned 14168 with values True where the corresponding element of the input is 14169 positive infinity and values False where the element of the input is 14170 not positive infinity. 14171 14172 If a second argument is supplied the result is stored there. If the 14173 type of that array is a numeric type the result is represented as zeros 14174 and ones, if the type is boolean then as False and True. 14175 The return value `y` is then a reference to that array. 14176 14177 See Also 14178 -------- 14179 isinf, isneginf, isfinite, isnan 14180 14181 Notes 14182 ----- 14183 Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic 14184 (IEEE 754). 14185 14186 Errors result if the second argument is also supplied when `x` is a 14187 scalar input, or if first and second arguments have different shapes. 14188 14189 Examples 14190 -------- 14191 >>> np.isposinf(np.PINF) 14192 array(True, dtype=bool) 14193 >>> np.isposinf(np.inf) 14194 array(True, dtype=bool) 14195 >>> np.isposinf(np.NINF) 14196 array(False, dtype=bool) 14197 >>> np.isposinf([-np.inf, 0., np.inf]) 14198 array([False, False, True], dtype=bool) 14199 14200 >>> x = np.array([-np.inf, 0., np.inf]) 14201 >>> y = np.array([2, 2, 2]) 14202 >>> np.isposinf(x, y) 14203 array([0, 0, 1]) 14204 >>> y 14205 array([0, 0, 1]) 14206 14207 """ 14208 return ndarray() 14209 def isreal(x): 14210 """ 14211 Returns a bool array, where True if input element is real. 14212 14213 If element has complex type with zero complex part, the return value 14214 for that element is True. 14215 14216 Parameters 14217 ---------- 14218 x : array_like 14219 Input array. 14220 14221 Returns 14222 ------- 14223 out : ndarray, bool 14224 Boolean array of same shape as `x`. 14225 14226 See Also 14227 -------- 14228 iscomplex 14229 isrealobj : Return True if x is not a complex type. 14230 14231 Examples 14232 -------- 14233 >>> np.isreal([1+1j, 1+0j, 4.5, 3, 2, 2j]) 14234 array([False, True, True, True, True, False], dtype=bool) 14235 14236 """ 14237 return ndarray() 14238 def isrealobj(x): 14239 """ 14240 Return True if x is a not complex type or an array of complex numbers. 14241 14242 The type of the input is checked, not the value. So even if the input 14243 has an imaginary part equal to zero, `isrealobj` evaluates to False 14244 if the data type is complex. 14245 14246 Parameters 14247 ---------- 14248 x : any 14249 The input can be of any type and shape. 14250 14251 Returns 14252 ------- 14253 y : bool 14254 The return value, False if `x` is of a complex type. 14255 14256 See Also 14257 -------- 14258 iscomplexobj, isreal 14259 14260 Examples 14261 -------- 14262 >>> np.isrealobj(1) 14263 True 14264 >>> np.isrealobj(1+0j) 14265 False 14266 >>> np.isrealobj([3, 1+0j, True]) 14267 False 14268 14269 """ 14270 return bool() 14271 def isscalar(num): 14272 """ 14273 Returns True if the type of `num` is a scalar type. 14274 14275 Parameters 14276 ---------- 14277 num : any 14278 Input argument, can be of any type and shape. 14279 14280 Returns 14281 ------- 14282 val : bool 14283 True if `num` is a scalar type, False if it is not. 14284 14285 Examples 14286 -------- 14287 >>> np.isscalar(3.1) 14288 True 14289 >>> np.isscalar([3.1]) 14290 False 14291 >>> np.isscalar(False) 14292 True 14293 14294 """ 14295 return bool() 14296 def issctype(rep): 14297 """ 14298 Determines whether the given object represents a scalar data-type. 14299 14300 Parameters 14301 ---------- 14302 rep : any 14303 If `rep` is an instance of a scalar dtype, True is returned. If not, 14304 False is returned. 14305 14306 Returns 14307 ------- 14308 out : bool 14309 Boolean result of check whether `rep` is a scalar dtype. 14310 14311 See Also 14312 -------- 14313 issubsctype, issubdtype, obj2sctype, sctype2char 14314 14315 Examples 14316 -------- 14317 >>> np.issctype(np.int32) 14318 True 14319 >>> np.issctype(list) 14320 False 14321 >>> np.issctype(1.1) 14322 False 14323 14324 Strings are also a scalar type: 14325 14326 >>> np.issctype(np.dtype('str')) 14327 True 14328 14329 """ 14330 return bool() 14331 def issub_class_(arg1, arg2): 14332 """ 14333 Determine if a class is a subclass of a second class. 14334 14335 `issubclass_` is equivalent to the Python built-in ``issubclass``, 14336 except that it returns False instead of raising a TypeError is one 14337 of the arguments is not a class. 14338 14339 Parameters 14340 ---------- 14341 arg1 : class 14342 Input class. True is returned if `arg1` is a subclass of `arg2`. 14343 arg2 : class or tuple of classes. 14344 Input class. If a tuple of classes, True is returned if `arg1` is a 14345 subclass of any of the tuple elements. 14346 14347 Returns 14348 ------- 14349 out : bool 14350 Whether `arg1` is a subclass of `arg2` or not. 14351 14352 See Also 14353 -------- 14354 issubsctype, issubdtype, issctype 14355 14356 Examples 14357 -------- 14358 >>> np.issubclass_(np.int32, np.int) 14359 True 14360 >>> np.issubclass_(np.int32, np.float) 14361 False 14362 14363 """ 14364 return bool() 14365 def issubdtype(arg1arg2): 14366 """ 14367 Returns True if first argument is a typecode lower/equal in type hierarchy. 14368 14369 Parameters 14370 ---------- 14371 arg1, arg2 : dtype_like 14372 dtype or string representing a typecode. 14373 14374 Returns 14375 ------- 14376 out : bool 14377 14378 See Also 14379 -------- 14380 issubsctype, issubclass_ 14381 numpy.core.numerictypes : Overview of numpy type hierarchy. 14382 14383 Examples 14384 -------- 14385 >>> np.issubdtype('S1', str) 14386 True 14387 >>> np.issubdtype(np.float64, np.float32) 14388 False 14389 14390 """ 14391 return bool() 14392 def issubsctype(arg1arg2): 14393 """ 14394 Determine if the first argument is a subclass of the second argument. 14395 14396 Parameters 14397 ---------- 14398 arg1, arg2 : dtype or dtype specifier 14399 Data-types. 14400 14401 Returns 14402 ------- 14403 out : bool 14404 The result. 14405 14406 See Also 14407 -------- 14408 issctype, issubdtype,obj2sctype 14409 14410 Examples 14411 -------- 14412 >>> np.issubsctype('S8', str) 14413 True 14414 >>> np.issubsctype(np.array([1]), np.int) 14415 True 14416 >>> np.issubsctype(np.array([1]), np.float) 14417 False 14418 14419 """ 14420 return bool() 14421 def iterable(y): 14422 """ 14423 Check whether or not an object can be iterated over. 14424 14425 Parameters 14426 ---------- 14427 y : object 14428 Input object. 14429 14430 Returns 14431 ------- 14432 b : {0, 1} 14433 Return 1 if the object has an iterator method or is a sequence, 14434 and 0 otherwise. 14435 14436 14437 Examples 14438 -------- 14439 >>> np.iterable([1, 2, 3]) 14440 1 14441 >>> np.iterable(2) 14442 0 14443 14444 """ 14445 return _0() 14446 def ix_(): 14447 """ 14448 Construct an open mesh from multiple sequences. 14449 14450 This function takes N 1-D sequences and returns N outputs with N 14451 dimensions each, such that the shape is 1 in all but one dimension 14452 and the dimension with the non-unit shape value cycles through all 14453 N dimensions. 14454 14455 Using `ix_` one can quickly construct index arrays that will index 14456 the cross product. ``a[np.ix_([1,3],[2,5])]`` returns the array 14457 ``[[a[1,2] a[1,5]], [a[3,2] a[3,5]]]``. 14458 14459 Parameters 14460 ---------- 14461 args : 1-D sequences 14462 14463 Returns 14464 ------- 14465 out : tuple of ndarrays 14466 N arrays with N dimensions each, with N the number of input 14467 sequences. Together these arrays form an open mesh. 14468 14469 See Also 14470 -------- 14471 ogrid, mgrid, meshgrid 14472 14473 Examples 14474 -------- 14475 >>> a = np.arange(10).reshape(2, 5) 14476 >>> a 14477 array([[0, 1, 2, 3, 4], 14478 [5, 6, 7, 8, 9]]) 14479 >>> ixgrid = np.ix_([0,1], [2,4]) 14480 >>> ixgrid 14481 (array([[0], 14482 [1]]), array([[2, 4]])) 14483 >>> ixgrid[0].shape, ixgrid[1].shape 14484 ((2, 1), (1, 2)) 14485 >>> a[ixgrid] 14486 array([[2, 4], 14487 [7, 9]]) 14488 14489 """ 14490 return tuple() 14491 def kaiser(M, beta): 14492 """ 14493 Return the Kaiser window. 14494 14495 The Kaiser window is a taper formed by using a Bessel function. 14496 14497 Parameters 14498 ---------- 14499 M : int 14500 Number of points in the output window. If zero or less, an 14501 empty array is returned. 14502 beta : float 14503 Shape parameter for window. 14504 14505 Returns 14506 ------- 14507 out : array 14508 The window, with the maximum value normalized to one (the value 14509 one appears only if the number of samples is odd). 14510 14511 See Also 14512 -------- 14513 bartlett, blackman, hamming, hanning 14514 14515 Notes 14516 ----- 14517 The Kaiser window is defined as 14518 14519 .. math:: w(n) = I_0\left( \beta \sqrt{1-\frac{4n^2}{(M-1)^2}} 14520 \right)/I_0(\beta) 14521 14522 with 14523 14524 .. math:: \quad -\frac{M-1}{2} \leq n \leq \frac{M-1}{2}, 14525 14526 where :math:`I_0` is the modified zeroth-order Bessel function. 14527 14528 The Kaiser was named for Jim Kaiser, who discovered a simple approximation 14529 to the DPSS window based on Bessel functions. 14530 The Kaiser window is a very good approximation to the Digital Prolate 14531 Spheroidal Sequence, or Slepian window, which is the transform which 14532 maximizes the energy in the main lobe of the window relative to total 14533 energy. 14534 14535 The Kaiser can approximate many other windows by varying the beta 14536 parameter. 14537 14538 ==== ======================= 14539 beta Window shape 14540 ==== ======================= 14541 0 Rectangular 14542 5 Similar to a Hamming 14543 6 Similar to a Hanning 14544 8.6 Similar to a Blackman 14545 ==== ======================= 14546 14547 A beta value of 14 is probably a good starting point. Note that as beta 14548 gets large, the window narrows, and so the number of samples needs to be 14549 large enough to sample the increasingly narrow spike, otherwise NaNs will 14550 get returned. 14551 14552 Most references to the Kaiser window come from the signal processing 14553 literature, where it is used as one of many windowing functions for 14554 smoothing values. It is also known as an apodization (which means 14555 "removing the foot", i.e. smoothing discontinuities at the beginning 14556 and end of the sampled signal) or tapering function. 14557 14558 References 14559 ---------- 14560 .. [1] J. F. Kaiser, "Digital Filters" - Ch 7 in "Systems analysis by 14561 digital computer", Editors: F.F. Kuo and J.F. Kaiser, p 218-285. 14562 John Wiley and Sons, New York, (1966). 14563 .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics", The 14564 University of Alberta Press, 1975, pp. 177-178. 14565 .. [3] Wikipedia, "Window function", 14566 http://en.wikipedia.org/wiki/Window_function 14567 14568 Examples 14569 -------- 14570 >>> np.kaiser(12, 14) 14571 array([ 7.72686684e-06, 3.46009194e-03, 4.65200189e-02, 14572 2.29737120e-01, 5.99885316e-01, 9.45674898e-01, 14573 9.45674898e-01, 5.99885316e-01, 2.29737120e-01, 14574 4.65200189e-02, 3.46009194e-03, 7.72686684e-06]) 14575 14576 14577 Plot the window and the frequency response: 14578 14579 >>> from numpy.fft import fft, fftshift 14580 >>> window = np.kaiser(51, 14) 14581 >>> plt.plot(window) 14582 [<matplotlib.lines.Line2D object at 0x...>] 14583 >>> plt.title("Kaiser window") 14584 <matplotlib.text.Text object at 0x...> 14585 >>> plt.ylabel("Amplitude") 14586 <matplotlib.text.Text object at 0x...> 14587 >>> plt.xlabel("Sample") 14588 <matplotlib.text.Text object at 0x...> 14589 >>> plt.show() 14590 14591 >>> plt.figure() 14592 <matplotlib.figure.Figure object at 0x...> 14593 >>> A = fft(window, 2048) / 25.5 14594 >>> mag = np.abs(fftshift(A)) 14595 >>> freq = np.linspace(-0.5, 0.5, len(A)) 14596 >>> response = 20 * np.log10(mag) 14597 >>> response = np.clip(response, -100, 100) 14598 >>> plt.plot(freq, response) 14599 [<matplotlib.lines.Line2D object at 0x...>] 14600 >>> plt.title("Frequency response of Kaiser window") 14601 <matplotlib.text.Text object at 0x...> 14602 >>> plt.ylabel("Magnitude [dB]") 14603 <matplotlib.text.Text object at 0x...> 14604 >>> plt.xlabel("Normalized frequency [cycles per sample]") 14605 <matplotlib.text.Text object at 0x...> 14606 >>> plt.axis('tight') 14607 (-0.5, 0.5, -100.0, ...) 14608 >>> plt.show() 14609 14610 """ 14611 return array() 14612 def kron(ab): 14613 """ 14614 Kronecker product of two arrays. 14615 14616 Computes the Kronecker product, a composite array made of blocks of the 14617 second array scaled by the first. 14618 14619 Parameters 14620 ---------- 14621 a, b : array_like 14622 14623 Returns 14624 ------- 14625 out : ndarray 14626 14627 See Also 14628 -------- 14629 outer : The outer product 14630 14631 Notes 14632 ----- 14633 The function assumes that the number of dimenensions of `a` and `b` 14634 are the same, if necessary prepending the smallest with ones. 14635 If `a.shape = (r0,r1,..,rN)` and `b.shape = (s0,s1,...,sN)`, 14636 the Kronecker product has shape `(r0*s0, r1*s1, ..., rN*SN)`. 14637 The elements are products of elements from `a` and `b`, organized 14638 explicitly by:: 14639 14640 kron(a,b)[k0,k1,...,kN] = a[i0,i1,...,iN] * b[j0,j1,...,jN] 14641 14642 where:: 14643 14644 kt = it * st + jt, t = 0,...,N 14645 14646 In the common 2-D case (N=1), the block structure can be visualized:: 14647 14648 [[ a[0,0]*b, a[0,1]*b, ... , a[0,-1]*b ], 14649 [ ... ... ], 14650 [ a[-1,0]*b, a[-1,1]*b, ... , a[-1,-1]*b ]] 14651 14652 14653 Examples 14654 -------- 14655 >>> np.kron([1,10,100], [5,6,7]) 14656 array([ 5, 6, 7, 50, 60, 70, 500, 600, 700]) 14657 >>> np.kron([5,6,7], [1,10,100]) 14658 array([ 5, 50, 500, 6, 60, 600, 7, 70, 700]) 14659 14660 >>> np.kron(np.eye(2), np.ones((2,2))) 14661 array([[ 1., 1., 0., 0.], 14662 [ 1., 1., 0., 0.], 14663 [ 0., 0., 1., 1.], 14664 [ 0., 0., 1., 1.]]) 14665 14666 >>> a = np.arange(100).reshape((2,5,2,5)) 14667 >>> b = np.arange(24).reshape((2,3,4)) 14668 >>> c = np.kron(a,b) 14669 >>> c.shape 14670 (2, 10, 6, 20) 14671 >>> I = (1,3,0,2) 14672 >>> J = (0,2,1) 14673 >>> J1 = (0,) + J # extend to ndim=4 14674 >>> S1 = (1,) + b.shape 14675 >>> K = tuple(np.array(I) * np.array(S1) + np.array(J1)) 14676 >>> c[K] == a[I]*b[J] 14677 True 14678 14679 """ 14680 return ndarray() 14681 def ldexp(x1, x2, out): 14682 """ldexp(x1, x2[, out]) 14683 14684 Compute y = x1 * 2**x2.""" 14685 return None 14686 def left_shift(x1, x2, out=None): 14687 """left_shift(x1, x2[, out]) 14688 14689 Shift the bits of an integer to the left. 14690 14691 Bits are shifted to the left by appending `x2` 0s at the right of `x1`. 14692 Since the internal representation of numbers is in binary format, this 14693 operation is equivalent to multiplying `x1` by ``2**x2``. 14694 14695 Parameters 14696 ---------- 14697 x1 : array_like of integer type 14698 Input values. 14699 x2 : array_like of integer type 14700 Number of zeros to append to `x1`. Has to be non-negative. 14701 14702 Returns 14703 ------- 14704 out : array of integer type 14705 Return `x1` with bits shifted `x2` times to the left. 14706 14707 See Also 14708 -------- 14709 right_shift : Shift the bits of an integer to the right. 14710 binary_repr : Return the binary representation of the input number 14711 as a string. 14712 14713 Examples 14714 -------- 14715 >>> np.binary_repr(5) 14716 '101' 14717 >>> np.left_shift(5, 2) 14718 20 14719 >>> np.binary_repr(20) 14720 '10100' 14721 14722 >>> np.left_shift(5, [1,2,3]) 14723 array([10, 20, 40])""" 14724 return array() 14725 def less(x1, x2, out=None): 14726 """less(x1, x2[, out]) 14727 14728 Return the truth value of (x1 < x2) element-wise. 14729 14730 Parameters 14731 ---------- 14732 x1, x2 : array_like 14733 Input arrays. If ``x1.shape != x2.shape``, they must be 14734 broadcastable to a common shape (which may be the shape of one or 14735 the other). 14736 14737 Returns 14738 ------- 14739 out : bool or ndarray of bool 14740 Array of bools, or a single bool if `x1` and `x2` are scalars. 14741 14742 See Also 14743 -------- 14744 greater, less_equal, greater_equal, equal, not_equal 14745 14746 Examples 14747 -------- 14748 >>> np.less([1, 2], [2, 2]) 14749 array([ True, False], dtype=bool)""" 14750 return bool() if False else ndarray() 14751 def less_equal(x1, x2, out=None): 14752 """less_equal(x1, x2[, out]) 14753 14754 Return the truth value of (x1 =< x2) element-wise. 14755 14756 Parameters 14757 ---------- 14758 x1, x2 : array_like 14759 Input arrays. If ``x1.shape != x2.shape``, they must be 14760 broadcastable to a common shape (which may be the shape of one or 14761 the other). 14762 14763 Returns 14764 ------- 14765 out : bool or ndarray of bool 14766 Array of bools, or a single bool if `x1` and `x2` are scalars. 14767 14768 See Also 14769 -------- 14770 greater, less, greater_equal, equal, not_equal 14771 14772 Examples 14773 -------- 14774 >>> np.less_equal([4, 2, 1], [2, 2, 2]) 14775 array([False, True, True], dtype=bool)""" 14776 return bool() if False else ndarray() 14777 def lexsort(keys, axis): 14778 """lexsort(keys, axis=-1) 14779 14780 Perform an indirect sort using a sequence of keys. 14781 14782 Given multiple sorting keys, which can be interpreted as columns in a 14783 spreadsheet, lexsort returns an array of integer indices that describes 14784 the sort order by multiple columns. The last key in the sequence is used 14785 for the primary sort order, the second-to-last key for the secondary sort 14786 order, and so on. The keys argument must be a sequence of objects that 14787 can be converted to arrays of the same shape. If a 2D array is provided 14788 for the keys argument, it's rows are interpreted as the sorting keys and 14789 sorting is according to the last row, second last row etc. 14790 14791 Parameters 14792 ---------- 14793 keys : (k, N) array or tuple containing k (N,)-shaped sequences 14794 The `k` different "columns" to be sorted. The last column (or row if 14795 `keys` is a 2D array) is the primary sort key. 14796 axis : int, optional 14797 Axis to be indirectly sorted. By default, sort over the last axis. 14798 14799 Returns 14800 ------- 14801 indices : (N,) ndarray of ints 14802 Array of indices that sort the keys along the specified axis. 14803 14804 See Also 14805 -------- 14806 argsort : Indirect sort. 14807 ndarray.sort : In-place sort. 14808 sort : Return a sorted copy of an array. 14809 14810 Examples 14811 -------- 14812 Sort names: first by surname, then by name. 14813 14814 >>> surnames = ('Hertz', 'Galilei', 'Hertz') 14815 >>> first_names = ('Heinrich', 'Galileo', 'Gustav') 14816 >>> ind = np.lexsort((first_names, surnames)) 14817 >>> ind 14818 array([1, 2, 0]) 14819 14820 >>> [surnames[i] + ", " + first_names[i] for i in ind] 14821 ['Galilei, Galileo', 'Hertz, Gustav', 'Hertz, Heinrich'] 14822 14823 Sort two columns of numbers: 14824 14825 >>> a = [1,5,1,4,3,4,4] # First column 14826 >>> b = [9,4,0,4,0,2,1] # Second column 14827 >>> ind = np.lexsort((b,a)) # Sort by a, then by b 14828 >>> print ind 14829 [2 0 4 6 5 3 1] 14830 14831 >>> [(a[i],b[i]) for i in ind] 14832 [(1, 0), (1, 9), (3, 0), (4, 1), (4, 2), (4, 4), (5, 4)] 14833 14834 Note that sorting is first according to the elements of ``a``. 14835 Secondary sorting is according to the elements of ``b``. 14836 14837 A normal ``argsort`` would have yielded: 14838 14839 >>> [(a[i],b[i]) for i in np.argsort(a)] 14840 [(1, 9), (1, 0), (3, 0), (4, 4), (4, 2), (4, 1), (5, 4)] 14841 14842 Structured arrays are sorted lexically by ``argsort``: 14843 14844 >>> x = np.array([(1,9), (5,4), (1,0), (4,4), (3,0), (4,2), (4,1)], 14845 ... dtype=np.dtype([('x', int), ('y', int)])) 14846 14847 >>> np.argsort(x) # or np.argsort(x, order=('x', 'y')) 14848 array([2, 0, 4, 6, 5, 3, 1])""" 14849 return N() 14850 def linspace(start, stop=False, num=50, endpoint=True, retstep=False): 14851 """ 14852 Return evenly spaced numbers over a specified interval. 14853 14854 Returns `num` evenly spaced samples, calculated over the 14855 interval [`start`, `stop` ]. 14856 14857 The endpoint of the interval can optionally be excluded. 14858 14859 Parameters 14860 ---------- 14861 start : scalar 14862 The starting value of the sequence. 14863 stop : scalar 14864 The end value of the sequence, unless `endpoint` is set to False. 14865 In that case, the sequence consists of all but the last of ``num + 1`` 14866 evenly spaced samples, so that `stop` is excluded. Note that the step 14867 size changes when `endpoint` is False. 14868 num : int, optional 14869 Number of samples to generate. Default is 50. 14870 endpoint : bool, optional 14871 If True, `stop` is the last sample. Otherwise, it is not included. 14872 Default is True. 14873 retstep : bool, optional 14874 If True, return (`samples`, `step`), where `step` is the spacing 14875 between samples. 14876 14877 Returns 14878 ------- 14879 samples : ndarray 14880 There are `num` equally spaced samples in the closed interval 14881 ``[start, stop]`` or the half-open interval ``[start, stop)`` 14882 (depending on whether `endpoint` is True or False). 14883 step : float (only if `retstep` is True) 14884 Size of spacing between samples. 14885 14886 14887 See Also 14888 -------- 14889 arange : Similar to `linspace`, but uses a step size (instead of the 14890 number of samples). 14891 logspace : Samples uniformly distributed in log space. 14892 14893 Examples 14894 -------- 14895 >>> np.linspace(2.0, 3.0, num=5) 14896 array([ 2. , 2.25, 2.5 , 2.75, 3. ]) 14897 >>> np.linspace(2.0, 3.0, num=5, endpoint=False) 14898 array([ 2. , 2.2, 2.4, 2.6, 2.8]) 14899 >>> np.linspace(2.0, 3.0, num=5, retstep=True) 14900 (array([ 2. , 2.25, 2.5 , 2.75, 3. ]), 0.25) 14901 14902 Graphical illustration: 14903 14904 >>> import matplotlib.pyplot as plt 14905 >>> N = 8 14906 >>> y = np.zeros(N) 14907 >>> x1 = np.linspace(0, 10, N, endpoint=True) 14908 >>> x2 = np.linspace(0, 10, N, endpoint=False) 14909 >>> plt.plot(x1, y, 'o') 14910 [<matplotlib.lines.Line2D object at 0x...>] 14911 >>> plt.plot(x2, y + 0.5, 'o') 14912 [<matplotlib.lines.Line2D object at 0x...>] 14913 >>> plt.ylim([-0.5, 1]) 14914 (-0.5, 1) 14915 >>> plt.show() 14916 14917 """ 14918 return ndarray() 14919 little_endian = bool() 14920 def load(file=None, mmap_mode=None): 14921 """ 14922 Load an array(s) or pickled objects from .npy, .npz, or pickled files. 14923 14924 Parameters 14925 ---------- 14926 file : file-like object or string 14927 The file to read. It must support ``seek()`` and ``read()`` methods. 14928 If the filename extension is ``.gz``, the file is first decompressed. 14929 mmap_mode : {None, 'r+', 'r', 'w+', 'c'}, optional 14930 If not None, then memory-map the file, using the given mode 14931 (see `numpy.memmap` for a detailed description of the modes). 14932 A memory-mapped array is kept on disk. However, it can be accessed 14933 and sliced like any ndarray. Memory mapping is especially useful for 14934 accessing small fragments of large files without reading the entire 14935 file into memory. 14936 14937 Returns 14938 ------- 14939 result : array, tuple, dict, etc. 14940 Data stored in the file. For '.npz' files, the returned instance of 14941 NpzFile class must be closed to avoid leaking file descriptors. 14942 14943 Raises 14944 ------ 14945 IOError 14946 If the input file does not exist or cannot be read. 14947 14948 See Also 14949 -------- 14950 save, savez, loadtxt 14951 memmap : Create a memory-map to an array stored in a file on disk. 14952 14953 Notes 14954 ----- 14955 - If the file contains pickle data, then whatever object is stored 14956 in the pickle is returned. 14957 - If the file is a ``.npy`` file, then a single array is returned. 14958 - If the file is a ``.npz`` file, then a dictionary-like object is 14959 returned, containing ``{filename: array}`` key-value pairs, one for 14960 each file in the archive. 14961 - If the file is a ``.npz`` file, the returned value supports the context 14962 manager protocol in a similar fashion to the open function:: 14963 14964 with load('foo.npz') as data: 14965 a = data['a'] 14966 14967 The underlyling file descriptor is closed when exiting the 'with' block. 14968 14969 Examples 14970 -------- 14971 Store data to disk, and load it again: 14972 14973 >>> np.save('/tmp/123', np.array([[1, 2, 3], [4, 5, 6]])) 14974 >>> np.load('/tmp/123.npy') 14975 array([[1, 2, 3], 14976 [4, 5, 6]]) 14977 14978 Store compressed data to disk, and load it again: 14979 14980 >>> a=np.array([[1, 2, 3], [4, 5, 6]]) 14981 >>> b=np.array([1, 2]) 14982 >>> np.savez('/tmp/123.npz', a=a, b=b) 14983 >>> data = np.load('/tmp/123.npz') 14984 >>> data['a'] 14985 array([[1, 2, 3], 14986 [4, 5, 6]]) 14987 >>> data['b'] 14988 array([1, 2]) 14989 >>> data.close() 14990 14991 Mem-map the stored array, and then access the second row 14992 directly from disk: 14993 14994 >>> X = np.load('/tmp/123.npy', mmap_mode='r') 14995 >>> X[1, :] 14996 memmap([4, 5, 6]) 14997 14998 """ 14999 return array() 15000 def loads(string): 15001 """loads(string) -- Load a pickle from the given string""" 15002 return None 15003 def loadtxt(fname=0, dtype=typefloat(), comments="#", delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0): 15004 """ 15005 Load data from a text file. 15006 15007 Each row in the text file must have the same number of values. 15008 15009 Parameters 15010 ---------- 15011 fname : file or str 15012 File, filename, or generator to read. If the filename extension is 15013 ``.gz`` or ``.bz2``, the file is first decompressed. Note that 15014 generators should return byte strings for Python 3k. 15015 dtype : data-type, optional 15016 Data-type of the resulting array; default: float. If this is a 15017 record data-type, the resulting array will be 1-dimensional, and 15018 each row will be interpreted as an element of the array. In this 15019 case, the number of columns used must match the number of fields in 15020 the data-type. 15021 comments : str, optional 15022 The character used to indicate the start of a comment; 15023 default: '#'. 15024 delimiter : str, optional 15025 The string used to separate values. By default, this is any 15026 whitespace. 15027 converters : dict, optional 15028 A dictionary mapping column number to a function that will convert 15029 that column to a float. E.g., if column 0 is a date string: 15030 ``converters = {0: datestr2num}``. Converters can also be used to 15031 provide a default value for missing data (but see also `genfromtxt`): 15032 ``converters = {3: lambda s: float(s.strip() or 0)}``. Default: None. 15033 skiprows : int, optional 15034 Skip the first `skiprows` lines; default: 0. 15035 usecols : sequence, optional 15036 Which columns to read, with 0 being the first. For example, 15037 ``usecols = (1,4,5)`` will extract the 2nd, 5th and 6th columns. 15038 The default, None, results in all columns being read. 15039 unpack : bool, optional 15040 If True, the returned array is transposed, so that arguments may be 15041 unpacked using ``x, y, z = loadtxt(...)``. When used with a record 15042 data-type, arrays are returned for each field. Default is False. 15043 ndmin : int, optional 15044 The returned array will have at least `ndmin` dimensions. 15045 Otherwise mono-dimensional axes will be squeezed. 15046 Legal values: 0 (default), 1 or 2. 15047 .. versionadded:: 1.6.0 15048 15049 Returns 15050 ------- 15051 out : ndarray 15052 Data read from the text file. 15053 15054 See Also 15055 -------- 15056 load, fromstring, fromregex 15057 genfromtxt : Load data with missing values handled as specified. 15058 scipy.io.loadmat : reads MATLAB data files 15059 15060 Notes 15061 ----- 15062 This function aims to be a fast reader for simply formatted files. The 15063 `genfromtxt` function provides more sophisticated handling of, e.g., 15064 lines with missing values. 15065 15066 Examples 15067 -------- 15068 >>> from StringIO import StringIO # StringIO behaves like a file object 15069 >>> c = StringIO("0 1\n2 3") 15070 >>> np.loadtxt(c) 15071 array([[ 0., 1.], 15072 [ 2., 3.]]) 15073 15074 >>> d = StringIO("M 21 72\nF 35 58") 15075 >>> np.loadtxt(d, dtype={'names': ('gender', 'age', 'weight'), 15076 ... 'formats': ('S1', 'i4', 'f4')}) 15077 array([('M', 21, 72.0), ('F', 35, 58.0)], 15078 dtype=[('gender', '|S1'), ('age', '<i4'), ('weight', '<f4')]) 15079 15080 >>> c = StringIO("1,0,2\n3,0,4") 15081 >>> x, y = np.loadtxt(c, delimiter=',', usecols=(0, 2), unpack=True) 15082 >>> x 15083 array([ 1., 3.]) 15084 >>> y 15085 array([ 2., 4.]) 15086 15087 """ 15088 return ndarray() 15089 def log(x, out=None): 15090 """log(x[, out]) 15091 15092 Natural logarithm, element-wise. 15093 15094 The natural logarithm `log` is the inverse of the exponential function, 15095 so that `log(exp(x)) = x`. The natural logarithm is logarithm in base `e`. 15096 15097 Parameters 15098 ---------- 15099 x : array_like 15100 Input value. 15101 15102 Returns 15103 ------- 15104 y : ndarray 15105 The natural logarithm of `x`, element-wise. 15106 15107 See Also 15108 -------- 15109 log10, log2, log1p, emath.log 15110 15111 Notes 15112 ----- 15113 Logarithm is a multivalued function: for each `x` there is an infinite 15114 number of `z` such that `exp(z) = x`. The convention is to return the `z` 15115 whose imaginary part lies in `[-pi, pi]`. 15116 15117 For real-valued input data types, `log` always returns real output. For 15118 each value that cannot be expressed as a real number or infinity, it 15119 yields ``nan`` and sets the `invalid` floating point error flag. 15120 15121 For complex-valued input, `log` is a complex analytical function that 15122 has a branch cut `[-inf, 0]` and is continuous from above on it. `log` 15123 handles the floating-point negative zero as an infinitesimal negative 15124 number, conforming to the C99 standard. 15125 15126 References 15127 ---------- 15128 .. [1] M. Abramowitz and I.A. Stegun, "Handbook of Mathematical Functions", 15129 10th printing, 1964, pp. 67. http://www.math.sfu.ca/~cbm/aands/ 15130 .. [2] Wikipedia, "Logarithm". http://en.wikipedia.org/wiki/Logarithm 15131 15132 Examples 15133 -------- 15134 >>> np.log([1, np.e, np.e**2, 0]) 15135 array([ 0., 1., 2., -Inf])""" 15136 return ndarray() 15137 def log10(x, out=None): 15138 """log10(x[, out]) 15139 15140 Return the base 10 logarithm of the input array, element-wise. 15141 15142 Parameters 15143 ---------- 15144 x : array_like 15145 Input values. 15146 15147 Returns 15148 ------- 15149 y : ndarray 15150 The logarithm to the base 10 of `x`, element-wise. NaNs are 15151 returned where x is negative. 15152 15153 See Also 15154 -------- 15155 emath.log10 15156 15157 Notes 15158 ----- 15159 Logarithm is a multivalued function: for each `x` there is an infinite 15160 number of `z` such that `10**z = x`. The convention is to return the `z` 15161 whose imaginary part lies in `[-pi, pi]`. 15162 15163 For real-valued input data types, `log10` always returns real output. For 15164 each value that cannot be expressed as a real number or infinity, it 15165 yields ``nan`` and sets the `invalid` floating point error flag. 15166 15167 For complex-valued input, `log10` is a complex analytical function that 15168 has a branch cut `[-inf, 0]` and is continuous from above on it. `log10` 15169 handles the floating-point negative zero as an infinitesimal negative 15170 number, conforming to the C99 standard. 15171 15172 References 15173 ---------- 15174 .. [1] M. Abramowitz and I.A. Stegun, "Handbook of Mathematical Functions", 15175 10th printing, 1964, pp. 67. http://www.math.sfu.ca/~cbm/aands/ 15176 .. [2] Wikipedia, "Logarithm". http://en.wikipedia.org/wiki/Logarithm 15177 15178 Examples 15179 -------- 15180 >>> np.log10([1e-15, -3.]) 15181 array([-15., NaN])""" 15182 return ndarray() 15183 def log1p(x, out=None): 15184 """log1p(x[, out]) 15185 15186 Return the natural logarithm of one plus the input array, element-wise. 15187 15188 Calculates ``log(1 + x)``. 15189 15190 Parameters 15191 ---------- 15192 x : array_like 15193 Input values. 15194 15195 Returns 15196 ------- 15197 y : ndarray 15198 Natural logarithm of `1 + x`, element-wise. 15199 15200 See Also 15201 -------- 15202 expm1 : ``exp(x) - 1``, the inverse of `log1p`. 15203 15204 Notes 15205 ----- 15206 For real-valued input, `log1p` is accurate also for `x` so small 15207 that `1 + x == 1` in floating-point accuracy. 15208 15209 Logarithm is a multivalued function: for each `x` there is an infinite 15210 number of `z` such that `exp(z) = 1 + x`. The convention is to return 15211 the `z` whose imaginary part lies in `[-pi, pi]`. 15212 15213 For real-valued input data types, `log1p` always returns real output. For 15214 each value that cannot be expressed as a real number or infinity, it 15215 yields ``nan`` and sets the `invalid` floating point error flag. 15216 15217 For complex-valued input, `log1p` is a complex analytical function that 15218 has a branch cut `[-inf, -1]` and is continuous from above on it. `log1p` 15219 handles the floating-point negative zero as an infinitesimal negative 15220 number, conforming to the C99 standard. 15221 15222 References 15223 ---------- 15224 .. [1] M. Abramowitz and I.A. Stegun, "Handbook of Mathematical Functions", 15225 10th printing, 1964, pp. 67. http://www.math.sfu.ca/~cbm/aands/ 15226 .. [2] Wikipedia, "Logarithm". http://en.wikipedia.org/wiki/Logarithm 15227 15228 Examples 15229 -------- 15230 >>> np.log1p(1e-99) 15231 1e-99 15232 >>> np.log(1 + 1e-99) 15233 0.0""" 15234 return ndarray() 15235 def log2(x, out=None): 15236 """log2(x[, out]) 15237 15238 Base-2 logarithm of `x`. 15239 15240 Parameters 15241 ---------- 15242 x : array_like 15243 Input values. 15244 15245 Returns 15246 ------- 15247 y : ndarray 15248 Base-2 logarithm of `x`. 15249 15250 See Also 15251 -------- 15252 log, log10, log1p, emath.log2 15253 15254 Notes 15255 ----- 15256 .. versionadded:: 1.3.0 15257 15258 Logarithm is a multivalued function: for each `x` there is an infinite 15259 number of `z` such that `2**z = x`. The convention is to return the `z` 15260 whose imaginary part lies in `[-pi, pi]`. 15261 15262 For real-valued input data types, `log2` always returns real output. For 15263 each value that cannot be expressed as a real number or infinity, it 15264 yields ``nan`` and sets the `invalid` floating point error flag. 15265 15266 For complex-valued input, `log2` is a complex analytical function that 15267 has a branch cut `[-inf, 0]` and is continuous from above on it. `log2` 15268 handles the floating-point negative zero as an infinitesimal negative 15269 number, conforming to the C99 standard. 15270 15271 Examples 15272 -------- 15273 >>> x = np.array([0, 1, 2, 2**4]) 15274 >>> np.log2(x) 15275 array([-Inf, 0., 1., 4.]) 15276 15277 >>> xi = np.array([0+1.j, 1, 2+0.j, 4.j]) 15278 >>> np.log2(xi) 15279 array([ 0.+2.26618007j, 0.+0.j , 1.+0.j , 2.+2.26618007j])""" 15280 return ndarray() 15281 def logaddexp(x1, x2, out=None): 15282 """logaddexp(x1, x2[, out]) 15283 15284 Logarithm of the sum of exponentiations of the inputs. 15285 15286 Calculates ``log(exp(x1) + exp(x2))``. This function is useful in 15287 statistics where the calculated probabilities of events may be so small 15288 as to exceed the range of normal floating point numbers. In such cases 15289 the logarithm of the calculated probability is stored. This function 15290 allows adding probabilities stored in such a fashion. 15291 15292 Parameters 15293 ---------- 15294 x1, x2 : array_like 15295 Input values. 15296 15297 Returns 15298 ------- 15299 result : ndarray 15300 Logarithm of ``exp(x1) + exp(x2)``. 15301 15302 See Also 15303 -------- 15304 logaddexp2: Logarithm of the sum of exponentiations of inputs in base-2. 15305 15306 Notes 15307 ----- 15308 .. versionadded:: 1.3.0 15309 15310 Examples 15311 -------- 15312 >>> prob1 = np.log(1e-50) 15313 >>> prob2 = np.log(2.5e-50) 15314 >>> prob12 = np.logaddexp(prob1, prob2) 15315 >>> prob12 15316 -113.87649168120691 15317 >>> np.exp(prob12) 15318 3.5000000000000057e-50""" 15319 return ndarray() 15320 def logaddexp2(x1, x2, out=None): 15321 """logaddexp2(x1, x2[, out]) 15322 15323 Logarithm of the sum of exponentiations of the inputs in base-2. 15324 15325 Calculates ``log2(2**x1 + 2**x2)``. This function is useful in machine 15326 learning when the calculated probabilities of events may be so small 15327 as to exceed the range of normal floating point numbers. In such cases 15328 the base-2 logarithm of the calculated probability can be used instead. 15329 This function allows adding probabilities stored in such a fashion. 15330 15331 Parameters 15332 ---------- 15333 x1, x2 : array_like 15334 Input values. 15335 out : ndarray, optional 15336 Array to store results in. 15337 15338 Returns 15339 ------- 15340 result : ndarray 15341 Base-2 logarithm of ``2**x1 + 2**x2``. 15342 15343 See Also 15344 -------- 15345 logaddexp: Logarithm of the sum of exponentiations of the inputs. 15346 15347 Notes 15348 ----- 15349 .. versionadded:: 1.3.0 15350 15351 Examples 15352 -------- 15353 >>> prob1 = np.log2(1e-50) 15354 >>> prob2 = np.log2(2.5e-50) 15355 >>> prob12 = np.logaddexp2(prob1, prob2) 15356 >>> prob1, prob2, prob12 15357 (-166.09640474436813, -164.77447664948076, -164.28904982231052) 15358 >>> 2**prob12 15359 3.4999999999999914e-50""" 15360 return ndarray() 15361 def logical_and(x1, x2, out=None): 15362 """logical_and(x1, x2[, out]) 15363 15364 Compute the truth value of x1 AND x2 elementwise. 15365 15366 Parameters 15367 ---------- 15368 x1, x2 : array_like 15369 Input arrays. `x1` and `x2` must be of the same shape. 15370 15371 15372 Returns 15373 ------- 15374 y : {ndarray, bool} 15375 Boolean result with the same shape as `x1` and `x2` of the logical 15376 AND operation on corresponding elements of `x1` and `x2`. 15377 15378 See Also 15379 -------- 15380 logical_or, logical_not, logical_xor 15381 bitwise_and 15382 15383 Examples 15384 -------- 15385 >>> np.logical_and(True, False) 15386 False 15387 >>> np.logical_and([True, False], [False, False]) 15388 array([False, False], dtype=bool) 15389 15390 >>> x = np.arange(5) 15391 >>> np.logical_and(x>1, x<4) 15392 array([False, False, True, True, False], dtype=bool)""" 15393 return None 15394 def logical_not(x, out=None): 15395 """logical_not(x[, out]) 15396 15397 Compute the truth value of NOT x elementwise. 15398 15399 Parameters 15400 ---------- 15401 x : array_like 15402 Logical NOT is applied to the elements of `x`. 15403 15404 Returns 15405 ------- 15406 y : bool or ndarray of bool 15407 Boolean result with the same shape as `x` of the NOT operation 15408 on elements of `x`. 15409 15410 See Also 15411 -------- 15412 logical_and, logical_or, logical_xor 15413 15414 Examples 15415 -------- 15416 >>> np.logical_not(3) 15417 False 15418 >>> np.logical_not([True, False, 0, 1]) 15419 array([False, True, True, False], dtype=bool) 15420 15421 >>> x = np.arange(5) 15422 >>> np.logical_not(x<3) 15423 array([False, False, False, True, True], dtype=bool)""" 15424 return bool() if False else ndarray() 15425 def logical_or(x1, x2, out=None): 15426 """logical_or(x1, x2[, out]) 15427 15428 Compute the truth value of x1 OR x2 elementwise. 15429 15430 Parameters 15431 ---------- 15432 x1, x2 : array_like 15433 Logical OR is applied to the elements of `x1` and `x2`. 15434 They have to be of the same shape. 15435 15436 Returns 15437 ------- 15438 y : {ndarray, bool} 15439 Boolean result with the same shape as `x1` and `x2` of the logical 15440 OR operation on elements of `x1` and `x2`. 15441 15442 See Also 15443 -------- 15444 logical_and, logical_not, logical_xor 15445 bitwise_or 15446 15447 Examples 15448 -------- 15449 >>> np.logical_or(True, False) 15450 True 15451 >>> np.logical_or([True, False], [False, False]) 15452 array([ True, False], dtype=bool) 15453 15454 >>> x = np.arange(5) 15455 >>> np.logical_or(x < 1, x > 3) 15456 array([ True, False, False, False, True], dtype=bool)""" 15457 return None 15458 def logical_xor(x1, x2, out=None): 15459 """logical_xor(x1, x2[, out]) 15460 15461 Compute the truth value of x1 XOR x2, element-wise. 15462 15463 Parameters 15464 ---------- 15465 x1, x2 : array_like 15466 Logical XOR is applied to the elements of `x1` and `x2`. They must 15467 be broadcastable to the same shape. 15468 15469 Returns 15470 ------- 15471 y : bool or ndarray of bool 15472 Boolean result of the logical XOR operation applied to the elements 15473 of `x1` and `x2`; the shape is determined by whether or not 15474 broadcasting of one or both arrays was required. 15475 15476 See Also 15477 -------- 15478 logical_and, logical_or, logical_not, bitwise_xor 15479 15480 Examples 15481 -------- 15482 >>> np.logical_xor(True, False) 15483 True 15484 >>> np.logical_xor([True, True, False, False], [True, False, True, False]) 15485 array([False, True, True, False], dtype=bool) 15486 15487 >>> x = np.arange(5) 15488 >>> np.logical_xor(x < 1, x > 3) 15489 array([ True, False, False, False, True], dtype=bool) 15490 15491 Simple example showing support of broadcasting 15492 15493 >>> np.logical_xor(0, np.eye(2)) 15494 array([[ True, False], 15495 [False, True]], dtype=bool)""" 15496 return bool() if False else ndarray() 15497 def logspace(start, stop=10.0, num=50, endpoint=True, base=10.0): 15498 """ 15499 Return numbers spaced evenly on a log scale. 15500 15501 In linear space, the sequence starts at ``base ** start`` 15502 (`base` to the power of `start`) and ends with ``base ** stop`` 15503 (see `endpoint` below). 15504 15505 Parameters 15506 ---------- 15507 start : float 15508 ``base ** start`` is the starting value of the sequence. 15509 stop : float 15510 ``base ** stop`` is the final value of the sequence, unless `endpoint` 15511 is False. In that case, ``num + 1`` values are spaced over the 15512 interval in log-space, of which all but the last (a sequence of 15513 length ``num``) are returned. 15514 num : integer, optional 15515 Number of samples to generate. Default is 50. 15516 endpoint : boolean, optional 15517 If true, `stop` is the last sample. Otherwise, it is not included. 15518 Default is True. 15519 base : float, optional 15520 The base of the log space. The step size between the elements in 15521 ``ln(samples) / ln(base)`` (or ``log_base(samples)``) is uniform. 15522 Default is 10.0. 15523 15524 Returns 15525 ------- 15526 samples : ndarray 15527 `num` samples, equally spaced on a log scale. 15528 15529 See Also 15530 -------- 15531 arange : Similar to linspace, with the step size specified instead of the 15532 number of samples. Note that, when used with a float endpoint, the 15533 endpoint may or may not be included. 15534 linspace : Similar to logspace, but with the samples uniformly distributed 15535 in linear space, instead of log space. 15536 15537 Notes 15538 ----- 15539 Logspace is equivalent to the code 15540 15541 >>> y = np.linspace(start, stop, num=num, endpoint=endpoint) 15542 ... # doctest: +SKIP 15543 >>> power(base, y) 15544 ... # doctest: +SKIP 15545 15546 Examples 15547 -------- 15548 >>> np.logspace(2.0, 3.0, num=4) 15549 array([ 100. , 215.443469 , 464.15888336, 1000. ]) 15550 >>> np.logspace(2.0, 3.0, num=4, endpoint=False) 15551 array([ 100. , 177.827941 , 316.22776602, 562.34132519]) 15552 >>> np.logspace(2.0, 3.0, num=4, base=2.0) 15553 array([ 4. , 5.0396842 , 6.34960421, 8. ]) 15554 15555 Graphical illustration: 15556 15557 >>> import matplotlib.pyplot as plt 15558 >>> N = 10 15559 >>> x1 = np.logspace(0.1, 1, N, endpoint=True) 15560 >>> x2 = np.logspace(0.1, 1, N, endpoint=False) 15561 >>> y = np.zeros(N) 15562 >>> plt.plot(x1, y, 'o') 15563 [<matplotlib.lines.Line2D object at 0x...>] 15564 >>> plt.plot(x2, y + 0.5, 'o') 15565 [<matplotlib.lines.Line2D object at 0x...>] 15566 >>> plt.ylim([-0.5, 1]) 15567 (-0.5, 1) 15568 >>> plt.show() 15569 15570 """ 15571 return ndarray() 15572 class long: 15573 __doc__ = str() 15574 def bit_length(self, _): 15575 """long.bit_length() -> int or long 15576 15577 Number of bits necessary to represent self in binary. 15578 >>> bin(37L) 15579 '0b100101' 15580 >>> (37L).bit_length() 15581 6""" 15582 return None 15583 def conjugate(self, _): 15584 """Returns self, the complex conjugate of any long.""" 15585 return None 15586 denominator = getset_descriptor() 15587 imag = getset_descriptor() 15588 numerator = getset_descriptor() 15589 real = getset_descriptor() 15590 class complex256: 15591 T = getset_descriptor() 15592 __array_interface__ = getset_descriptor() 15593 __array_priority__ = getset_descriptor() 15594 __array_struct__ = getset_descriptor() 15595 __doc__ = str() 15596 base = getset_descriptor() 15597 def conj(self, _): 15598 """None""" 15599 return None 15600 data = getset_descriptor() 15601 dtype = getset_descriptor() 15602 flags = getset_descriptor() 15603 flat = getset_descriptor() 15604 imag = getset_descriptor() 15605 itemsize = getset_descriptor() 15606 nbytes = getset_descriptor() 15607 ndim = getset_descriptor() 15608 def newbyteorder(self, new_order): 15609 """newbyteorder(new_order='S') 15610 15611 Return a new `dtype` with a different byte order. 15612 15613 Changes are also made in all fields and sub-arrays of the data type. 15614 15615 The `new_order` code can be any from the following: 15616 15617 * {'<', 'L'} - little endian 15618 * {'>', 'B'} - big endian 15619 * {'=', 'N'} - native order 15620 * 'S' - swap dtype from current to opposite endian 15621 * {'|', 'I'} - ignore (no change to byte order) 15622 15623 Parameters 15624 ---------- 15625 new_order : str, optional 15626 Byte order to force; a value from the byte order specifications 15627 above. The default value ('S') results in swapping the current 15628 byte order. The code does a case-insensitive check on the first 15629 letter of `new_order` for the alternatives above. For example, 15630 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 15631 15632 15633 Returns 15634 ------- 15635 new_dtype : dtype 15636 New `dtype` object with the given change to the byte order.""" 15637 return dtype() 15638 real = getset_descriptor() 15639 shape = getset_descriptor() 15640 size = getset_descriptor() 15641 strides = getset_descriptor() 15642 class float128: 15643 T = getset_descriptor() 15644 __array_interface__ = getset_descriptor() 15645 __array_priority__ = getset_descriptor() 15646 __array_struct__ = getset_descriptor() 15647 __doc__ = str() 15648 base = getset_descriptor() 15649 def conj(self, _): 15650 """None""" 15651 return None 15652 data = getset_descriptor() 15653 dtype = getset_descriptor() 15654 flags = getset_descriptor() 15655 flat = getset_descriptor() 15656 imag = getset_descriptor() 15657 itemsize = getset_descriptor() 15658 nbytes = getset_descriptor() 15659 ndim = getset_descriptor() 15660 def newbyteorder(self, new_order): 15661 """newbyteorder(new_order='S') 15662 15663 Return a new `dtype` with a different byte order. 15664 15665 Changes are also made in all fields and sub-arrays of the data type. 15666 15667 The `new_order` code can be any from the following: 15668 15669 * {'<', 'L'} - little endian 15670 * {'>', 'B'} - big endian 15671 * {'=', 'N'} - native order 15672 * 'S' - swap dtype from current to opposite endian 15673 * {'|', 'I'} - ignore (no change to byte order) 15674 15675 Parameters 15676 ---------- 15677 new_order : str, optional 15678 Byte order to force; a value from the byte order specifications 15679 above. The default value ('S') results in swapping the current 15680 byte order. The code does a case-insensitive check on the first 15681 letter of `new_order` for the alternatives above. For example, 15682 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 15683 15684 15685 Returns 15686 ------- 15687 new_dtype : dtype 15688 New `dtype` object with the given change to the byte order.""" 15689 return dtype() 15690 real = getset_descriptor() 15691 shape = getset_descriptor() 15692 size = getset_descriptor() 15693 strides = getset_descriptor() 15694 class float128: 15695 T = getset_descriptor() 15696 __array_interface__ = getset_descriptor() 15697 __array_priority__ = getset_descriptor() 15698 __array_struct__ = getset_descriptor() 15699 __doc__ = str() 15700 base = getset_descriptor() 15701 def conj(self, _): 15702 """None""" 15703 return None 15704 data = getset_descriptor() 15705 dtype = getset_descriptor() 15706 flags = getset_descriptor() 15707 flat = getset_descriptor() 15708 imag = getset_descriptor() 15709 itemsize = getset_descriptor() 15710 nbytes = getset_descriptor() 15711 ndim = getset_descriptor() 15712 def newbyteorder(self, new_order): 15713 """newbyteorder(new_order='S') 15714 15715 Return a new `dtype` with a different byte order. 15716 15717 Changes are also made in all fields and sub-arrays of the data type. 15718 15719 The `new_order` code can be any from the following: 15720 15721 * {'<', 'L'} - little endian 15722 * {'>', 'B'} - big endian 15723 * {'=', 'N'} - native order 15724 * 'S' - swap dtype from current to opposite endian 15725 * {'|', 'I'} - ignore (no change to byte order) 15726 15727 Parameters 15728 ---------- 15729 new_order : str, optional 15730 Byte order to force; a value from the byte order specifications 15731 above. The default value ('S') results in swapping the current 15732 byte order. The code does a case-insensitive check on the first 15733 letter of `new_order` for the alternatives above. For example, 15734 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 15735 15736 15737 Returns 15738 ------- 15739 new_dtype : dtype 15740 New `dtype` object with the given change to the byte order.""" 15741 return dtype() 15742 real = getset_descriptor() 15743 shape = getset_descriptor() 15744 size = getset_descriptor() 15745 strides = getset_descriptor() 15746 class int64: 15747 T = getset_descriptor() 15748 __array_interface__ = getset_descriptor() 15749 __array_priority__ = getset_descriptor() 15750 __array_struct__ = getset_descriptor() 15751 __doc__ = None 15752 base = getset_descriptor() 15753 def bit_length(self, _): 15754 """int.bit_length() -> int 15755 15756 Number of bits necessary to represent self in binary. 15757 >>> bin(37) 15758 '0b100101' 15759 >>> (37).bit_length() 15760 6""" 15761 return None 15762 def conj(self, _): 15763 """None""" 15764 return None 15765 data = getset_descriptor() 15766 denominator = getset_descriptor() 15767 dtype = getset_descriptor() 15768 flags = getset_descriptor() 15769 flat = getset_descriptor() 15770 imag = getset_descriptor() 15771 itemsize = getset_descriptor() 15772 nbytes = getset_descriptor() 15773 ndim = getset_descriptor() 15774 def newbyteorder(self, new_order): 15775 """newbyteorder(new_order='S') 15776 15777 Return a new `dtype` with a different byte order. 15778 15779 Changes are also made in all fields and sub-arrays of the data type. 15780 15781 The `new_order` code can be any from the following: 15782 15783 * {'<', 'L'} - little endian 15784 * {'>', 'B'} - big endian 15785 * {'=', 'N'} - native order 15786 * 'S' - swap dtype from current to opposite endian 15787 * {'|', 'I'} - ignore (no change to byte order) 15788 15789 Parameters 15790 ---------- 15791 new_order : str, optional 15792 Byte order to force; a value from the byte order specifications 15793 above. The default value ('S') results in swapping the current 15794 byte order. The code does a case-insensitive check on the first 15795 letter of `new_order` for the alternatives above. For example, 15796 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 15797 15798 15799 Returns 15800 ------- 15801 new_dtype : dtype 15802 New `dtype` object with the given change to the byte order.""" 15803 return dtype() 15804 numerator = getset_descriptor() 15805 real = getset_descriptor() 15806 shape = getset_descriptor() 15807 size = getset_descriptor() 15808 strides = getset_descriptor() 15809 def lookfor(what=None, module=None, import_modules=True, regenerate=False, output=None): 15810 """ 15811 Do a keyword search on docstrings. 15812 15813 A list of of objects that matched the search is displayed, 15814 sorted by relevance. All given keywords need to be found in the 15815 docstring for it to be returned as a result, but the order does 15816 not matter. 15817 15818 Parameters 15819 ---------- 15820 what : str 15821 String containing words to look for. 15822 module : str or list, optional 15823 Name of module(s) whose docstrings to go through. 15824 import_modules : bool, optional 15825 Whether to import sub-modules in packages. Default is True. 15826 regenerate : bool, optional 15827 Whether to re-generate the docstring cache. Default is False. 15828 output : file-like, optional 15829 File-like object to write the output to. If omitted, use a pager. 15830 15831 See Also 15832 -------- 15833 source, info 15834 15835 Notes 15836 ----- 15837 Relevance is determined only roughly, by checking if the keywords occur 15838 in the function name, at the start of a docstring, etc. 15839 15840 Examples 15841 -------- 15842 >>> np.lookfor('binary representation') 15843 Search results for 'binary representation' 15844 ------------------------------------------ 15845 numpy.binary_repr 15846 Return the binary representation of the input number as a string. 15847 numpy.core.setup_common.long_double_representation 15848 Given a binary dump as given by GNU od -b, look for long double 15849 numpy.base_repr 15850 Return a string representation of a number in the given base system. 15851 ... 15852 15853 """ 15854 return None 15855 def ma_fromtxt(fnamekwargs): 15856 """ 15857 Load ASCII data stored in a text file and return a masked array. 15858 15859 Parameters 15860 ---------- 15861 fname, kwargs : For a description of input parameters, see `genfromtxt`. 15862 15863 See Also 15864 -------- 15865 numpy.genfromtxt : generic function to load ASCII data. 15866 15867 """ 15868 return None 15869 def mask_indices(n, mask_func=0, k=0): 15870 """ 15871 Return the indices to access (n, n) arrays, given a masking function. 15872 15873 Assume `mask_func` is a function that, for a square array a of size 15874 ``(n, n)`` with a possible offset argument `k`, when called as 15875 ``mask_func(a, k)`` returns a new array with zeros in certain locations 15876 (functions like `triu` or `tril` do precisely this). Then this function 15877 returns the indices where the non-zero values would be located. 15878 15879 Parameters 15880 ---------- 15881 n : int 15882 The returned indices will be valid to access arrays of shape (n, n). 15883 mask_func : callable 15884 A function whose call signature is similar to that of `triu`, `tril`. 15885 That is, ``mask_func(x, k)`` returns a boolean array, shaped like `x`. 15886 `k` is an optional argument to the function. 15887 k : scalar 15888 An optional argument which is passed through to `mask_func`. Functions 15889 like `triu`, `tril` take a second argument that is interpreted as an 15890 offset. 15891 15892 Returns 15893 ------- 15894 indices : tuple of arrays. 15895 The `n` arrays of indices corresponding to the locations where 15896 ``mask_func(np.ones((n, n)), k)`` is True. 15897 15898 See Also 15899 -------- 15900 triu, tril, triu_indices, tril_indices 15901 15902 Notes 15903 ----- 15904 .. versionadded:: 1.4.0 15905 15906 Examples 15907 -------- 15908 These are the indices that would allow you to access the upper triangular 15909 part of any 3x3 array: 15910 15911 >>> iu = np.mask_indices(3, np.triu) 15912 15913 For example, if `a` is a 3x3 array: 15914 15915 >>> a = np.arange(9).reshape(3, 3) 15916 >>> a 15917 array([[0, 1, 2], 15918 [3, 4, 5], 15919 [6, 7, 8]]) 15920 >>> a[iu] 15921 array([0, 1, 2, 4, 5, 8]) 15922 15923 An offset can be passed also to the masking function. This gets us the 15924 indices starting on the first diagonal right of the main one: 15925 15926 >>> iu1 = np.mask_indices(3, np.triu, 1) 15927 15928 with which we now extract only three elements: 15929 15930 >>> a[iu1] 15931 array([1, 2, 5]) 15932 15933 """ 15934 return tuple() 15935 def asmatrix(data=None, dtype=None): 15936 """ 15937 Interpret the input as a matrix. 15938 15939 Unlike `matrix`, `asmatrix` does not make a copy if the input is already 15940 a matrix or an ndarray. Equivalent to ``matrix(data, copy=False)``. 15941 15942 Parameters 15943 ---------- 15944 data : array_like 15945 Input data. 15946 15947 Returns 15948 ------- 15949 mat : matrix 15950 `data` interpreted as a matrix. 15951 15952 Examples 15953 -------- 15954 >>> x = np.array([[1, 2], [3, 4]]) 15955 15956 >>> m = np.asmatrix(x) 15957 15958 >>> x[0,0] = 5 15959 15960 >>> m 15961 matrix([[5, 2], 15962 [3, 4]]) 15963 15964 """ 15965 return matrix() 15966 class matrix: 15967 A = property() 15968 A1 = property() 15969 H = property() 15970 I = property() 15971 T = property() 15972 __array_interface__ = getset_descriptor() 15973 __array_priority__ = float() 15974 __array_struct__ = getset_descriptor() 15975 __dict__ = dictproxy() 15976 __doc__ = str() 15977 __module__ = str() 15978 def _align(self, _): 15979 """A convenience function for operations that need to preserve axis 15980 orientation. 15981 """ 15982 return None 15983 def _collapse(self, _): 15984 """A convenience function for operations that want to collapse 15985 to a scalar like _align, but are using keepdims=True 15986 """ 15987 return None 15988 def all(self=None, axis=None, out=None): 15989 """ 15990 Test whether all matrix elements along a given axis evaluate to True. 15991 15992 Parameters 15993 ---------- 15994 See `numpy.all` for complete descriptions 15995 15996 See Also 15997 -------- 15998 numpy.all 15999 16000 Notes 16001 ----- 16002 This is the same as `ndarray.all`, but it returns a `matrix` object. 16003 16004 Examples 16005 -------- 16006 >>> x = np.matrix(np.arange(12).reshape((3,4))); x 16007 matrix([[ 0, 1, 2, 3], 16008 [ 4, 5, 6, 7], 16009 [ 8, 9, 10, 11]]) 16010 >>> y = x[0]; y 16011 matrix([[0, 1, 2, 3]]) 16012 >>> (x == y) 16013 matrix([[ True, True, True, True], 16014 [False, False, False, False], 16015 [False, False, False, False]], dtype=bool) 16016 >>> (x == y).all() 16017 False 16018 >>> (x == y).all(0) 16019 matrix([[False, False, False, False]], dtype=bool) 16020 >>> (x == y).all(1) 16021 matrix([[ True], 16022 [False], 16023 [False]], dtype=bool) 16024 16025 """ 16026 return None 16027 def any(self=None, axis=None, out=None): 16028 """ 16029 Test whether any array element along a given axis evaluates to True. 16030 16031 Refer to `numpy.any` for full documentation. 16032 16033 Parameters 16034 ---------- 16035 axis : int, optional 16036 Axis along which logical OR is performed 16037 out : ndarray, optional 16038 Output to existing array instead of creating new one, must have 16039 same shape as expected output 16040 16041 Returns 16042 ------- 16043 any : bool, ndarray 16044 Returns a single bool if `axis` is ``None``; otherwise, 16045 returns `ndarray` 16046 16047 """ 16048 return bool() 16049 def argmax(self=None, axis=None, out=None): 16050 """ 16051 Indices of the maximum values along an axis. 16052 16053 Parameters 16054 ---------- 16055 See `numpy.argmax` for complete descriptions 16056 16057 See Also 16058 -------- 16059 numpy.argmax 16060 16061 Notes 16062 ----- 16063 This is the same as `ndarray.argmax`, but returns a `matrix` object 16064 where `ndarray.argmax` would return an `ndarray`. 16065 16066 Examples 16067 -------- 16068 >>> x = np.matrix(np.arange(12).reshape((3,4))); x 16069 matrix([[ 0, 1, 2, 3], 16070 [ 4, 5, 6, 7], 16071 [ 8, 9, 10, 11]]) 16072 >>> x.argmax() 16073 11 16074 >>> x.argmax(0) 16075 matrix([[2, 2, 2, 2]]) 16076 >>> x.argmax(1) 16077 matrix([[3], 16078 [3], 16079 [3]]) 16080 16081 """ 16082 return None 16083 def argmin(self=None, axis=None, out=None): 16084 """ 16085 Return the indices of the minimum values along an axis. 16086 16087 Parameters 16088 ---------- 16089 See `numpy.argmin` for complete descriptions. 16090 16091 See Also 16092 -------- 16093 numpy.argmin 16094 16095 Notes 16096 ----- 16097 This is the same as `ndarray.argmin`, but returns a `matrix` object 16098 where `ndarray.argmin` would return an `ndarray`. 16099 16100 Examples 16101 -------- 16102 >>> x = -np.matrix(np.arange(12).reshape((3,4))); x 16103 matrix([[ 0, -1, -2, -3], 16104 [ -4, -5, -6, -7], 16105 [ -8, -9, -10, -11]]) 16106 >>> x.argmin() 16107 11 16108 >>> x.argmin(0) 16109 matrix([[2, 2, 2, 2]]) 16110 >>> x.argmin(1) 16111 matrix([[3], 16112 [3], 16113 [3]]) 16114 16115 """ 16116 return None 16117 def argpartition(self, kth, axis=_1, kind=quickselect, order=None): 16118 """a.argpartition(kth, axis=-1, kind='quickselect', order=None) 16119 16120 Returns the indices that would partition this array. 16121 16122 Refer to `numpy.argpartition` for full documentation. 16123 16124 .. versionadded:: 1.8.0 16125 16126 See Also 16127 -------- 16128 numpy.argpartition : equivalent function""" 16129 return None 16130 def argsort(self, axis=_1, kind=quicksort, order=None): 16131 """a.argsort(axis=-1, kind='quicksort', order=None) 16132 16133 Returns the indices that would sort this array. 16134 16135 Refer to `numpy.argsort` for full documentation. 16136 16137 See Also 16138 -------- 16139 numpy.argsort : equivalent function""" 16140 return None 16141 def astype(self, dtype, order, casting, subok, copy): 16142 """a.astype(dtype, order='K', casting='unsafe', subok=True, copy=True) 16143 16144 Copy of the array, cast to a specified type. 16145 16146 Parameters 16147 ---------- 16148 dtype : str or dtype 16149 Typecode or data-type to which the array is cast. 16150 order : {'C', 'F', 'A', 'K'}, optional 16151 Controls the memory layout order of the result. 16152 'C' means C order, 'F' means Fortran order, 'A' 16153 means 'F' order if all the arrays are Fortran contiguous, 16154 'C' order otherwise, and 'K' means as close to the 16155 order the array elements appear in memory as possible. 16156 Default is 'K'. 16157 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional 16158 Controls what kind of data casting may occur. Defaults to 'unsafe' 16159 for backwards compatibility. 16160 16161 * 'no' means the data types should not be cast at all. 16162 * 'equiv' means only byte-order changes are allowed. 16163 * 'safe' means only casts which can preserve values are allowed. 16164 * 'same_kind' means only safe casts or casts within a kind, 16165 like float64 to float32, are allowed. 16166 * 'unsafe' means any data conversions may be done. 16167 subok : bool, optional 16168 If True, then sub-classes will be passed-through (default), otherwise 16169 the returned array will be forced to be a base-class array. 16170 copy : bool, optional 16171 By default, astype always returns a newly allocated array. If this 16172 is set to false, and the `dtype`, `order`, and `subok` 16173 requirements are satisfied, the input array is returned instead 16174 of a copy. 16175 16176 Returns 16177 ------- 16178 arr_t : ndarray 16179 Unless `copy` is False and the other conditions for returning the input 16180 array are satisfied (see description for `copy` input paramter), `arr_t` 16181 is a new array of the same shape as the input array, with dtype, order 16182 given by `dtype`, `order`. 16183 16184 Raises 16185 ------ 16186 ComplexWarning 16187 When casting from complex to float or int. To avoid this, 16188 one should use ``a.real.astype(t)``. 16189 16190 Examples 16191 -------- 16192 >>> x = np.array([1, 2, 2.5]) 16193 >>> x 16194 array([ 1. , 2. , 2.5]) 16195 16196 >>> x.astype(int) 16197 array([1, 2, 2])""" 16198 return ndarray() 16199 base = getset_descriptor() 16200 def byteswap(self, inplace): 16201 """a.byteswap(inplace) 16202 16203 Swap the bytes of the array elements 16204 16205 Toggle between low-endian and big-endian data representation by 16206 returning a byteswapped array, optionally swapped in-place. 16207 16208 Parameters 16209 ---------- 16210 inplace : bool, optional 16211 If ``True``, swap bytes in-place, default is ``False``. 16212 16213 Returns 16214 ------- 16215 out : ndarray 16216 The byteswapped array. If `inplace` is ``True``, this is 16217 a view to self. 16218 16219 Examples 16220 -------- 16221 >>> A = np.array([1, 256, 8755], dtype=np.int16) 16222 >>> map(hex, A) 16223 ['0x1', '0x100', '0x2233'] 16224 >>> A.byteswap(True) 16225 array([ 256, 1, 13090], dtype=int16) 16226 >>> map(hex, A) 16227 ['0x100', '0x1', '0x3322'] 16228 16229 Arrays of strings are not swapped 16230 16231 >>> A = np.array(['ceg', 'fac']) 16232 >>> A.byteswap() 16233 array(['ceg', 'fac'], 16234 dtype='|S3')""" 16235 return ndarray() 16236 def choose(self, choices, out=None, mode=_raise): 16237 """a.choose(choices, out=None, mode='raise') 16238 16239 Use an index array to construct a new array from a set of choices. 16240 16241 Refer to `numpy.choose` for full documentation. 16242 16243 See Also 16244 -------- 16245 numpy.choose : equivalent function""" 16246 return None 16247 def clip(self, a_min, a_max, out=None): 16248 """a.clip(a_min, a_max, out=None) 16249 16250 Return an array whose values are limited to ``[a_min, a_max]``. 16251 16252 Refer to `numpy.clip` for full documentation. 16253 16254 See Also 16255 -------- 16256 numpy.clip : equivalent function""" 16257 return None 16258 def compress(self, condition, axis=None, out=None): 16259 """a.compress(condition, axis=None, out=None) 16260 16261 Return selected slices of this array along given axis. 16262 16263 Refer to `numpy.compress` for full documentation. 16264 16265 See Also 16266 -------- 16267 numpy.compress : equivalent function""" 16268 return None 16269 def conj(self, _): 16270 """a.conj() 16271 16272 Complex-conjugate all elements. 16273 16274 Refer to `numpy.conjugate` for full documentation. 16275 16276 See Also 16277 -------- 16278 numpy.conjugate : equivalent function""" 16279 return None 16280 def conjugate(self, _): 16281 """a.conjugate() 16282 16283 Return the complex conjugate, element-wise. 16284 16285 Refer to `numpy.conjugate` for full documentation. 16286 16287 See Also 16288 -------- 16289 numpy.conjugate : equivalent function""" 16290 return None 16291 def copy(self, order): 16292 """a.copy(order='C') 16293 16294 Return a copy of the array. 16295 16296 Parameters 16297 ---------- 16298 order : {'C', 'F', 'A', 'K'}, optional 16299 Controls the memory layout of the copy. 'C' means C-order, 16300 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, 16301 'C' otherwise. 'K' means match the layout of `a` as closely 16302 as possible. (Note that this function and :func:numpy.copy are very 16303 similar, but have different default values for their order= 16304 arguments.) 16305 16306 See also 16307 -------- 16308 numpy.copy 16309 numpy.copyto 16310 16311 Examples 16312 -------- 16313 >>> x = np.array([[1,2,3],[4,5,6]], order='F') 16314 16315 >>> y = x.copy() 16316 16317 >>> x.fill(0) 16318 16319 >>> x 16320 array([[0, 0, 0], 16321 [0, 0, 0]]) 16322 16323 >>> y 16324 array([[1, 2, 3], 16325 [4, 5, 6]]) 16326 16327 >>> y.flags['C_CONTIGUOUS'] 16328 True""" 16329 return None 16330 ctypes = getset_descriptor() 16331 def cumprod(self, axis=None, dtype=None, out=None): 16332 """a.cumprod(axis=None, dtype=None, out=None) 16333 16334 Return the cumulative product of the elements along the given axis. 16335 16336 Refer to `numpy.cumprod` for full documentation. 16337 16338 See Also 16339 -------- 16340 numpy.cumprod : equivalent function""" 16341 return None 16342 def cumsum(self, axis=None, dtype=None, out=None): 16343 """a.cumsum(axis=None, dtype=None, out=None) 16344 16345 Return the cumulative sum of the elements along the given axis. 16346 16347 Refer to `numpy.cumsum` for full documentation. 16348 16349 See Also 16350 -------- 16351 numpy.cumsum : equivalent function""" 16352 return None 16353 data = getset_descriptor() 16354 def diagonal(self, offset=0, axis1=0, axis2=1): 16355 """a.diagonal(offset=0, axis1=0, axis2=1) 16356 16357 Return specified diagonals. 16358 16359 Refer to :func:`numpy.diagonal` for full documentation. 16360 16361 See Also 16362 -------- 16363 numpy.diagonal : equivalent function""" 16364 return None 16365 def dot(self, b, out=None): 16366 """a.dot(b, out=None) 16367 16368 Dot product of two arrays. 16369 16370 Refer to `numpy.dot` for full documentation. 16371 16372 See Also 16373 -------- 16374 numpy.dot : equivalent function 16375 16376 Examples 16377 -------- 16378 >>> a = np.eye(2) 16379 >>> b = np.ones((2, 2)) * 2 16380 >>> a.dot(b) 16381 array([[ 2., 2.], 16382 [ 2., 2.]]) 16383 16384 This array method can be conveniently chained: 16385 16386 >>> a.dot(b).dot(b) 16387 array([[ 8., 8.], 16388 [ 8., 8.]])""" 16389 return None 16390 dtype = getset_descriptor() 16391 def dump(self, file): 16392 """a.dump(file) 16393 16394 Dump a pickle of the array to the specified file. 16395 The array can be read back with pickle.load or numpy.load. 16396 16397 Parameters 16398 ---------- 16399 file : str 16400 A string naming the dump file.""" 16401 return None 16402 def dumps(self, _): 16403 """a.dumps() 16404 16405 Returns the pickle of the array as a string. 16406 pickle.loads or numpy.loads will convert the string back to an array. 16407 16408 Parameters 16409 ---------- 16410 None""" 16411 return None 16412 def fill(self, value): 16413 """a.fill(value) 16414 16415 Fill the array with a scalar value. 16416 16417 Parameters 16418 ---------- 16419 value : scalar 16420 All elements of `a` will be assigned this value. 16421 16422 Examples 16423 -------- 16424 >>> a = np.array([1, 2]) 16425 >>> a.fill(0) 16426 >>> a 16427 array([0, 0]) 16428 >>> a = np.empty(2) 16429 >>> a.fill(1) 16430 >>> a 16431 array([ 1., 1.])""" 16432 return None 16433 flags = getset_descriptor() 16434 flat = getset_descriptor() 16435 def flatten(self, order): 16436 """a.flatten(order='C') 16437 16438 Return a copy of the array collapsed into one dimension. 16439 16440 Parameters 16441 ---------- 16442 order : {'C', 'F', 'A'}, optional 16443 Whether to flatten in C (row-major), Fortran (column-major) order, 16444 or preserve the C/Fortran ordering from `a`. 16445 The default is 'C'. 16446 16447 Returns 16448 ------- 16449 y : ndarray 16450 A copy of the input array, flattened to one dimension. 16451 16452 See Also 16453 -------- 16454 ravel : Return a flattened array. 16455 flat : A 1-D flat iterator over the array. 16456 16457 Examples 16458 -------- 16459 >>> a = np.array([[1,2], [3,4]]) 16460 >>> a.flatten() 16461 array([1, 2, 3, 4]) 16462 >>> a.flatten('F') 16463 array([1, 3, 2, 4])""" 16464 return ndarray() 16465 def getA(self, _): 16466 """ 16467 Return `self` as an `ndarray` object. 16468 16469 Equivalent to ``np.asarray(self)``. 16470 16471 Parameters 16472 ---------- 16473 None 16474 16475 Returns 16476 ------- 16477 ret : ndarray 16478 `self` as an `ndarray` 16479 16480 Examples 16481 -------- 16482 >>> x = np.matrix(np.arange(12).reshape((3,4))); x 16483 matrix([[ 0, 1, 2, 3], 16484 [ 4, 5, 6, 7], 16485 [ 8, 9, 10, 11]]) 16486 >>> x.getA() 16487 array([[ 0, 1, 2, 3], 16488 [ 4, 5, 6, 7], 16489 [ 8, 9, 10, 11]]) 16490 16491 """ 16492 return ndarray() 16493 def getA1(self, _): 16494 """ 16495 Return `self` as a flattened `ndarray`. 16496 16497 Equivalent to ``np.asarray(x).ravel()`` 16498 16499 Parameters 16500 ---------- 16501 None 16502 16503 Returns 16504 ------- 16505 ret : ndarray 16506 `self`, 1-D, as an `ndarray` 16507 16508 Examples 16509 -------- 16510 >>> x = np.matrix(np.arange(12).reshape((3,4))); x 16511 matrix([[ 0, 1, 2, 3], 16512 [ 4, 5, 6, 7], 16513 [ 8, 9, 10, 11]]) 16514 >>> x.getA1() 16515 array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) 16516 16517 """ 16518 return ndarray() 16519 def getH(self, _): 16520 """ 16521 Returns the (complex) conjugate transpose of `self`. 16522 16523 Equivalent to ``np.transpose(self)`` if `self` is real-valued. 16524 16525 Parameters 16526 ---------- 16527 None 16528 16529 Returns 16530 ------- 16531 ret : matrix object 16532 complex conjugate transpose of `self` 16533 16534 Examples 16535 -------- 16536 >>> x = np.matrix(np.arange(12).reshape((3,4))) 16537 >>> z = x - 1j*x; z 16538 matrix([[ 0. +0.j, 1. -1.j, 2. -2.j, 3. -3.j], 16539 [ 4. -4.j, 5. -5.j, 6. -6.j, 7. -7.j], 16540 [ 8. -8.j, 9. -9.j, 10.-10.j, 11.-11.j]]) 16541 >>> z.getH() 16542 matrix([[ 0. +0.j, 4. +4.j, 8. +8.j], 16543 [ 1. +1.j, 5. +5.j, 9. +9.j], 16544 [ 2. +2.j, 6. +6.j, 10.+10.j], 16545 [ 3. +3.j, 7. +7.j, 11.+11.j]]) 16546 16547 """ 16548 return matrix() 16549 def getI(self, _): 16550 """ 16551 Returns the (multiplicative) inverse of invertible `self`. 16552 16553 Parameters 16554 ---------- 16555 None 16556 16557 Returns 16558 ------- 16559 ret : matrix object 16560 If `self` is non-singular, `ret` is such that ``ret * self`` == 16561 ``self * ret`` == ``np.matrix(np.eye(self[0,:].size)`` all return 16562 ``True``. 16563 16564 Raises 16565 ------ 16566 numpy.linalg.LinAlgError: Singular matrix 16567 If `self` is singular. 16568 16569 See Also 16570 -------- 16571 linalg.inv 16572 16573 Examples 16574 -------- 16575 >>> m = np.matrix('[1, 2; 3, 4]'); m 16576 matrix([[1, 2], 16577 [3, 4]]) 16578 >>> m.getI() 16579 matrix([[-2. , 1. ], 16580 [ 1.5, -0.5]]) 16581 >>> m.getI() * m 16582 matrix([[ 1., 0.], 16583 [ 0., 1.]]) 16584 16585 """ 16586 return matrix() 16587 def getT(self, _): 16588 """ 16589 Returns the transpose of the matrix. 16590 16591 Does *not* conjugate! For the complex conjugate transpose, use `getH`. 16592 16593 Parameters 16594 ---------- 16595 None 16596 16597 Returns 16598 ------- 16599 ret : matrix object 16600 The (non-conjugated) transpose of the matrix. 16601 16602 See Also 16603 -------- 16604 transpose, getH 16605 16606 Examples 16607 -------- 16608 >>> m = np.matrix('[1, 2; 3, 4]') 16609 >>> m 16610 matrix([[1, 2], 16611 [3, 4]]) 16612 >>> m.getT() 16613 matrix([[1, 3], 16614 [2, 4]]) 16615 16616 """ 16617 return matrix() 16618 def getfield(self, dtype, offset): 16619 """a.getfield(dtype, offset=0) 16620 16621 Returns a field of the given array as a certain type. 16622 16623 A field is a view of the array data with a given data-type. The values in 16624 the view are determined by the given type and the offset into the current 16625 array in bytes. The offset needs to be such that the view dtype fits in the 16626 array dtype; for example an array of dtype complex128 has 16-byte elements. 16627 If taking a view with a 32-bit integer (4 bytes), the offset needs to be 16628 between 0 and 12 bytes. 16629 16630 Parameters 16631 ---------- 16632 dtype : str or dtype 16633 The data type of the view. The dtype size of the view can not be larger 16634 than that of the array itself. 16635 offset : int 16636 Number of bytes to skip before beginning the element view. 16637 16638 Examples 16639 -------- 16640 >>> x = np.diag([1.+1.j]*2) 16641 >>> x[1, 1] = 2 + 4.j 16642 >>> x 16643 array([[ 1.+1.j, 0.+0.j], 16644 [ 0.+0.j, 2.+4.j]]) 16645 >>> x.getfield(np.float64) 16646 array([[ 1., 0.], 16647 [ 0., 2.]]) 16648 16649 By choosing an offset of 8 bytes we can select the complex part of the 16650 array for our view: 16651 16652 >>> x.getfield(np.float64, offset=8) 16653 array([[ 1., 0.], 16654 [ 0., 4.]])""" 16655 return array() 16656 imag = getset_descriptor() 16657 def item(self, ESCargs): 16658 """a.item(*args) 16659 16660 Copy an element of an array to a standard Python scalar and return it. 16661 16662 Parameters 16663 ---------- 16664 \*args : Arguments (variable number and type) 16665 16666 * none: in this case, the method only works for arrays 16667 with one element (`a.size == 1`), which element is 16668 copied into a standard Python scalar object and returned. 16669 16670 * int_type: this argument is interpreted as a flat index into 16671 the array, specifying which element to copy and return. 16672 16673 * tuple of int_types: functions as does a single int_type argument, 16674 except that the argument is interpreted as an nd-index into the 16675 array. 16676 16677 Returns 16678 ------- 16679 z : Standard Python scalar object 16680 A copy of the specified element of the array as a suitable 16681 Python scalar 16682 16683 Notes 16684 ----- 16685 When the data type of `a` is longdouble or clongdouble, item() returns 16686 a scalar array object because there is no available Python scalar that 16687 would not lose information. Void arrays return a buffer object for item(), 16688 unless fields are defined, in which case a tuple is returned. 16689 16690 `item` is very similar to a[args], except, instead of an array scalar, 16691 a standard Python scalar is returned. This can be useful for speeding up 16692 access to elements of the array and doing arithmetic on elements of the 16693 array using Python's optimized math. 16694 16695 Examples 16696 -------- 16697 >>> x = np.random.randint(9, size=(3, 3)) 16698 >>> x 16699 array([[3, 1, 7], 16700 [2, 8, 3], 16701 [8, 5, 3]]) 16702 >>> x.item(3) 16703 2 16704 >>> x.item(7) 16705 5 16706 >>> x.item((0, 1)) 16707 1 16708 >>> x.item((2, 2)) 16709 3""" 16710 return Standard() 16711 def itemset(self, ESCargs): 16712 """a.itemset(*args) 16713 16714 Insert scalar into an array (scalar is cast to array's dtype, if possible) 16715 16716 There must be at least 1 argument, and define the last argument 16717 as *item*. Then, ``a.itemset(*args)`` is equivalent to but faster 16718 than ``a[args] = item``. The item should be a scalar value and `args` 16719 must select a single item in the array `a`. 16720 16721 Parameters 16722 ---------- 16723 \*args : Arguments 16724 If one argument: a scalar, only used in case `a` is of size 1. 16725 If two arguments: the last argument is the value to be set 16726 and must be a scalar, the first argument specifies a single array 16727 element location. It is either an int or a tuple. 16728 16729 Notes 16730 ----- 16731 Compared to indexing syntax, `itemset` provides some speed increase 16732 for placing a scalar into a particular location in an `ndarray`, 16733 if you must do this. However, generally this is discouraged: 16734 among other problems, it complicates the appearance of the code. 16735 Also, when using `itemset` (and `item`) inside a loop, be sure 16736 to assign the methods to a local variable to avoid the attribute 16737 look-up at each loop iteration. 16738 16739 Examples 16740 -------- 16741 >>> x = np.random.randint(9, size=(3, 3)) 16742 >>> x 16743 array([[3, 1, 7], 16744 [2, 8, 3], 16745 [8, 5, 3]]) 16746 >>> x.itemset(4, 0) 16747 >>> x.itemset((2, 2), 9) 16748 >>> x 16749 array([[3, 1, 7], 16750 [2, 0, 3], 16751 [8, 5, 9]])""" 16752 return None 16753 itemsize = getset_descriptor() 16754 def max(self=None, axis=None, out=None): 16755 """ 16756 Return the maximum value along an axis. 16757 16758 Parameters 16759 ---------- 16760 See `amax` for complete descriptions 16761 16762 See Also 16763 -------- 16764 amax, ndarray.max 16765 16766 Notes 16767 ----- 16768 This is the same as `ndarray.max`, but returns a `matrix` object 16769 where `ndarray.max` would return an ndarray. 16770 16771 Examples 16772 -------- 16773 >>> x = np.matrix(np.arange(12).reshape((3,4))); x 16774 matrix([[ 0, 1, 2, 3], 16775 [ 4, 5, 6, 7], 16776 [ 8, 9, 10, 11]]) 16777 >>> x.max() 16778 11 16779 >>> x.max(0) 16780 matrix([[ 8, 9, 10, 11]]) 16781 >>> x.max(1) 16782 matrix([[ 3], 16783 [ 7], 16784 [11]]) 16785 16786 """ 16787 return None 16788 def mean(self=None, axis=None, dtype=None, out=None): 16789 """ 16790 Returns the average of the matrix elements along the given axis. 16791 16792 Refer to `numpy.mean` for full documentation. 16793 16794 See Also 16795 -------- 16796 numpy.mean 16797 16798 Notes 16799 ----- 16800 Same as `ndarray.mean` except that, where that returns an `ndarray`, 16801 this returns a `matrix` object. 16802 16803 Examples 16804 -------- 16805 >>> x = np.matrix(np.arange(12).reshape((3, 4))) 16806 >>> x 16807 matrix([[ 0, 1, 2, 3], 16808 [ 4, 5, 6, 7], 16809 [ 8, 9, 10, 11]]) 16810 >>> x.mean() 16811 5.5 16812 >>> x.mean(0) 16813 matrix([[ 4., 5., 6., 7.]]) 16814 >>> x.mean(1) 16815 matrix([[ 1.5], 16816 [ 5.5], 16817 [ 9.5]]) 16818 16819 """ 16820 return None 16821 def min(self=None, axis=None, out=None): 16822 """ 16823 Return the minimum value along an axis. 16824 16825 Parameters 16826 ---------- 16827 See `amin` for complete descriptions. 16828 16829 See Also 16830 -------- 16831 amin, ndarray.min 16832 16833 Notes 16834 ----- 16835 This is the same as `ndarray.min`, but returns a `matrix` object 16836 where `ndarray.min` would return an ndarray. 16837 16838 Examples 16839 -------- 16840 >>> x = -np.matrix(np.arange(12).reshape((3,4))); x 16841 matrix([[ 0, -1, -2, -3], 16842 [ -4, -5, -6, -7], 16843 [ -8, -9, -10, -11]]) 16844 >>> x.min() 16845 -11 16846 >>> x.min(0) 16847 matrix([[ -8, -9, -10, -11]]) 16848 >>> x.min(1) 16849 matrix([[ -3], 16850 [ -7], 16851 [-11]]) 16852 16853 """ 16854 return None 16855 nbytes = getset_descriptor() 16856 ndim = getset_descriptor() 16857 def newbyteorder(self, new_order): 16858 """arr.newbyteorder(new_order='S') 16859 16860 Return the array with the same data viewed with a different byte order. 16861 16862 Equivalent to:: 16863 16864 arr.view(arr.dtype.newbytorder(new_order)) 16865 16866 Changes are also made in all fields and sub-arrays of the array data 16867 type. 16868 16869 16870 16871 Parameters 16872 ---------- 16873 new_order : string, optional 16874 Byte order to force; a value from the byte order specifications 16875 above. `new_order` codes can be any of:: 16876 16877 * 'S' - swap dtype from current to opposite endian 16878 * {'<', 'L'} - little endian 16879 * {'>', 'B'} - big endian 16880 * {'=', 'N'} - native order 16881 * {'|', 'I'} - ignore (no change to byte order) 16882 16883 The default value ('S') results in swapping the current 16884 byte order. The code does a case-insensitive check on the first 16885 letter of `new_order` for the alternatives above. For example, 16886 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 16887 16888 16889 Returns 16890 ------- 16891 new_arr : array 16892 New array object with the dtype reflecting given change to the 16893 byte order.""" 16894 return array() 16895 def nonzero(self, _): 16896 """a.nonzero() 16897 16898 Return the indices of the elements that are non-zero. 16899 16900 Refer to `numpy.nonzero` for full documentation. 16901 16902 See Also 16903 -------- 16904 numpy.nonzero : equivalent function""" 16905 return None 16906 def partition(self, kth, axis, kind, order): 16907 """a.partition(kth, axis=-1, kind='introselect', order=None) 16908 16909 Rearranges the elements in the array in such a way that value of the 16910 element in kth position is in the position it would be in a sorted array. 16911 All elements smaller than the kth element are moved before this element and 16912 all equal or greater are moved behind it. The ordering of the elements in 16913 the two partitions is undefined. 16914 16915 .. versionadded:: 1.8.0 16916 16917 Parameters 16918 ---------- 16919 kth : int or sequence of ints 16920 Element index to partition by. The kth element value will be in its 16921 final sorted position and all smaller elements will be moved before it 16922 and all equal or greater elements behind it. 16923 The order all elements in the partitions is undefined. 16924 If provided with a sequence of kth it will partition all elements 16925 indexed by kth of them into their sorted position at once. 16926 axis : int, optional 16927 Axis along which to sort. Default is -1, which means sort along the 16928 last axis. 16929 kind : {'introselect'}, optional 16930 Selection algorithm. Default is 'introselect'. 16931 order : list, optional 16932 When `a` is an array with fields defined, this argument specifies 16933 which fields to compare first, second, etc. Not all fields need be 16934 specified. 16935 16936 See Also 16937 -------- 16938 numpy.partition : Return a parititioned copy of an array. 16939 argpartition : Indirect partition. 16940 sort : Full sort. 16941 16942 Notes 16943 ----- 16944 See ``np.partition`` for notes on the different algorithms. 16945 16946 Examples 16947 -------- 16948 >>> a = np.array([3, 4, 2, 1]) 16949 >>> a.partition(a, 3) 16950 >>> a 16951 array([2, 1, 3, 4]) 16952 16953 >>> a.partition((1, 3)) 16954 array([1, 2, 3, 4])""" 16955 return None 16956 def prod(self=None, axis=None, dtype=None, out=None): 16957 """ 16958 Return the product of the array elements over the given axis. 16959 16960 Refer to `prod` for full documentation. 16961 16962 See Also 16963 -------- 16964 prod, ndarray.prod 16965 16966 Notes 16967 ----- 16968 Same as `ndarray.prod`, except, where that returns an `ndarray`, this 16969 returns a `matrix` object instead. 16970 16971 Examples 16972 -------- 16973 >>> x = np.matrix(np.arange(12).reshape((3,4))); x 16974 matrix([[ 0, 1, 2, 3], 16975 [ 4, 5, 6, 7], 16976 [ 8, 9, 10, 11]]) 16977 >>> x.prod() 16978 0 16979 >>> x.prod(0) 16980 matrix([[ 0, 45, 120, 231]]) 16981 >>> x.prod(1) 16982 matrix([[ 0], 16983 [ 840], 16984 [7920]]) 16985 16986 """ 16987 return None 16988 def ptp(self=None, axis=None, out=None): 16989 """ 16990 Peak-to-peak (maximum - minimum) value along the given axis. 16991 16992 Refer to `numpy.ptp` for full documentation. 16993 16994 See Also 16995 -------- 16996 numpy.ptp 16997 16998 Notes 16999 ----- 17000 Same as `ndarray.ptp`, except, where that would return an `ndarray` object, 17001 this returns a `matrix` object. 17002 17003 Examples 17004 -------- 17005 >>> x = np.matrix(np.arange(12).reshape((3,4))); x 17006 matrix([[ 0, 1, 2, 3], 17007 [ 4, 5, 6, 7], 17008 [ 8, 9, 10, 11]]) 17009 >>> x.ptp() 17010 11 17011 >>> x.ptp(0) 17012 matrix([[8, 8, 8, 8]]) 17013 >>> x.ptp(1) 17014 matrix([[3], 17015 [3], 17016 [3]]) 17017 17018 """ 17019 return None 17020 def put(self, indices, values, mode=_raise): 17021 """a.put(indices, values, mode='raise') 17022 17023 Set ``a.flat[n] = values[n]`` for all `n` in indices. 17024 17025 Refer to `numpy.put` for full documentation. 17026 17027 See Also 17028 -------- 17029 numpy.put : equivalent function""" 17030 return None 17031 def ravel(self, order): 17032 """a.ravel([order]) 17033 17034 Return a flattened array. 17035 17036 Refer to `numpy.ravel` for full documentation. 17037 17038 See Also 17039 -------- 17040 numpy.ravel : equivalent function 17041 17042 ndarray.flat : a flat iterator on the array.""" 17043 return None 17044 real = getset_descriptor() 17045 def repeat(self, repeats, axis=None): 17046 """a.repeat(repeats, axis=None) 17047 17048 Repeat elements of an array. 17049 17050 Refer to `numpy.repeat` for full documentation. 17051 17052 See Also 17053 -------- 17054 numpy.repeat : equivalent function""" 17055 return None 17056 def reshape(self, shape, order=C): 17057 """a.reshape(shape, order='C') 17058 17059 Returns an array containing the same data with a new shape. 17060 17061 Refer to `numpy.reshape` for full documentation. 17062 17063 See Also 17064 -------- 17065 numpy.reshape : equivalent function""" 17066 return None 17067 def resize(self, new_shape, refcheck): 17068 """a.resize(new_shape, refcheck=True) 17069 17070 Change shape and size of array in-place. 17071 17072 Parameters 17073 ---------- 17074 new_shape : tuple of ints, or `n` ints 17075 Shape of resized array. 17076 refcheck : bool, optional 17077 If False, reference count will not be checked. Default is True. 17078 17079 Returns 17080 ------- 17081 None 17082 17083 Raises 17084 ------ 17085 ValueError 17086 If `a` does not own its own data or references or views to it exist, 17087 and the data memory must be changed. 17088 17089 SystemError 17090 If the `order` keyword argument is specified. This behaviour is a 17091 bug in NumPy. 17092 17093 See Also 17094 -------- 17095 resize : Return a new array with the specified shape. 17096 17097 Notes 17098 ----- 17099 This reallocates space for the data area if necessary. 17100 17101 Only contiguous arrays (data elements consecutive in memory) can be 17102 resized. 17103 17104 The purpose of the reference count check is to make sure you 17105 do not use this array as a buffer for another Python object and then 17106 reallocate the memory. However, reference counts can increase in 17107 other ways so if you are sure that you have not shared the memory 17108 for this array with another Python object, then you may safely set 17109 `refcheck` to False. 17110 17111 Examples 17112 -------- 17113 Shrinking an array: array is flattened (in the order that the data are 17114 stored in memory), resized, and reshaped: 17115 17116 >>> a = np.array([[0, 1], [2, 3]], order='C') 17117 >>> a.resize((2, 1)) 17118 >>> a 17119 array([[0], 17120 [1]]) 17121 17122 >>> a = np.array([[0, 1], [2, 3]], order='F') 17123 >>> a.resize((2, 1)) 17124 >>> a 17125 array([[0], 17126 [2]]) 17127 17128 Enlarging an array: as above, but missing entries are filled with zeros: 17129 17130 >>> b = np.array([[0, 1], [2, 3]]) 17131 >>> b.resize(2, 3) # new_shape parameter doesn't have to be a tuple 17132 >>> b 17133 array([[0, 1, 2], 17134 [3, 0, 0]]) 17135 17136 Referencing an array prevents resizing... 17137 17138 >>> c = a 17139 >>> a.resize((1, 1)) 17140 Traceback (most recent call last): 17141 ... 17142 ValueError: cannot resize an array that has been referenced ... 17143 17144 Unless `refcheck` is False: 17145 17146 >>> a.resize((1, 1), refcheck=False) 17147 >>> a 17148 array([[0]]) 17149 >>> c 17150 array([[0]])""" 17151 return None 17152 def round(self, decimals=0, out=None): 17153 """a.round(decimals=0, out=None) 17154 17155 Return `a` with each element rounded to the given number of decimals. 17156 17157 Refer to `numpy.around` for full documentation. 17158 17159 See Also 17160 -------- 17161 numpy.around : equivalent function""" 17162 return None 17163 def searchsorted(self, v, side=left, sorter=None): 17164 """a.searchsorted(v, side='left', sorter=None) 17165 17166 Find indices where elements of v should be inserted in a to maintain order. 17167 17168 For full documentation, see `numpy.searchsorted` 17169 17170 See Also 17171 -------- 17172 numpy.searchsorted : equivalent function""" 17173 return None 17174 def setfield(self, val, dtype, offset): 17175 """a.setfield(val, dtype, offset=0) 17176 17177 Put a value into a specified place in a field defined by a data-type. 17178 17179 Place `val` into `a`'s field defined by `dtype` and beginning `offset` 17180 bytes into the field. 17181 17182 Parameters 17183 ---------- 17184 val : object 17185 Value to be placed in field. 17186 dtype : dtype object 17187 Data-type of the field in which to place `val`. 17188 offset : int, optional 17189 The number of bytes into the field at which to place `val`. 17190 17191 Returns 17192 ------- 17193 None 17194 17195 See Also 17196 -------- 17197 getfield 17198 17199 Examples 17200 -------- 17201 >>> x = np.eye(3) 17202 >>> x.getfield(np.float64) 17203 array([[ 1., 0., 0.], 17204 [ 0., 1., 0.], 17205 [ 0., 0., 1.]]) 17206 >>> x.setfield(3, np.int32) 17207 >>> x.getfield(np.int32) 17208 array([[3, 3, 3], 17209 [3, 3, 3], 17210 [3, 3, 3]]) 17211 >>> x 17212 array([[ 1.00000000e+000, 1.48219694e-323, 1.48219694e-323], 17213 [ 1.48219694e-323, 1.00000000e+000, 1.48219694e-323], 17214 [ 1.48219694e-323, 1.48219694e-323, 1.00000000e+000]]) 17215 >>> x.setfield(np.eye(3), np.int32) 17216 >>> x 17217 array([[ 1., 0., 0.], 17218 [ 0., 1., 0.], 17219 [ 0., 0., 1.]])""" 17220 return None 17221 def setflags(self, write, align, uic): 17222 """a.setflags(write=None, align=None, uic=None) 17223 17224 Set array flags WRITEABLE, ALIGNED, and UPDATEIFCOPY, respectively. 17225 17226 These Boolean-valued flags affect how numpy interprets the memory 17227 area used by `a` (see Notes below). The ALIGNED flag can only 17228 be set to True if the data is actually aligned according to the type. 17229 The UPDATEIFCOPY flag can never be set to True. The flag WRITEABLE 17230 can only be set to True if the array owns its own memory, or the 17231 ultimate owner of the memory exposes a writeable buffer interface, 17232 or is a string. (The exception for string is made so that unpickling 17233 can be done without copying memory.) 17234 17235 Parameters 17236 ---------- 17237 write : bool, optional 17238 Describes whether or not `a` can be written to. 17239 align : bool, optional 17240 Describes whether or not `a` is aligned properly for its type. 17241 uic : bool, optional 17242 Describes whether or not `a` is a copy of another "base" array. 17243 17244 Notes 17245 ----- 17246 Array flags provide information about how the memory area used 17247 for the array is to be interpreted. There are 6 Boolean flags 17248 in use, only three of which can be changed by the user: 17249 UPDATEIFCOPY, WRITEABLE, and ALIGNED. 17250 17251 WRITEABLE (W) the data area can be written to; 17252 17253 ALIGNED (A) the data and strides are aligned appropriately for the hardware 17254 (as determined by the compiler); 17255 17256 UPDATEIFCOPY (U) this array is a copy of some other array (referenced 17257 by .base). When this array is deallocated, the base array will be 17258 updated with the contents of this array. 17259 17260 All flags can be accessed using their first (upper case) letter as well 17261 as the full name. 17262 17263 Examples 17264 -------- 17265 >>> y 17266 array([[3, 1, 7], 17267 [2, 0, 0], 17268 [8, 5, 9]]) 17269 >>> y.flags 17270 C_CONTIGUOUS : True 17271 F_CONTIGUOUS : False 17272 OWNDATA : True 17273 WRITEABLE : True 17274 ALIGNED : True 17275 UPDATEIFCOPY : False 17276 >>> y.setflags(write=0, align=0) 17277 >>> y.flags 17278 C_CONTIGUOUS : True 17279 F_CONTIGUOUS : False 17280 OWNDATA : True 17281 WRITEABLE : False 17282 ALIGNED : False 17283 UPDATEIFCOPY : False 17284 >>> y.setflags(uic=1) 17285 Traceback (most recent call last): 17286 File "<stdin>", line 1, in <module> 17287 ValueError: cannot set UPDATEIFCOPY flag to True""" 17288 return None 17289 shape = getset_descriptor() 17290 size = getset_descriptor() 17291 def sort(self, axis, kind, order): 17292 """a.sort(axis=-1, kind='quicksort', order=None) 17293 17294 Sort an array, in-place. 17295 17296 Parameters 17297 ---------- 17298 axis : int, optional 17299 Axis along which to sort. Default is -1, which means sort along the 17300 last axis. 17301 kind : {'quicksort', 'mergesort', 'heapsort'}, optional 17302 Sorting algorithm. Default is 'quicksort'. 17303 order : list, optional 17304 When `a` is an array with fields defined, this argument specifies 17305 which fields to compare first, second, etc. Not all fields need be 17306 specified. 17307 17308 See Also 17309 -------- 17310 numpy.sort : Return a sorted copy of an array. 17311 argsort : Indirect sort. 17312 lexsort : Indirect stable sort on multiple keys. 17313 searchsorted : Find elements in sorted array. 17314 partition: Partial sort. 17315 17316 Notes 17317 ----- 17318 See ``sort`` for notes on the different sorting algorithms. 17319 17320 Examples 17321 -------- 17322 >>> a = np.array([[1,4], [3,1]]) 17323 >>> a.sort(axis=1) 17324 >>> a 17325 array([[1, 4], 17326 [1, 3]]) 17327 >>> a.sort(axis=0) 17328 >>> a 17329 array([[1, 3], 17330 [1, 4]]) 17331 17332 Use the `order` keyword to specify a field to use when sorting a 17333 structured array: 17334 17335 >>> a = np.array([('a', 2), ('c', 1)], dtype=[('x', 'S1'), ('y', int)]) 17336 >>> a.sort(order='y') 17337 >>> a 17338 array([('c', 1), ('a', 2)], 17339 dtype=[('x', '|S1'), ('y', '<i4')])""" 17340 return None 17341 def squeeze(self, axis=None): 17342 """a.squeeze(axis=None) 17343 17344 Remove single-dimensional entries from the shape of `a`. 17345 17346 Refer to `numpy.squeeze` for full documentation. 17347 17348 See Also 17349 -------- 17350 numpy.squeeze : equivalent function""" 17351 return None 17352 def std(self=0, axis=None, dtype=None, out=None, ddof=0): 17353 """ 17354 Return the standard deviation of the array elements along the given axis. 17355 17356 Refer to `numpy.std` for full documentation. 17357 17358 See Also 17359 -------- 17360 numpy.std 17361 17362 Notes 17363 ----- 17364 This is the same as `ndarray.std`, except that where an `ndarray` would 17365 be returned, a `matrix` object is returned instead. 17366 17367 Examples 17368 -------- 17369 >>> x = np.matrix(np.arange(12).reshape((3, 4))) 17370 >>> x 17371 matrix([[ 0, 1, 2, 3], 17372 [ 4, 5, 6, 7], 17373 [ 8, 9, 10, 11]]) 17374 >>> x.std() 17375 3.4520525295346629 17376 >>> x.std(0) 17377 matrix([[ 3.26598632, 3.26598632, 3.26598632, 3.26598632]]) 17378 >>> x.std(1) 17379 matrix([[ 1.11803399], 17380 [ 1.11803399], 17381 [ 1.11803399]]) 17382 17383 """ 17384 return None 17385 strides = getset_descriptor() 17386 def sum(self=None, axis=None, dtype=None, out=None): 17387 """ 17388 Returns the sum of the matrix elements, along the given axis. 17389 17390 Refer to `numpy.sum` for full documentation. 17391 17392 See Also 17393 -------- 17394 numpy.sum 17395 17396 Notes 17397 ----- 17398 This is the same as `ndarray.sum`, except that where an `ndarray` would 17399 be returned, a `matrix` object is returned instead. 17400 17401 Examples 17402 -------- 17403 >>> x = np.matrix([[1, 2], [4, 3]]) 17404 >>> x.sum() 17405 10 17406 >>> x.sum(axis=1) 17407 matrix([[3], 17408 [7]]) 17409 >>> x.sum(axis=1, dtype='float') 17410 matrix([[ 3.], 17411 [ 7.]]) 17412 >>> out = np.zeros((1, 2), dtype='float') 17413 >>> x.sum(axis=1, dtype='float', out=out) 17414 matrix([[ 3.], 17415 [ 7.]]) 17416 17417 """ 17418 return None 17419 def swapaxes(self, axis1, axis2): 17420 """a.swapaxes(axis1, axis2) 17421 17422 Return a view of the array with `axis1` and `axis2` interchanged. 17423 17424 Refer to `numpy.swapaxes` for full documentation. 17425 17426 See Also 17427 -------- 17428 numpy.swapaxes : equivalent function""" 17429 return None 17430 def take(self, indices, axis=None, out=None, mode=_raise): 17431 """a.take(indices, axis=None, out=None, mode='raise') 17432 17433 Return an array formed from the elements of `a` at the given indices. 17434 17435 Refer to `numpy.take` for full documentation. 17436 17437 See Also 17438 -------- 17439 numpy.take : equivalent function""" 17440 return None 17441 def tofile(self, fid, sep, format): 17442 """a.tofile(fid, sep="", format="%s") 17443 17444 Write array to a file as text or binary (default). 17445 17446 Data is always written in 'C' order, independent of the order of `a`. 17447 The data produced by this method can be recovered using the function 17448 fromfile(). 17449 17450 Parameters 17451 ---------- 17452 fid : file or str 17453 An open file object, or a string containing a filename. 17454 sep : str 17455 Separator between array items for text output. 17456 If "" (empty), a binary file is written, equivalent to 17457 ``file.write(a.tostring())``. 17458 format : str 17459 Format string for text file output. 17460 Each entry in the array is formatted to text by first converting 17461 it to the closest Python type, and then using "format" % item. 17462 17463 Notes 17464 ----- 17465 This is a convenience function for quick storage of array data. 17466 Information on endianness and precision is lost, so this method is not a 17467 good choice for files intended to archive data or transport data between 17468 machines with different endianness. Some of these problems can be overcome 17469 by outputting the data as text files, at the expense of speed and file 17470 size.""" 17471 return None 17472 def tolist(self, _): 17473 """ 17474 Return the matrix as a (possibly nested) list. 17475 17476 See `ndarray.tolist` for full documentation. 17477 17478 See Also 17479 -------- 17480 ndarray.tolist 17481 17482 Examples 17483 -------- 17484 >>> x = np.matrix(np.arange(12).reshape((3,4))); x 17485 matrix([[ 0, 1, 2, 3], 17486 [ 4, 5, 6, 7], 17487 [ 8, 9, 10, 11]]) 17488 >>> x.tolist() 17489 [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]] 17490 17491 """ 17492 return None 17493 def tostring(self, order): 17494 """a.tostring(order='C') 17495 17496 Construct a Python string containing the raw data bytes in the array. 17497 17498 Constructs a Python string showing a copy of the raw contents of 17499 data memory. The string can be produced in either 'C' or 'Fortran', 17500 or 'Any' order (the default is 'C'-order). 'Any' order means C-order 17501 unless the F_CONTIGUOUS flag in the array is set, in which case it 17502 means 'Fortran' order. 17503 17504 Parameters 17505 ---------- 17506 order : {'C', 'F', None}, optional 17507 Order of the data for multidimensional arrays: 17508 C, Fortran, or the same as for the original array. 17509 17510 Returns 17511 ------- 17512 s : str 17513 A Python string exhibiting a copy of `a`'s raw data. 17514 17515 Examples 17516 -------- 17517 >>> x = np.array([[0, 1], [2, 3]]) 17518 >>> x.tostring() 17519 '\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00' 17520 >>> x.tostring('C') == x.tostring() 17521 True 17522 >>> x.tostring('F') 17523 '\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00'""" 17524 return str() 17525 def trace(self, offset=0, axis1=0, axis2=1, dtype=None, out=None): 17526 """a.trace(offset=0, axis1=0, axis2=1, dtype=None, out=None) 17527 17528 Return the sum along diagonals of the array. 17529 17530 Refer to `numpy.trace` for full documentation. 17531 17532 See Also 17533 -------- 17534 numpy.trace : equivalent function""" 17535 return None 17536 def transpose(self, axes): 17537 """a.transpose(*axes) 17538 17539 Returns a view of the array with axes transposed. 17540 17541 For a 1-D array, this has no effect. (To change between column and 17542 row vectors, first cast the 1-D array into a matrix object.) 17543 For a 2-D array, this is the usual matrix transpose. 17544 For an n-D array, if axes are given, their order indicates how the 17545 axes are permuted (see Examples). If axes are not provided and 17546 ``a.shape = (i[0], i[1], ... i[n-2], i[n-1])``, then 17547 ``a.transpose().shape = (i[n-1], i[n-2], ... i[1], i[0])``. 17548 17549 Parameters 17550 ---------- 17551 axes : None, tuple of ints, or `n` ints 17552 17553 * None or no argument: reverses the order of the axes. 17554 17555 * tuple of ints: `i` in the `j`-th place in the tuple means `a`'s 17556 `i`-th axis becomes `a.transpose()`'s `j`-th axis. 17557 17558 * `n` ints: same as an n-tuple of the same ints (this form is 17559 intended simply as a "convenience" alternative to the tuple form) 17560 17561 Returns 17562 ------- 17563 out : ndarray 17564 View of `a`, with axes suitably permuted. 17565 17566 See Also 17567 -------- 17568 ndarray.T : Array property returning the array transposed. 17569 17570 Examples 17571 -------- 17572 >>> a = np.array([[1, 2], [3, 4]]) 17573 >>> a 17574 array([[1, 2], 17575 [3, 4]]) 17576 >>> a.transpose() 17577 array([[1, 3], 17578 [2, 4]]) 17579 >>> a.transpose((1, 0)) 17580 array([[1, 3], 17581 [2, 4]]) 17582 >>> a.transpose(1, 0) 17583 array([[1, 3], 17584 [2, 4]])""" 17585 return ndarray() 17586 def var(self=0, axis=None, dtype=None, out=None, ddof=0): 17587 """ 17588 Returns the variance of the matrix elements, along the given axis. 17589 17590 Refer to `numpy.var` for full documentation. 17591 17592 See Also 17593 -------- 17594 numpy.var 17595 17596 Notes 17597 ----- 17598 This is the same as `ndarray.var`, except that where an `ndarray` would 17599 be returned, a `matrix` object is returned instead. 17600 17601 Examples 17602 -------- 17603 >>> x = np.matrix(np.arange(12).reshape((3, 4))) 17604 >>> x 17605 matrix([[ 0, 1, 2, 3], 17606 [ 4, 5, 6, 7], 17607 [ 8, 9, 10, 11]]) 17608 >>> x.var() 17609 11.916666666666666 17610 >>> x.var(0) 17611 matrix([[ 10.66666667, 10.66666667, 10.66666667, 10.66666667]]) 17612 >>> x.var(1) 17613 matrix([[ 1.25], 17614 [ 1.25], 17615 [ 1.25]]) 17616 17617 """ 17618 return None 17619 def view(self, dtype, type): 17620 """a.view(dtype=None, type=None) 17621 17622 New view of array with the same data. 17623 17624 Parameters 17625 ---------- 17626 dtype : data-type or ndarray sub-class, optional 17627 Data-type descriptor of the returned view, e.g., float32 or int16. The 17628 default, None, results in the view having the same data-type as `a`. 17629 This argument can also be specified as an ndarray sub-class, which 17630 then specifies the type of the returned object (this is equivalent to 17631 setting the ``type`` parameter). 17632 type : Python type, optional 17633 Type of the returned view, e.g., ndarray or matrix. Again, the 17634 default None results in type preservation. 17635 17636 Notes 17637 ----- 17638 ``a.view()`` is used two different ways: 17639 17640 ``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view 17641 of the array's memory with a different data-type. This can cause a 17642 reinterpretation of the bytes of memory. 17643 17644 ``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just 17645 returns an instance of `ndarray_subclass` that looks at the same array 17646 (same shape, dtype, etc.) This does not cause a reinterpretation of the 17647 memory. 17648 17649 For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of 17650 bytes per entry than the previous dtype (for example, converting a 17651 regular array to a structured array), then the behavior of the view 17652 cannot be predicted just from the superficial appearance of ``a`` (shown 17653 by ``print(a)``). It also depends on exactly how ``a`` is stored in 17654 memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus 17655 defined as a slice or transpose, etc., the view may give different 17656 results. 17657 17658 17659 Examples 17660 -------- 17661 >>> x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)]) 17662 17663 Viewing array data using a different type and dtype: 17664 17665 >>> y = x.view(dtype=np.int16, type=np.matrix) 17666 >>> y 17667 matrix([[513]], dtype=int16) 17668 >>> print type(y) 17669 <class 'numpy.matrixlib.defmatrix.matrix'> 17670 17671 Creating a view on a structured array so it can be used in calculations 17672 17673 >>> x = np.array([(1, 2),(3,4)], dtype=[('a', np.int8), ('b', np.int8)]) 17674 >>> xv = x.view(dtype=np.int8).reshape(-1,2) 17675 >>> xv 17676 array([[1, 2], 17677 [3, 4]], dtype=int8) 17678 >>> xv.mean(0) 17679 array([ 2., 3.]) 17680 17681 Making changes to the view changes the underlying array 17682 17683 >>> xv[0,1] = 20 17684 >>> print x 17685 [(1, 20) (3, 4)] 17686 17687 Using a view to convert an array to a record array: 17688 17689 >>> z = x.view(np.recarray) 17690 >>> z.a 17691 array([1], dtype=int8) 17692 17693 Views share data: 17694 17695 >>> x[0] = (9, 10) 17696 >>> z[0] 17697 (9, 10) 17698 17699 Views that change the dtype size (bytes per entry) should normally be 17700 avoided on arrays defined by slices, transposes, fortran-ordering, etc.: 17701 17702 >>> x = np.array([[1,2,3],[4,5,6]], dtype=np.int16) 17703 >>> y = x[:, 0:2] 17704 >>> y 17705 array([[1, 2], 17706 [4, 5]], dtype=int16) 17707 >>> y.view(dtype=[('width', np.int16), ('length', np.int16)]) 17708 Traceback (most recent call last): 17709 File "<stdin>", line 1, in <module> 17710 ValueError: new type not compatible with array. 17711 >>> z = y.copy() 17712 >>> z.view(dtype=[('width', np.int16), ('length', np.int16)]) 17713 array([[(1, 2)], 17714 [(4, 5)]], dtype=[('width', '<i2'), ('length', '<i2')])""" 17715 return None 17716 def amax(a=False, axis=None, out=None, keepdims=False): 17717 """ 17718 Return the maximum of an array or maximum along an axis. 17719 17720 Parameters 17721 ---------- 17722 a : array_like 17723 Input data. 17724 axis : int, optional 17725 Axis along which to operate. By default, flattened input is used. 17726 out : ndarray, optional 17727 Alternative output array in which to place the result. Must 17728 be of the same shape and buffer length as the expected output. 17729 See `doc.ufuncs` (Section "Output arguments") for more details. 17730 keepdims : bool, optional 17731 If this is set to True, the axes which are reduced are left 17732 in the result as dimensions with size one. With this option, 17733 the result will broadcast correctly against the original `arr`. 17734 17735 Returns 17736 ------- 17737 amax : ndarray or scalar 17738 Maximum of `a`. If `axis` is None, the result is a scalar value. 17739 If `axis` is given, the result is an array of dimension 17740 ``a.ndim - 1``. 17741 17742 See Also 17743 -------- 17744 amin : 17745 The minimum value of an array along a given axis, propagating any NaNs. 17746 nanmax : 17747 The maximum value of an array along a given axis, ignoring any NaNs. 17748 maximum : 17749 Element-wise maximum of two arrays, propagating any NaNs. 17750 fmax : 17751 Element-wise maximum of two arrays, ignoring any NaNs. 17752 argmax : 17753 Return the indices of the maximum values. 17754 17755 nanmin, minimum, fmin 17756 17757 Notes 17758 ----- 17759 NaN values are propagated, that is if at least one item is NaN, the 17760 corresponding max value will be NaN as well. To ignore NaN values 17761 (MATLAB behavior), please use nanmax. 17762 17763 Don't use `amax` for element-wise comparison of 2 arrays; when 17764 ``a.shape[0]`` is 2, ``maximum(a[0], a[1])`` is faster than 17765 ``amax(a, axis=0)``. 17766 17767 Examples 17768 -------- 17769 >>> a = np.arange(4).reshape((2,2)) 17770 >>> a 17771 array([[0, 1], 17772 [2, 3]]) 17773 >>> np.amax(a) # Maximum of the flattened array 17774 3 17775 >>> np.amax(a, axis=0) # Maxima along the first axis 17776 array([2, 3]) 17777 >>> np.amax(a, axis=1) # Maxima along the second axis 17778 array([1, 3]) 17779 17780 >>> b = np.arange(5, dtype=np.float) 17781 >>> b[2] = np.NaN 17782 >>> np.amax(b) 17783 nan 17784 >>> np.nanmax(b) 17785 4.0 17786 17787 """ 17788 return ndarray() if False else float() 17789 def maximum(x1, x2, out=None): 17790 """maximum(x1, x2[, out]) 17791 17792 Element-wise maximum of array elements. 17793 17794 Compare two arrays and returns a new array containing the element-wise 17795 maxima. If one of the elements being compared is a nan, then that element 17796 is returned. If both elements are nans then the first is returned. The 17797 latter distinction is important for complex nans, which are defined as at 17798 least one of the real or imaginary parts being a nan. The net effect is 17799 that nans are propagated. 17800 17801 Parameters 17802 ---------- 17803 x1, x2 : array_like 17804 The arrays holding the elements to be compared. They must have 17805 the same shape, or shapes that can be broadcast to a single shape. 17806 17807 Returns 17808 ------- 17809 y : {ndarray, scalar} 17810 The maximum of `x1` and `x2`, element-wise. Returns scalar if 17811 both `x1` and `x2` are scalars. 17812 17813 See Also 17814 -------- 17815 minimum : 17816 Element-wise minimum of two arrays, propagating any NaNs. 17817 fmax : 17818 Element-wise maximum of two arrays, ignoring any NaNs. 17819 amax : 17820 The maximum value of an array along a given axis, propagating any NaNs. 17821 nanmax : 17822 The maximum value of an array along a given axis, ignoring any NaNs. 17823 17824 fmin, amin, nanmin 17825 17826 Notes 17827 ----- 17828 The maximum is equivalent to ``np.where(x1 >= x2, x1, x2)`` when neither 17829 x1 nor x2 are nans, but it is faster and does proper broadcasting. 17830 17831 Examples 17832 -------- 17833 >>> np.maximum([2, 3, 4], [1, 5, 2]) 17834 array([2, 5, 4]) 17835 17836 >>> np.maximum(np.eye(2), [0.5, 2]) # broadcasting 17837 array([[ 1. , 2. ], 17838 [ 0.5, 2. ]]) 17839 17840 >>> np.maximum([np.nan, 0, np.nan], [0, np.nan, np.nan]) 17841 array([ NaN, NaN, NaN]) 17842 >>> np.maximum(np.Inf, 1) 17843 inf""" 17844 return ndarray() 17845 def maximum_sctype(t): 17846 """ 17847 Return the scalar type of highest precision of the same kind as the input. 17848 17849 Parameters 17850 ---------- 17851 t : dtype or dtype specifier 17852 The input data type. This can be a `dtype` object or an object that 17853 is convertible to a `dtype`. 17854 17855 Returns 17856 ------- 17857 out : dtype 17858 The highest precision data type of the same kind (`dtype.kind`) as `t`. 17859 17860 See Also 17861 -------- 17862 obj2sctype, mintypecode, sctype2char 17863 dtype 17864 17865 Examples 17866 -------- 17867 >>> np.maximum_sctype(np.int) 17868 <type 'numpy.int64'> 17869 >>> np.maximum_sctype(np.uint8) 17870 <type 'numpy.uint64'> 17871 >>> np.maximum_sctype(np.complex) 17872 <type 'numpy.complex192'> 17873 17874 >>> np.maximum_sctype(str) 17875 <type 'numpy.string_'> 17876 17877 >>> np.maximum_sctype('i2') 17878 <type 'numpy.int64'> 17879 >>> np.maximum_sctype('f4') 17880 <type 'numpy.float96'> 17881 17882 """ 17883 return dtype() 17884 def may_share_memory(ab): 17885 """Determine if two arrays can share memory 17886 17887 The memory-bounds of a and b are computed. If they overlap then 17888 this function returns True. Otherwise, it returns False. 17889 17890 A return of True does not necessarily mean that the two arrays 17891 share any element. It just means that they *might*. 17892 17893 Parameters 17894 ---------- 17895 a, b : ndarray 17896 17897 Returns 17898 ------- 17899 out : bool 17900 17901 Examples 17902 -------- 17903 >>> np.may_share_memory(np.array([1,2]), np.array([5,8,9])) 17904 False""" 17905 return bool() 17906 def mean(a=False, axis=None, dtype=None, out=None, keepdims=False): 17907 """ 17908 Compute the arithmetic mean along the specified axis. 17909 17910 Returns the average of the array elements. The average is taken over 17911 the flattened array by default, otherwise over the specified axis. 17912 `float64` intermediate and return values are used for integer inputs. 17913 17914 Parameters 17915 ---------- 17916 a : array_like 17917 Array containing numbers whose mean is desired. If `a` is not an 17918 array, a conversion is attempted. 17919 axis : int, optional 17920 Axis along which the means are computed. The default is to compute 17921 the mean of the flattened array. 17922 dtype : data-type, optional 17923 Type to use in computing the mean. For integer inputs, the default 17924 is `float64`; for floating point inputs, it is the same as the 17925 input dtype. 17926 out : ndarray, optional 17927 Alternate output array in which to place the result. The default 17928 is ``None``; if provided, it must have the same shape as the 17929 expected output, but the type will be cast if necessary. 17930 See `doc.ufuncs` for details. 17931 keepdims : bool, optional 17932 If this is set to True, the axes which are reduced are left 17933 in the result as dimensions with size one. With this option, 17934 the result will broadcast correctly against the original `arr`. 17935 17936 Returns 17937 ------- 17938 m : ndarray, see dtype parameter above 17939 If `out=None`, returns a new array containing the mean values, 17940 otherwise a reference to the output array is returned. 17941 17942 See Also 17943 -------- 17944 average : Weighted average 17945 std, var, nanmean, nanstd, nanvar 17946 17947 Notes 17948 ----- 17949 The arithmetic mean is the sum of the elements along the axis divided 17950 by the number of elements. 17951 17952 Note that for floating-point input, the mean is computed using the 17953 same precision the input has. Depending on the input data, this can 17954 cause the results to be inaccurate, especially for `float32` (see 17955 example below). Specifying a higher-precision accumulator using the 17956 `dtype` keyword can alleviate this issue. 17957 17958 Examples 17959 -------- 17960 >>> a = np.array([[1, 2], [3, 4]]) 17961 >>> np.mean(a) 17962 2.5 17963 >>> np.mean(a, axis=0) 17964 array([ 2., 3.]) 17965 >>> np.mean(a, axis=1) 17966 array([ 1.5, 3.5]) 17967 17968 In single precision, `mean` can be inaccurate: 17969 17970 >>> a = np.zeros((2, 512*512), dtype=np.float32) 17971 >>> a[0, :] = 1.0 17972 >>> a[1, :] = 0.1 17973 >>> np.mean(a) 17974 0.546875 17975 17976 Computing the mean in float64 is more accurate: 17977 17978 >>> np.mean(a, dtype=np.float64) 17979 0.55000000074505806 17980 17981 """ 17982 return ndarray() 17983 def median(a=False, axis=None, out=None, overwrite_input=False): 17984 """ 17985 Compute the median along the specified axis. 17986 17987 Returns the median of the array elements. 17988 17989 Parameters 17990 ---------- 17991 a : array_like 17992 Input array or object that can be converted to an array. 17993 axis : int, optional 17994 Axis along which the medians are computed. The default (axis=None) 17995 is to compute the median along a flattened version of the array. 17996 out : ndarray, optional 17997 Alternative output array in which to place the result. It must 17998 have the same shape and buffer length as the expected output, 17999 but the type (of the output) will be cast if necessary. 18000 overwrite_input : bool, optional 18001 If True, then allow use of memory of input array (a) for 18002 calculations. The input array will be modified by the call to 18003 median. This will save memory when you do not need to preserve 18004 the contents of the input array. Treat the input as undefined, 18005 but it will probably be fully or partially sorted. Default is 18006 False. Note that, if `overwrite_input` is True and the input 18007 is not already an ndarray, an error will be raised. 18008 18009 Returns 18010 ------- 18011 median : ndarray 18012 A new array holding the result (unless `out` is specified, in 18013 which case that array is returned instead). If the input contains 18014 integers, or floats of smaller precision than 64, then the output 18015 data-type is float64. Otherwise, the output data-type is the same 18016 as that of the input. 18017 18018 See Also 18019 -------- 18020 mean, percentile 18021 18022 Notes 18023 ----- 18024 Given a vector V of length N, the median of V is the middle value of 18025 a sorted copy of V, ``V_sorted`` - i.e., ``V_sorted[(N-1)/2]``, when N is 18026 odd. When N is even, it is the average of the two middle values of 18027 ``V_sorted``. 18028 18029 Examples 18030 -------- 18031 >>> a = np.array([[10, 7, 4], [3, 2, 1]]) 18032 >>> a 18033 array([[10, 7, 4], 18034 [ 3, 2, 1]]) 18035 >>> np.median(a) 18036 3.5 18037 >>> np.median(a, axis=0) 18038 array([ 6.5, 4.5, 2.5]) 18039 >>> np.median(a, axis=1) 18040 array([ 7., 2.]) 18041 >>> m = np.median(a, axis=0) 18042 >>> out = np.zeros_like(m) 18043 >>> np.median(a, axis=0, out=m) 18044 array([ 6.5, 4.5, 2.5]) 18045 >>> m 18046 array([ 6.5, 4.5, 2.5]) 18047 >>> b = a.copy() 18048 >>> np.median(b, axis=1, overwrite_input=True) 18049 array([ 7., 2.]) 18050 >>> assert not np.all(a==b) 18051 >>> b = a.copy() 18052 >>> np.median(b, axis=None, overwrite_input=True) 18053 3.5 18054 >>> assert not np.all(a==b) 18055 18056 """ 18057 return ndarray() 18058 class memmap: 18059 T = getset_descriptor() 18060 __array_interface__ = getset_descriptor() 18061 __array_priority__ = float() 18062 __array_struct__ = getset_descriptor() 18063 __dict__ = dictproxy() 18064 __doc__ = str() 18065 __module__ = str() 18066 def all(self, axis=None, out=None): 18067 """a.all(axis=None, out=None) 18068 18069 Returns True if all elements evaluate to True. 18070 18071 Refer to `numpy.all` for full documentation. 18072 18073 See Also 18074 -------- 18075 numpy.all : equivalent function""" 18076 return None 18077 def any(self, axis=None, out=None): 18078 """a.any(axis=None, out=None) 18079 18080 Returns True if any of the elements of `a` evaluate to True. 18081 18082 Refer to `numpy.any` for full documentation. 18083 18084 See Also 18085 -------- 18086 numpy.any : equivalent function""" 18087 return None 18088 def argmax(self, axis=None, out=None): 18089 """a.argmax(axis=None, out=None) 18090 18091 Return indices of the maximum values along the given axis. 18092 18093 Refer to `numpy.argmax` for full documentation. 18094 18095 See Also 18096 -------- 18097 numpy.argmax : equivalent function""" 18098 return None 18099 def argmin(self, axis=None, out=None): 18100 """a.argmin(axis=None, out=None) 18101 18102 Return indices of the minimum values along the given axis of `a`. 18103 18104 Refer to `numpy.argmin` for detailed documentation. 18105 18106 See Also 18107 -------- 18108 numpy.argmin : equivalent function""" 18109 return None 18110 def argpartition(self, kth, axis=_1, kind=quickselect, order=None): 18111 """a.argpartition(kth, axis=-1, kind='quickselect', order=None) 18112 18113 Returns the indices that would partition this array. 18114 18115 Refer to `numpy.argpartition` for full documentation. 18116 18117 .. versionadded:: 1.8.0 18118 18119 See Also 18120 -------- 18121 numpy.argpartition : equivalent function""" 18122 return None 18123 def argsort(self, axis=_1, kind=quicksort, order=None): 18124 """a.argsort(axis=-1, kind='quicksort', order=None) 18125 18126 Returns the indices that would sort this array. 18127 18128 Refer to `numpy.argsort` for full documentation. 18129 18130 See Also 18131 -------- 18132 numpy.argsort : equivalent function""" 18133 return None 18134 def astype(self, dtype, order, casting, subok, copy): 18135 """a.astype(dtype, order='K', casting='unsafe', subok=True, copy=True) 18136 18137 Copy of the array, cast to a specified type. 18138 18139 Parameters 18140 ---------- 18141 dtype : str or dtype 18142 Typecode or data-type to which the array is cast. 18143 order : {'C', 'F', 'A', 'K'}, optional 18144 Controls the memory layout order of the result. 18145 'C' means C order, 'F' means Fortran order, 'A' 18146 means 'F' order if all the arrays are Fortran contiguous, 18147 'C' order otherwise, and 'K' means as close to the 18148 order the array elements appear in memory as possible. 18149 Default is 'K'. 18150 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional 18151 Controls what kind of data casting may occur. Defaults to 'unsafe' 18152 for backwards compatibility. 18153 18154 * 'no' means the data types should not be cast at all. 18155 * 'equiv' means only byte-order changes are allowed. 18156 * 'safe' means only casts which can preserve values are allowed. 18157 * 'same_kind' means only safe casts or casts within a kind, 18158 like float64 to float32, are allowed. 18159 * 'unsafe' means any data conversions may be done. 18160 subok : bool, optional 18161 If True, then sub-classes will be passed-through (default), otherwise 18162 the returned array will be forced to be a base-class array. 18163 copy : bool, optional 18164 By default, astype always returns a newly allocated array. If this 18165 is set to false, and the `dtype`, `order`, and `subok` 18166 requirements are satisfied, the input array is returned instead 18167 of a copy. 18168 18169 Returns 18170 ------- 18171 arr_t : ndarray 18172 Unless `copy` is False and the other conditions for returning the input 18173 array are satisfied (see description for `copy` input paramter), `arr_t` 18174 is a new array of the same shape as the input array, with dtype, order 18175 given by `dtype`, `order`. 18176 18177 Raises 18178 ------ 18179 ComplexWarning 18180 When casting from complex to float or int. To avoid this, 18181 one should use ``a.real.astype(t)``. 18182 18183 Examples 18184 -------- 18185 >>> x = np.array([1, 2, 2.5]) 18186 >>> x 18187 array([ 1. , 2. , 2.5]) 18188 18189 >>> x.astype(int) 18190 array([1, 2, 2])""" 18191 return ndarray() 18192 base = getset_descriptor() 18193 def byteswap(self, inplace): 18194 """a.byteswap(inplace) 18195 18196 Swap the bytes of the array elements 18197 18198 Toggle between low-endian and big-endian data representation by 18199 returning a byteswapped array, optionally swapped in-place. 18200 18201 Parameters 18202 ---------- 18203 inplace : bool, optional 18204 If ``True``, swap bytes in-place, default is ``False``. 18205 18206 Returns 18207 ------- 18208 out : ndarray 18209 The byteswapped array. If `inplace` is ``True``, this is 18210 a view to self. 18211 18212 Examples 18213 -------- 18214 >>> A = np.array([1, 256, 8755], dtype=np.int16) 18215 >>> map(hex, A) 18216 ['0x1', '0x100', '0x2233'] 18217 >>> A.byteswap(True) 18218 array([ 256, 1, 13090], dtype=int16) 18219 >>> map(hex, A) 18220 ['0x100', '0x1', '0x3322'] 18221 18222 Arrays of strings are not swapped 18223 18224 >>> A = np.array(['ceg', 'fac']) 18225 >>> A.byteswap() 18226 array(['ceg', 'fac'], 18227 dtype='|S3')""" 18228 return ndarray() 18229 def choose(self, choices, out=None, mode=_raise): 18230 """a.choose(choices, out=None, mode='raise') 18231 18232 Use an index array to construct a new array from a set of choices. 18233 18234 Refer to `numpy.choose` for full documentation. 18235 18236 See Also 18237 -------- 18238 numpy.choose : equivalent function""" 18239 return None 18240 def clip(self, a_min, a_max, out=None): 18241 """a.clip(a_min, a_max, out=None) 18242 18243 Return an array whose values are limited to ``[a_min, a_max]``. 18244 18245 Refer to `numpy.clip` for full documentation. 18246 18247 See Also 18248 -------- 18249 numpy.clip : equivalent function""" 18250 return None 18251 def compress(self, condition, axis=None, out=None): 18252 """a.compress(condition, axis=None, out=None) 18253 18254 Return selected slices of this array along given axis. 18255 18256 Refer to `numpy.compress` for full documentation. 18257 18258 See Also 18259 -------- 18260 numpy.compress : equivalent function""" 18261 return None 18262 def conj(self, _): 18263 """a.conj() 18264 18265 Complex-conjugate all elements. 18266 18267 Refer to `numpy.conjugate` for full documentation. 18268 18269 See Also 18270 -------- 18271 numpy.conjugate : equivalent function""" 18272 return None 18273 def conjugate(self, _): 18274 """a.conjugate() 18275 18276 Return the complex conjugate, element-wise. 18277 18278 Refer to `numpy.conjugate` for full documentation. 18279 18280 See Also 18281 -------- 18282 numpy.conjugate : equivalent function""" 18283 return None 18284 def copy(self, order): 18285 """a.copy(order='C') 18286 18287 Return a copy of the array. 18288 18289 Parameters 18290 ---------- 18291 order : {'C', 'F', 'A', 'K'}, optional 18292 Controls the memory layout of the copy. 'C' means C-order, 18293 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, 18294 'C' otherwise. 'K' means match the layout of `a` as closely 18295 as possible. (Note that this function and :func:numpy.copy are very 18296 similar, but have different default values for their order= 18297 arguments.) 18298 18299 See also 18300 -------- 18301 numpy.copy 18302 numpy.copyto 18303 18304 Examples 18305 -------- 18306 >>> x = np.array([[1,2,3],[4,5,6]], order='F') 18307 18308 >>> y = x.copy() 18309 18310 >>> x.fill(0) 18311 18312 >>> x 18313 array([[0, 0, 0], 18314 [0, 0, 0]]) 18315 18316 >>> y 18317 array([[1, 2, 3], 18318 [4, 5, 6]]) 18319 18320 >>> y.flags['C_CONTIGUOUS'] 18321 True""" 18322 return None 18323 ctypes = getset_descriptor() 18324 def cumprod(self, axis=None, dtype=None, out=None): 18325 """a.cumprod(axis=None, dtype=None, out=None) 18326 18327 Return the cumulative product of the elements along the given axis. 18328 18329 Refer to `numpy.cumprod` for full documentation. 18330 18331 See Also 18332 -------- 18333 numpy.cumprod : equivalent function""" 18334 return None 18335 def cumsum(self, axis=None, dtype=None, out=None): 18336 """a.cumsum(axis=None, dtype=None, out=None) 18337 18338 Return the cumulative sum of the elements along the given axis. 18339 18340 Refer to `numpy.cumsum` for full documentation. 18341 18342 See Also 18343 -------- 18344 numpy.cumsum : equivalent function""" 18345 return None 18346 data = getset_descriptor() 18347 def diagonal(self, offset=0, axis1=0, axis2=1): 18348 """a.diagonal(offset=0, axis1=0, axis2=1) 18349 18350 Return specified diagonals. 18351 18352 Refer to :func:`numpy.diagonal` for full documentation. 18353 18354 See Also 18355 -------- 18356 numpy.diagonal : equivalent function""" 18357 return None 18358 def dot(self, b, out=None): 18359 """a.dot(b, out=None) 18360 18361 Dot product of two arrays. 18362 18363 Refer to `numpy.dot` for full documentation. 18364 18365 See Also 18366 -------- 18367 numpy.dot : equivalent function 18368 18369 Examples 18370 -------- 18371 >>> a = np.eye(2) 18372 >>> b = np.ones((2, 2)) * 2 18373 >>> a.dot(b) 18374 array([[ 2., 2.], 18375 [ 2., 2.]]) 18376 18377 This array method can be conveniently chained: 18378 18379 >>> a.dot(b).dot(b) 18380 array([[ 8., 8.], 18381 [ 8., 8.]])""" 18382 return None 18383 dtype = getset_descriptor() 18384 def dump(self, file): 18385 """a.dump(file) 18386 18387 Dump a pickle of the array to the specified file. 18388 The array can be read back with pickle.load or numpy.load. 18389 18390 Parameters 18391 ---------- 18392 file : str 18393 A string naming the dump file.""" 18394 return None 18395 def dumps(self, _): 18396 """a.dumps() 18397 18398 Returns the pickle of the array as a string. 18399 pickle.loads or numpy.loads will convert the string back to an array. 18400 18401 Parameters 18402 ---------- 18403 None""" 18404 return None 18405 def fill(self, value): 18406 """a.fill(value) 18407 18408 Fill the array with a scalar value. 18409 18410 Parameters 18411 ---------- 18412 value : scalar 18413 All elements of `a` will be assigned this value. 18414 18415 Examples 18416 -------- 18417 >>> a = np.array([1, 2]) 18418 >>> a.fill(0) 18419 >>> a 18420 array([0, 0]) 18421 >>> a = np.empty(2) 18422 >>> a.fill(1) 18423 >>> a 18424 array([ 1., 1.])""" 18425 return None 18426 flags = getset_descriptor() 18427 flat = getset_descriptor() 18428 def flatten(self, order): 18429 """a.flatten(order='C') 18430 18431 Return a copy of the array collapsed into one dimension. 18432 18433 Parameters 18434 ---------- 18435 order : {'C', 'F', 'A'}, optional 18436 Whether to flatten in C (row-major), Fortran (column-major) order, 18437 or preserve the C/Fortran ordering from `a`. 18438 The default is 'C'. 18439 18440 Returns 18441 ------- 18442 y : ndarray 18443 A copy of the input array, flattened to one dimension. 18444 18445 See Also 18446 -------- 18447 ravel : Return a flattened array. 18448 flat : A 1-D flat iterator over the array. 18449 18450 Examples 18451 -------- 18452 >>> a = np.array([[1,2], [3,4]]) 18453 >>> a.flatten() 18454 array([1, 2, 3, 4]) 18455 >>> a.flatten('F') 18456 array([1, 3, 2, 4])""" 18457 return ndarray() 18458 def flush(self, _): 18459 """ 18460 Write any changes in the array to the file on disk. 18461 18462 For further information, see `memmap`. 18463 18464 Parameters 18465 ---------- 18466 None 18467 18468 See Also 18469 -------- 18470 memmap 18471 18472 """ 18473 return None 18474 def getfield(self, dtype, offset): 18475 """a.getfield(dtype, offset=0) 18476 18477 Returns a field of the given array as a certain type. 18478 18479 A field is a view of the array data with a given data-type. The values in 18480 the view are determined by the given type and the offset into the current 18481 array in bytes. The offset needs to be such that the view dtype fits in the 18482 array dtype; for example an array of dtype complex128 has 16-byte elements. 18483 If taking a view with a 32-bit integer (4 bytes), the offset needs to be 18484 between 0 and 12 bytes. 18485 18486 Parameters 18487 ---------- 18488 dtype : str or dtype 18489 The data type of the view. The dtype size of the view can not be larger 18490 than that of the array itself. 18491 offset : int 18492 Number of bytes to skip before beginning the element view. 18493 18494 Examples 18495 -------- 18496 >>> x = np.diag([1.+1.j]*2) 18497 >>> x[1, 1] = 2 + 4.j 18498 >>> x 18499 array([[ 1.+1.j, 0.+0.j], 18500 [ 0.+0.j, 2.+4.j]]) 18501 >>> x.getfield(np.float64) 18502 array([[ 1., 0.], 18503 [ 0., 2.]]) 18504 18505 By choosing an offset of 8 bytes we can select the complex part of the 18506 array for our view: 18507 18508 >>> x.getfield(np.float64, offset=8) 18509 array([[ 1., 0.], 18510 [ 0., 4.]])""" 18511 return array() 18512 imag = getset_descriptor() 18513 def item(self, ESCargs): 18514 """a.item(*args) 18515 18516 Copy an element of an array to a standard Python scalar and return it. 18517 18518 Parameters 18519 ---------- 18520 \*args : Arguments (variable number and type) 18521 18522 * none: in this case, the method only works for arrays 18523 with one element (`a.size == 1`), which element is 18524 copied into a standard Python scalar object and returned. 18525 18526 * int_type: this argument is interpreted as a flat index into 18527 the array, specifying which element to copy and return. 18528 18529 * tuple of int_types: functions as does a single int_type argument, 18530 except that the argument is interpreted as an nd-index into the 18531 array. 18532 18533 Returns 18534 ------- 18535 z : Standard Python scalar object 18536 A copy of the specified element of the array as a suitable 18537 Python scalar 18538 18539 Notes 18540 ----- 18541 When the data type of `a` is longdouble or clongdouble, item() returns 18542 a scalar array object because there is no available Python scalar that 18543 would not lose information. Void arrays return a buffer object for item(), 18544 unless fields are defined, in which case a tuple is returned. 18545 18546 `item` is very similar to a[args], except, instead of an array scalar, 18547 a standard Python scalar is returned. This can be useful for speeding up 18548 access to elements of the array and doing arithmetic on elements of the 18549 array using Python's optimized math. 18550 18551 Examples 18552 -------- 18553 >>> x = np.random.randint(9, size=(3, 3)) 18554 >>> x 18555 array([[3, 1, 7], 18556 [2, 8, 3], 18557 [8, 5, 3]]) 18558 >>> x.item(3) 18559 2 18560 >>> x.item(7) 18561 5 18562 >>> x.item((0, 1)) 18563 1 18564 >>> x.item((2, 2)) 18565 3""" 18566 return Standard() 18567 def itemset(self, ESCargs): 18568 """a.itemset(*args) 18569 18570 Insert scalar into an array (scalar is cast to array's dtype, if possible) 18571 18572 There must be at least 1 argument, and define the last argument 18573 as *item*. Then, ``a.itemset(*args)`` is equivalent to but faster 18574 than ``a[args] = item``. The item should be a scalar value and `args` 18575 must select a single item in the array `a`. 18576 18577 Parameters 18578 ---------- 18579 \*args : Arguments 18580 If one argument: a scalar, only used in case `a` is of size 1. 18581 If two arguments: the last argument is the value to be set 18582 and must be a scalar, the first argument specifies a single array 18583 element location. It is either an int or a tuple. 18584 18585 Notes 18586 ----- 18587 Compared to indexing syntax, `itemset` provides some speed increase 18588 for placing a scalar into a particular location in an `ndarray`, 18589 if you must do this. However, generally this is discouraged: 18590 among other problems, it complicates the appearance of the code. 18591 Also, when using `itemset` (and `item`) inside a loop, be sure 18592 to assign the methods to a local variable to avoid the attribute 18593 look-up at each loop iteration. 18594 18595 Examples 18596 -------- 18597 >>> x = np.random.randint(9, size=(3, 3)) 18598 >>> x 18599 array([[3, 1, 7], 18600 [2, 8, 3], 18601 [8, 5, 3]]) 18602 >>> x.itemset(4, 0) 18603 >>> x.itemset((2, 2), 9) 18604 >>> x 18605 array([[3, 1, 7], 18606 [2, 0, 3], 18607 [8, 5, 9]])""" 18608 return None 18609 itemsize = getset_descriptor() 18610 def max(self, axis=None, out=None): 18611 """a.max(axis=None, out=None) 18612 18613 Return the maximum along a given axis. 18614 18615 Refer to `numpy.amax` for full documentation. 18616 18617 See Also 18618 -------- 18619 numpy.amax : equivalent function""" 18620 return None 18621 def mean(self, axis=None, dtype=None, out=None): 18622 """a.mean(axis=None, dtype=None, out=None) 18623 18624 Returns the average of the array elements along given axis. 18625 18626 Refer to `numpy.mean` for full documentation. 18627 18628 See Also 18629 -------- 18630 numpy.mean : equivalent function""" 18631 return None 18632 def min(self, axis=None, out=None): 18633 """a.min(axis=None, out=None) 18634 18635 Return the minimum along a given axis. 18636 18637 Refer to `numpy.amin` for full documentation. 18638 18639 See Also 18640 -------- 18641 numpy.amin : equivalent function""" 18642 return None 18643 nbytes = getset_descriptor() 18644 ndim = getset_descriptor() 18645 def newbyteorder(self, new_order): 18646 """arr.newbyteorder(new_order='S') 18647 18648 Return the array with the same data viewed with a different byte order. 18649 18650 Equivalent to:: 18651 18652 arr.view(arr.dtype.newbytorder(new_order)) 18653 18654 Changes are also made in all fields and sub-arrays of the array data 18655 type. 18656 18657 18658 18659 Parameters 18660 ---------- 18661 new_order : string, optional 18662 Byte order to force; a value from the byte order specifications 18663 above. `new_order` codes can be any of:: 18664 18665 * 'S' - swap dtype from current to opposite endian 18666 * {'<', 'L'} - little endian 18667 * {'>', 'B'} - big endian 18668 * {'=', 'N'} - native order 18669 * {'|', 'I'} - ignore (no change to byte order) 18670 18671 The default value ('S') results in swapping the current 18672 byte order. The code does a case-insensitive check on the first 18673 letter of `new_order` for the alternatives above. For example, 18674 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 18675 18676 18677 Returns 18678 ------- 18679 new_arr : array 18680 New array object with the dtype reflecting given change to the 18681 byte order.""" 18682 return array() 18683 def nonzero(self, _): 18684 """a.nonzero() 18685 18686 Return the indices of the elements that are non-zero. 18687 18688 Refer to `numpy.nonzero` for full documentation. 18689 18690 See Also 18691 -------- 18692 numpy.nonzero : equivalent function""" 18693 return None 18694 def partition(self, kth, axis, kind, order): 18695 """a.partition(kth, axis=-1, kind='introselect', order=None) 18696 18697 Rearranges the elements in the array in such a way that value of the 18698 element in kth position is in the position it would be in a sorted array. 18699 All elements smaller than the kth element are moved before this element and 18700 all equal or greater are moved behind it. The ordering of the elements in 18701 the two partitions is undefined. 18702 18703 .. versionadded:: 1.8.0 18704 18705 Parameters 18706 ---------- 18707 kth : int or sequence of ints 18708 Element index to partition by. The kth element value will be in its 18709 final sorted position and all smaller elements will be moved before it 18710 and all equal or greater elements behind it. 18711 The order all elements in the partitions is undefined. 18712 If provided with a sequence of kth it will partition all elements 18713 indexed by kth of them into their sorted position at once. 18714 axis : int, optional 18715 Axis along which to sort. Default is -1, which means sort along the 18716 last axis. 18717 kind : {'introselect'}, optional 18718 Selection algorithm. Default is 'introselect'. 18719 order : list, optional 18720 When `a` is an array with fields defined, this argument specifies 18721 which fields to compare first, second, etc. Not all fields need be 18722 specified. 18723 18724 See Also 18725 -------- 18726 numpy.partition : Return a parititioned copy of an array. 18727 argpartition : Indirect partition. 18728 sort : Full sort. 18729 18730 Notes 18731 ----- 18732 See ``np.partition`` for notes on the different algorithms. 18733 18734 Examples 18735 -------- 18736 >>> a = np.array([3, 4, 2, 1]) 18737 >>> a.partition(a, 3) 18738 >>> a 18739 array([2, 1, 3, 4]) 18740 18741 >>> a.partition((1, 3)) 18742 array([1, 2, 3, 4])""" 18743 return None 18744 def prod(self, axis=None, dtype=None, out=None): 18745 """a.prod(axis=None, dtype=None, out=None) 18746 18747 Return the product of the array elements over the given axis 18748 18749 Refer to `numpy.prod` for full documentation. 18750 18751 See Also 18752 -------- 18753 numpy.prod : equivalent function""" 18754 return None 18755 def ptp(self, axis=None, out=None): 18756 """a.ptp(axis=None, out=None) 18757 18758 Peak to peak (maximum - minimum) value along a given axis. 18759 18760 Refer to `numpy.ptp` for full documentation. 18761 18762 See Also 18763 -------- 18764 numpy.ptp : equivalent function""" 18765 return None 18766 def put(self, indices, values, mode=_raise): 18767 """a.put(indices, values, mode='raise') 18768 18769 Set ``a.flat[n] = values[n]`` for all `n` in indices. 18770 18771 Refer to `numpy.put` for full documentation. 18772 18773 See Also 18774 -------- 18775 numpy.put : equivalent function""" 18776 return None 18777 def ravel(self, order): 18778 """a.ravel([order]) 18779 18780 Return a flattened array. 18781 18782 Refer to `numpy.ravel` for full documentation. 18783 18784 See Also 18785 -------- 18786 numpy.ravel : equivalent function 18787 18788 ndarray.flat : a flat iterator on the array.""" 18789 return None 18790 real = getset_descriptor() 18791 def repeat(self, repeats, axis=None): 18792 """a.repeat(repeats, axis=None) 18793 18794 Repeat elements of an array. 18795 18796 Refer to `numpy.repeat` for full documentation. 18797 18798 See Also 18799 -------- 18800 numpy.repeat : equivalent function""" 18801 return None 18802 def reshape(self, shape, order=C): 18803 """a.reshape(shape, order='C') 18804 18805 Returns an array containing the same data with a new shape. 18806 18807 Refer to `numpy.reshape` for full documentation. 18808 18809 See Also 18810 -------- 18811 numpy.reshape : equivalent function""" 18812 return None 18813 def resize(self, new_shape, refcheck): 18814 """a.resize(new_shape, refcheck=True) 18815 18816 Change shape and size of array in-place. 18817 18818 Parameters 18819 ---------- 18820 new_shape : tuple of ints, or `n` ints 18821 Shape of resized array. 18822 refcheck : bool, optional 18823 If False, reference count will not be checked. Default is True. 18824 18825 Returns 18826 ------- 18827 None 18828 18829 Raises 18830 ------ 18831 ValueError 18832 If `a` does not own its own data or references or views to it exist, 18833 and the data memory must be changed. 18834 18835 SystemError 18836 If the `order` keyword argument is specified. This behaviour is a 18837 bug in NumPy. 18838 18839 See Also 18840 -------- 18841 resize : Return a new array with the specified shape. 18842 18843 Notes 18844 ----- 18845 This reallocates space for the data area if necessary. 18846 18847 Only contiguous arrays (data elements consecutive in memory) can be 18848 resized. 18849 18850 The purpose of the reference count check is to make sure you 18851 do not use this array as a buffer for another Python object and then 18852 reallocate the memory. However, reference counts can increase in 18853 other ways so if you are sure that you have not shared the memory 18854 for this array with another Python object, then you may safely set 18855 `refcheck` to False. 18856 18857 Examples 18858 -------- 18859 Shrinking an array: array is flattened (in the order that the data are 18860 stored in memory), resized, and reshaped: 18861 18862 >>> a = np.array([[0, 1], [2, 3]], order='C') 18863 >>> a.resize((2, 1)) 18864 >>> a 18865 array([[0], 18866 [1]]) 18867 18868 >>> a = np.array([[0, 1], [2, 3]], order='F') 18869 >>> a.resize((2, 1)) 18870 >>> a 18871 array([[0], 18872 [2]]) 18873 18874 Enlarging an array: as above, but missing entries are filled with zeros: 18875 18876 >>> b = np.array([[0, 1], [2, 3]]) 18877 >>> b.resize(2, 3) # new_shape parameter doesn't have to be a tuple 18878 >>> b 18879 array([[0, 1, 2], 18880 [3, 0, 0]]) 18881 18882 Referencing an array prevents resizing... 18883 18884 >>> c = a 18885 >>> a.resize((1, 1)) 18886 Traceback (most recent call last): 18887 ... 18888 ValueError: cannot resize an array that has been referenced ... 18889 18890 Unless `refcheck` is False: 18891 18892 >>> a.resize((1, 1), refcheck=False) 18893 >>> a 18894 array([[0]]) 18895 >>> c 18896 array([[0]])""" 18897 return None 18898 def round(self, decimals=0, out=None): 18899 """a.round(decimals=0, out=None) 18900 18901 Return `a` with each element rounded to the given number of decimals. 18902 18903 Refer to `numpy.around` for full documentation. 18904 18905 See Also 18906 -------- 18907 numpy.around : equivalent function""" 18908 return None 18909 def searchsorted(self, v, side=left, sorter=None): 18910 """a.searchsorted(v, side='left', sorter=None) 18911 18912 Find indices where elements of v should be inserted in a to maintain order. 18913 18914 For full documentation, see `numpy.searchsorted` 18915 18916 See Also 18917 -------- 18918 numpy.searchsorted : equivalent function""" 18919 return None 18920 def setfield(self, val, dtype, offset): 18921 """a.setfield(val, dtype, offset=0) 18922 18923 Put a value into a specified place in a field defined by a data-type. 18924 18925 Place `val` into `a`'s field defined by `dtype` and beginning `offset` 18926 bytes into the field. 18927 18928 Parameters 18929 ---------- 18930 val : object 18931 Value to be placed in field. 18932 dtype : dtype object 18933 Data-type of the field in which to place `val`. 18934 offset : int, optional 18935 The number of bytes into the field at which to place `val`. 18936 18937 Returns 18938 ------- 18939 None 18940 18941 See Also 18942 -------- 18943 getfield 18944 18945 Examples 18946 -------- 18947 >>> x = np.eye(3) 18948 >>> x.getfield(np.float64) 18949 array([[ 1., 0., 0.], 18950 [ 0., 1., 0.], 18951 [ 0., 0., 1.]]) 18952 >>> x.setfield(3, np.int32) 18953 >>> x.getfield(np.int32) 18954 array([[3, 3, 3], 18955 [3, 3, 3], 18956 [3, 3, 3]]) 18957 >>> x 18958 array([[ 1.00000000e+000, 1.48219694e-323, 1.48219694e-323], 18959 [ 1.48219694e-323, 1.00000000e+000, 1.48219694e-323], 18960 [ 1.48219694e-323, 1.48219694e-323, 1.00000000e+000]]) 18961 >>> x.setfield(np.eye(3), np.int32) 18962 >>> x 18963 array([[ 1., 0., 0.], 18964 [ 0., 1., 0.], 18965 [ 0., 0., 1.]])""" 18966 return None 18967 def setflags(self, write, align, uic): 18968 """a.setflags(write=None, align=None, uic=None) 18969 18970 Set array flags WRITEABLE, ALIGNED, and UPDATEIFCOPY, respectively. 18971 18972 These Boolean-valued flags affect how numpy interprets the memory 18973 area used by `a` (see Notes below). The ALIGNED flag can only 18974 be set to True if the data is actually aligned according to the type. 18975 The UPDATEIFCOPY flag can never be set to True. The flag WRITEABLE 18976 can only be set to True if the array owns its own memory, or the 18977 ultimate owner of the memory exposes a writeable buffer interface, 18978 or is a string. (The exception for string is made so that unpickling 18979 can be done without copying memory.) 18980 18981 Parameters 18982 ---------- 18983 write : bool, optional 18984 Describes whether or not `a` can be written to. 18985 align : bool, optional 18986 Describes whether or not `a` is aligned properly for its type. 18987 uic : bool, optional 18988 Describes whether or not `a` is a copy of another "base" array. 18989 18990 Notes 18991 ----- 18992 Array flags provide information about how the memory area used 18993 for the array is to be interpreted. There are 6 Boolean flags 18994 in use, only three of which can be changed by the user: 18995 UPDATEIFCOPY, WRITEABLE, and ALIGNED. 18996 18997 WRITEABLE (W) the data area can be written to; 18998 18999 ALIGNED (A) the data and strides are aligned appropriately for the hardware 19000 (as determined by the compiler); 19001 19002 UPDATEIFCOPY (U) this array is a copy of some other array (referenced 19003 by .base). When this array is deallocated, the base array will be 19004 updated with the contents of this array. 19005 19006 All flags can be accessed using their first (upper case) letter as well 19007 as the full name. 19008 19009 Examples 19010 -------- 19011 >>> y 19012 array([[3, 1, 7], 19013 [2, 0, 0], 19014 [8, 5, 9]]) 19015 >>> y.flags 19016 C_CONTIGUOUS : True 19017 F_CONTIGUOUS : False 19018 OWNDATA : True 19019 WRITEABLE : True 19020 ALIGNED : True 19021 UPDATEIFCOPY : False 19022 >>> y.setflags(write=0, align=0) 19023 >>> y.flags 19024 C_CONTIGUOUS : True 19025 F_CONTIGUOUS : False 19026 OWNDATA : True 19027 WRITEABLE : False 19028 ALIGNED : False 19029 UPDATEIFCOPY : False 19030 >>> y.setflags(uic=1) 19031 Traceback (most recent call last): 19032 File "<stdin>", line 1, in <module> 19033 ValueError: cannot set UPDATEIFCOPY flag to True""" 19034 return None 19035 shape = getset_descriptor() 19036 size = getset_descriptor() 19037 def sort(self, axis, kind, order): 19038 """a.sort(axis=-1, kind='quicksort', order=None) 19039 19040 Sort an array, in-place. 19041 19042 Parameters 19043 ---------- 19044 axis : int, optional 19045 Axis along which to sort. Default is -1, which means sort along the 19046 last axis. 19047 kind : {'quicksort', 'mergesort', 'heapsort'}, optional 19048 Sorting algorithm. Default is 'quicksort'. 19049 order : list, optional 19050 When `a` is an array with fields defined, this argument specifies 19051 which fields to compare first, second, etc. Not all fields need be 19052 specified. 19053 19054 See Also 19055 -------- 19056 numpy.sort : Return a sorted copy of an array. 19057 argsort : Indirect sort. 19058 lexsort : Indirect stable sort on multiple keys. 19059 searchsorted : Find elements in sorted array. 19060 partition: Partial sort. 19061 19062 Notes 19063 ----- 19064 See ``sort`` for notes on the different sorting algorithms. 19065 19066 Examples 19067 -------- 19068 >>> a = np.array([[1,4], [3,1]]) 19069 >>> a.sort(axis=1) 19070 >>> a 19071 array([[1, 4], 19072 [1, 3]]) 19073 >>> a.sort(axis=0) 19074 >>> a 19075 array([[1, 3], 19076 [1, 4]]) 19077 19078 Use the `order` keyword to specify a field to use when sorting a 19079 structured array: 19080 19081 >>> a = np.array([('a', 2), ('c', 1)], dtype=[('x', 'S1'), ('y', int)]) 19082 >>> a.sort(order='y') 19083 >>> a 19084 array([('c', 1), ('a', 2)], 19085 dtype=[('x', '|S1'), ('y', '<i4')])""" 19086 return None 19087 def squeeze(self, axis=None): 19088 """a.squeeze(axis=None) 19089 19090 Remove single-dimensional entries from the shape of `a`. 19091 19092 Refer to `numpy.squeeze` for full documentation. 19093 19094 See Also 19095 -------- 19096 numpy.squeeze : equivalent function""" 19097 return None 19098 def std(self, axis=None, dtype=None, out=None, ddof=0): 19099 """a.std(axis=None, dtype=None, out=None, ddof=0) 19100 19101 Returns the standard deviation of the array elements along given axis. 19102 19103 Refer to `numpy.std` for full documentation. 19104 19105 See Also 19106 -------- 19107 numpy.std : equivalent function""" 19108 return None 19109 strides = getset_descriptor() 19110 def sum(self, axis=None, dtype=None, out=None): 19111 """a.sum(axis=None, dtype=None, out=None) 19112 19113 Return the sum of the array elements over the given axis. 19114 19115 Refer to `numpy.sum` for full documentation. 19116 19117 See Also 19118 -------- 19119 numpy.sum : equivalent function""" 19120 return None 19121 def swapaxes(self, axis1, axis2): 19122 """a.swapaxes(axis1, axis2) 19123 19124 Return a view of the array with `axis1` and `axis2` interchanged. 19125 19126 Refer to `numpy.swapaxes` for full documentation. 19127 19128 See Also 19129 -------- 19130 numpy.swapaxes : equivalent function""" 19131 return None 19132 def take(self, indices, axis=None, out=None, mode=_raise): 19133 """a.take(indices, axis=None, out=None, mode='raise') 19134 19135 Return an array formed from the elements of `a` at the given indices. 19136 19137 Refer to `numpy.take` for full documentation. 19138 19139 See Also 19140 -------- 19141 numpy.take : equivalent function""" 19142 return None 19143 def tofile(self, fid, sep, format): 19144 """a.tofile(fid, sep="", format="%s") 19145 19146 Write array to a file as text or binary (default). 19147 19148 Data is always written in 'C' order, independent of the order of `a`. 19149 The data produced by this method can be recovered using the function 19150 fromfile(). 19151 19152 Parameters 19153 ---------- 19154 fid : file or str 19155 An open file object, or a string containing a filename. 19156 sep : str 19157 Separator between array items for text output. 19158 If "" (empty), a binary file is written, equivalent to 19159 ``file.write(a.tostring())``. 19160 format : str 19161 Format string for text file output. 19162 Each entry in the array is formatted to text by first converting 19163 it to the closest Python type, and then using "format" % item. 19164 19165 Notes 19166 ----- 19167 This is a convenience function for quick storage of array data. 19168 Information on endianness and precision is lost, so this method is not a 19169 good choice for files intended to archive data or transport data between 19170 machines with different endianness. Some of these problems can be overcome 19171 by outputting the data as text files, at the expense of speed and file 19172 size.""" 19173 return None 19174 def tolist(self, _): 19175 """a.tolist() 19176 19177 Return the array as a (possibly nested) list. 19178 19179 Return a copy of the array data as a (nested) Python list. 19180 Data items are converted to the nearest compatible Python type. 19181 19182 Parameters 19183 ---------- 19184 none 19185 19186 Returns 19187 ------- 19188 y : list 19189 The possibly nested list of array elements. 19190 19191 Notes 19192 ----- 19193 The array may be recreated, ``a = np.array(a.tolist())``. 19194 19195 Examples 19196 -------- 19197 >>> a = np.array([1, 2]) 19198 >>> a.tolist() 19199 [1, 2] 19200 >>> a = np.array([[1, 2], [3, 4]]) 19201 >>> list(a) 19202 [array([1, 2]), array([3, 4])] 19203 >>> a.tolist() 19204 [[1, 2], [3, 4]]""" 19205 return list() 19206 def tostring(self, order): 19207 """a.tostring(order='C') 19208 19209 Construct a Python string containing the raw data bytes in the array. 19210 19211 Constructs a Python string showing a copy of the raw contents of 19212 data memory. The string can be produced in either 'C' or 'Fortran', 19213 or 'Any' order (the default is 'C'-order). 'Any' order means C-order 19214 unless the F_CONTIGUOUS flag in the array is set, in which case it 19215 means 'Fortran' order. 19216 19217 Parameters 19218 ---------- 19219 order : {'C', 'F', None}, optional 19220 Order of the data for multidimensional arrays: 19221 C, Fortran, or the same as for the original array. 19222 19223 Returns 19224 ------- 19225 s : str 19226 A Python string exhibiting a copy of `a`'s raw data. 19227 19228 Examples 19229 -------- 19230 >>> x = np.array([[0, 1], [2, 3]]) 19231 >>> x.tostring() 19232 '\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00' 19233 >>> x.tostring('C') == x.tostring() 19234 True 19235 >>> x.tostring('F') 19236 '\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00'""" 19237 return str() 19238 def trace(self, offset=0, axis1=0, axis2=1, dtype=None, out=None): 19239 """a.trace(offset=0, axis1=0, axis2=1, dtype=None, out=None) 19240 19241 Return the sum along diagonals of the array. 19242 19243 Refer to `numpy.trace` for full documentation. 19244 19245 See Also 19246 -------- 19247 numpy.trace : equivalent function""" 19248 return None 19249 def transpose(self, axes): 19250 """a.transpose(*axes) 19251 19252 Returns a view of the array with axes transposed. 19253 19254 For a 1-D array, this has no effect. (To change between column and 19255 row vectors, first cast the 1-D array into a matrix object.) 19256 For a 2-D array, this is the usual matrix transpose. 19257 For an n-D array, if axes are given, their order indicates how the 19258 axes are permuted (see Examples). If axes are not provided and 19259 ``a.shape = (i[0], i[1], ... i[n-2], i[n-1])``, then 19260 ``a.transpose().shape = (i[n-1], i[n-2], ... i[1], i[0])``. 19261 19262 Parameters 19263 ---------- 19264 axes : None, tuple of ints, or `n` ints 19265 19266 * None or no argument: reverses the order of the axes. 19267 19268 * tuple of ints: `i` in the `j`-th place in the tuple means `a`'s 19269 `i`-th axis becomes `a.transpose()`'s `j`-th axis. 19270 19271 * `n` ints: same as an n-tuple of the same ints (this form is 19272 intended simply as a "convenience" alternative to the tuple form) 19273 19274 Returns 19275 ------- 19276 out : ndarray 19277 View of `a`, with axes suitably permuted. 19278 19279 See Also 19280 -------- 19281 ndarray.T : Array property returning the array transposed. 19282 19283 Examples 19284 -------- 19285 >>> a = np.array([[1, 2], [3, 4]]) 19286 >>> a 19287 array([[1, 2], 19288 [3, 4]]) 19289 >>> a.transpose() 19290 array([[1, 3], 19291 [2, 4]]) 19292 >>> a.transpose((1, 0)) 19293 array([[1, 3], 19294 [2, 4]]) 19295 >>> a.transpose(1, 0) 19296 array([[1, 3], 19297 [2, 4]])""" 19298 return ndarray() 19299 def var(self, axis=None, dtype=None, out=None, ddof=0): 19300 """a.var(axis=None, dtype=None, out=None, ddof=0) 19301 19302 Returns the variance of the array elements, along given axis. 19303 19304 Refer to `numpy.var` for full documentation. 19305 19306 See Also 19307 -------- 19308 numpy.var : equivalent function""" 19309 return None 19310 def view(self, dtype, type): 19311 """a.view(dtype=None, type=None) 19312 19313 New view of array with the same data. 19314 19315 Parameters 19316 ---------- 19317 dtype : data-type or ndarray sub-class, optional 19318 Data-type descriptor of the returned view, e.g., float32 or int16. The 19319 default, None, results in the view having the same data-type as `a`. 19320 This argument can also be specified as an ndarray sub-class, which 19321 then specifies the type of the returned object (this is equivalent to 19322 setting the ``type`` parameter). 19323 type : Python type, optional 19324 Type of the returned view, e.g., ndarray or matrix. Again, the 19325 default None results in type preservation. 19326 19327 Notes 19328 ----- 19329 ``a.view()`` is used two different ways: 19330 19331 ``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view 19332 of the array's memory with a different data-type. This can cause a 19333 reinterpretation of the bytes of memory. 19334 19335 ``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just 19336 returns an instance of `ndarray_subclass` that looks at the same array 19337 (same shape, dtype, etc.) This does not cause a reinterpretation of the 19338 memory. 19339 19340 For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of 19341 bytes per entry than the previous dtype (for example, converting a 19342 regular array to a structured array), then the behavior of the view 19343 cannot be predicted just from the superficial appearance of ``a`` (shown 19344 by ``print(a)``). It also depends on exactly how ``a`` is stored in 19345 memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus 19346 defined as a slice or transpose, etc., the view may give different 19347 results. 19348 19349 19350 Examples 19351 -------- 19352 >>> x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)]) 19353 19354 Viewing array data using a different type and dtype: 19355 19356 >>> y = x.view(dtype=np.int16, type=np.matrix) 19357 >>> y 19358 matrix([[513]], dtype=int16) 19359 >>> print type(y) 19360 <class 'numpy.matrixlib.defmatrix.matrix'> 19361 19362 Creating a view on a structured array so it can be used in calculations 19363 19364 >>> x = np.array([(1, 2),(3,4)], dtype=[('a', np.int8), ('b', np.int8)]) 19365 >>> xv = x.view(dtype=np.int8).reshape(-1,2) 19366 >>> xv 19367 array([[1, 2], 19368 [3, 4]], dtype=int8) 19369 >>> xv.mean(0) 19370 array([ 2., 3.]) 19371 19372 Making changes to the view changes the underlying array 19373 19374 >>> xv[0,1] = 20 19375 >>> print x 19376 [(1, 20) (3, 4)] 19377 19378 Using a view to convert an array to a record array: 19379 19380 >>> z = x.view(np.recarray) 19381 >>> z.a 19382 array([1], dtype=int8) 19383 19384 Views share data: 19385 19386 >>> x[0] = (9, 10) 19387 >>> z[0] 19388 (9, 10) 19389 19390 Views that change the dtype size (bytes per entry) should normally be 19391 avoided on arrays defined by slices, transposes, fortran-ordering, etc.: 19392 19393 >>> x = np.array([[1,2,3],[4,5,6]], dtype=np.int16) 19394 >>> y = x[:, 0:2] 19395 >>> y 19396 array([[1, 2], 19397 [4, 5]], dtype=int16) 19398 >>> y.view(dtype=[('width', np.int16), ('length', np.int16)]) 19399 Traceback (most recent call last): 19400 File "<stdin>", line 1, in <module> 19401 ValueError: new type not compatible with array. 19402 >>> z = y.copy() 19403 >>> z.view(dtype=[('width', np.int16), ('length', np.int16)]) 19404 array([[(1, 2)], 19405 [(4, 5)]], dtype=[('width', '<i2'), ('length', '<i2')])""" 19406 return None 19407 def meshgrid(): 19408 """ 19409 Return coordinate matrices from two or more coordinate vectors. 19410 19411 Make N-D coordinate arrays for vectorized evaluations of 19412 N-D scalar/vector fields over N-D grids, given 19413 one-dimensional coordinate arrays x1, x2,..., xn. 19414 19415 Parameters 19416 ---------- 19417 x1, x2,..., xn : array_like 19418 1-D arrays representing the coordinates of a grid. 19419 indexing : {'xy', 'ij'}, optional 19420 Cartesian ('xy', default) or matrix ('ij') indexing of output. 19421 See Notes for more details. 19422 sparse : bool, optional 19423 If True a sparse grid is returned in order to conserve memory. 19424 Default is False. 19425 copy : bool, optional 19426 If False, a view into the original arrays are returned in 19427 order to conserve memory. Default is True. Please note that 19428 ``sparse=False, copy=False`` will likely return non-contiguous arrays. 19429 Furthermore, more than one element of a broadcast array may refer to 19430 a single memory location. If you need to write to the arrays, make 19431 copies first. 19432 19433 Returns 19434 ------- 19435 X1, X2,..., XN : ndarray 19436 For vectors `x1`, `x2`,..., 'xn' with lengths ``Ni=len(xi)`` , 19437 return ``(N1, N2, N3,...Nn)`` shaped arrays if indexing='ij' 19438 or ``(N2, N1, N3,...Nn)`` shaped arrays if indexing='xy' 19439 with the elements of `xi` repeated to fill the matrix along 19440 the first dimension for `x1`, the second for `x2` and so on. 19441 19442 Notes 19443 ----- 19444 This function supports both indexing conventions through the indexing keyword 19445 argument. Giving the string 'ij' returns a meshgrid with matrix indexing, 19446 while 'xy' returns a meshgrid with Cartesian indexing. In the 2-D case 19447 with inputs of length M and N, the outputs are of shape (N, M) for 'xy' 19448 indexing and (M, N) for 'ij' indexing. In the 3-D case with inputs of 19449 length M, N and P, outputs are of shape (N, M, P) for 'xy' indexing and (M, 19450 N, P) for 'ij' indexing. The difference is illustrated by the following 19451 code snippet:: 19452 19453 xv, yv = meshgrid(x, y, sparse=False, indexing='ij') 19454 for i in range(nx): 19455 for j in range(ny): 19456 # treat xv[i,j], yv[i,j] 19457 19458 xv, yv = meshgrid(x, y, sparse=False, indexing='xy') 19459 for i in range(nx): 19460 for j in range(ny): 19461 # treat xv[j,i], yv[j,i] 19462 19463 See Also 19464 -------- 19465 index_tricks.mgrid : Construct a multi-dimensional "meshgrid" 19466 using indexing notation. 19467 index_tricks.ogrid : Construct an open multi-dimensional "meshgrid" 19468 using indexing notation. 19469 19470 Examples 19471 -------- 19472 >>> nx, ny = (3, 2) 19473 >>> x = np.linspace(0, 1, nx) 19474 >>> y = np.linspace(0, 1, ny) 19475 >>> xv, yv = meshgrid(x, y) 19476 >>> xv 19477 array([[ 0. , 0.5, 1. ], 19478 [ 0. , 0.5, 1. ]]) 19479 >>> yv 19480 array([[ 0., 0., 0.], 19481 [ 1., 1., 1.]]) 19482 >>> xv, yv = meshgrid(x, y, sparse=True) # make sparse output arrays 19483 >>> xv 19484 array([[ 0. , 0.5, 1. ]]) 19485 >>> yv 19486 array([[ 0.], 19487 [ 1.]]) 19488 19489 `meshgrid` is very useful to evaluate functions on a grid. 19490 19491 >>> x = np.arange(-5, 5, 0.1) 19492 >>> y = np.arange(-5, 5, 0.1) 19493 >>> xx, yy = meshgrid(x, y, sparse=True) 19494 >>> z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2) 19495 >>> h = plt.contourf(x,y,z) 19496 19497 """ 19498 return ndarray() 19499 mgrid = nd_grid() 19500 def amin(a=False, axis=None, out=None, keepdims=False): 19501 """ 19502 Return the minimum of an array or minimum along an axis. 19503 19504 Parameters 19505 ---------- 19506 a : array_like 19507 Input data. 19508 axis : int, optional 19509 Axis along which to operate. By default, flattened input is used. 19510 out : ndarray, optional 19511 Alternative output array in which to place the result. Must 19512 be of the same shape and buffer length as the expected output. 19513 See `doc.ufuncs` (Section "Output arguments") for more details. 19514 keepdims : bool, optional 19515 If this is set to True, the axes which are reduced are left 19516 in the result as dimensions with size one. With this option, 19517 the result will broadcast correctly against the original `arr`. 19518 19519 Returns 19520 ------- 19521 amin : ndarray or scalar 19522 Minimum of `a`. If `axis` is None, the result is a scalar value. 19523 If `axis` is given, the result is an array of dimension 19524 ``a.ndim - 1``. 19525 19526 See Also 19527 -------- 19528 amax : 19529 The maximum value of an array along a given axis, propagating any NaNs. 19530 nanmin : 19531 The minimum value of an array along a given axis, ignoring any NaNs. 19532 minimum : 19533 Element-wise minimum of two arrays, propagating any NaNs. 19534 fmin : 19535 Element-wise minimum of two arrays, ignoring any NaNs. 19536 argmin : 19537 Return the indices of the minimum values. 19538 19539 nanmax, maximum, fmax 19540 19541 Notes 19542 ----- 19543 NaN values are propagated, that is if at least one item is NaN, the 19544 corresponding min value will be NaN as well. To ignore NaN values 19545 (MATLAB behavior), please use nanmin. 19546 19547 Don't use `amin` for element-wise comparison of 2 arrays; when 19548 ``a.shape[0]`` is 2, ``minimum(a[0], a[1])`` is faster than 19549 ``amin(a, axis=0)``. 19550 19551 Examples 19552 -------- 19553 >>> a = np.arange(4).reshape((2,2)) 19554 >>> a 19555 array([[0, 1], 19556 [2, 3]]) 19557 >>> np.amin(a) # Minimum of the flattened array 19558 0 19559 >>> np.amin(a, axis=0) # Minima along the first axis 19560 array([0, 1]) 19561 >>> np.amin(a, axis=1) # Minima along the second axis 19562 array([0, 2]) 19563 19564 >>> b = np.arange(5, dtype=np.float) 19565 >>> b[2] = np.NaN 19566 >>> np.amin(b) 19567 nan 19568 >>> np.nanmin(b) 19569 0.0 19570 19571 """ 19572 return ndarray() if False else float() 19573 def min_scalar_type(a): 19574 """min_scalar_type(a) 19575 19576 For scalar ``a``, returns the data type with the smallest size 19577 and smallest scalar kind which can hold its value. For non-scalar 19578 array ``a``, returns the vector's dtype unmodified. 19579 19580 Floating point values are not demoted to integers, 19581 and complex values are not demoted to floats. 19582 19583 Parameters 19584 ---------- 19585 a : scalar or array_like 19586 The value whose minimal data type is to be found. 19587 19588 Returns 19589 ------- 19590 out : dtype 19591 The minimal data type. 19592 19593 Notes 19594 ----- 19595 .. versionadded:: 1.6.0 19596 19597 See Also 19598 -------- 19599 result_type, promote_types, dtype, can_cast 19600 19601 Examples 19602 -------- 19603 >>> np.min_scalar_type(10) 19604 dtype('uint8') 19605 19606 >>> np.min_scalar_type(-260) 19607 dtype('int16') 19608 19609 >>> np.min_scalar_type(3.1) 19610 dtype('float16') 19611 19612 >>> np.min_scalar_type(1e50) 19613 dtype('float64') 19614 19615 >>> np.min_scalar_type(np.arange(4,dtype='f8')) 19616 dtype('float64')""" 19617 return dtype() 19618 def minimum(x1, x2, out=None): 19619 """minimum(x1, x2[, out]) 19620 19621 Element-wise minimum of array elements. 19622 19623 Compare two arrays and returns a new array containing the element-wise 19624 minima. If one of the elements being compared is a nan, then that element 19625 is returned. If both elements are nans then the first is returned. The 19626 latter distinction is important for complex nans, which are defined as at 19627 least one of the real or imaginary parts being a nan. The net effect is 19628 that nans are propagated. 19629 19630 Parameters 19631 ---------- 19632 x1, x2 : array_like 19633 The arrays holding the elements to be compared. They must have 19634 the same shape, or shapes that can be broadcast to a single shape. 19635 19636 Returns 19637 ------- 19638 y : {ndarray, scalar} 19639 The minimum of `x1` and `x2`, element-wise. Returns scalar if 19640 both `x1` and `x2` are scalars. 19641 19642 See Also 19643 -------- 19644 maximum : 19645 Element-wise maximum of two arrays, propagating any NaNs. 19646 fmin : 19647 Element-wise minimum of two arrays, ignoring any NaNs. 19648 amin : 19649 The minimum value of an array along a given axis, propagating any NaNs. 19650 nanmin : 19651 The minimum value of an array along a given axis, ignoring any NaNs. 19652 19653 fmax, amax, nanmax 19654 19655 Notes 19656 ----- 19657 The minimum is equivalent to ``np.where(x1 <= x2, x1, x2)`` when neither 19658 x1 nor x2 are nans, but it is faster and does proper broadcasting. 19659 19660 Examples 19661 -------- 19662 >>> np.minimum([2, 3, 4], [1, 5, 2]) 19663 array([1, 3, 2]) 19664 19665 >>> np.minimum(np.eye(2), [0.5, 2]) # broadcasting 19666 array([[ 0.5, 0. ], 19667 [ 0. , 1. ]]) 19668 19669 >>> np.minimum([np.nan, 0, np.nan],[0, np.nan, np.nan]) 19670 array([ NaN, NaN, NaN]) 19671 >>> np.minimum(-np.Inf, 1) 19672 -inf""" 19673 return ndarray() 19674 def mintypecode(typechars="d", typeset="GDFgdf", default="d"): 19675 """ 19676 Return the character for the minimum-size type to which given types can 19677 be safely cast. 19678 19679 The returned type character must represent the smallest size dtype such 19680 that an array of the returned type can handle the data from an array of 19681 all types in `typechars` (or if `typechars` is an array, then its 19682 dtype.char). 19683 19684 Parameters 19685 ---------- 19686 typechars : list of str or array_like 19687 If a list of strings, each string should represent a dtype. 19688 If array_like, the character representation of the array dtype is used. 19689 typeset : str or list of str, optional 19690 The set of characters that the returned character is chosen from. 19691 The default set is 'GDFgdf'. 19692 default : str, optional 19693 The default character, this is returned if none of the characters in 19694 `typechars` matches a character in `typeset`. 19695 19696 Returns 19697 ------- 19698 typechar : str 19699 The character representing the minimum-size type that was found. 19700 19701 See Also 19702 -------- 19703 dtype, sctype2char, maximum_sctype 19704 19705 Examples 19706 -------- 19707 >>> np.mintypecode(['d', 'f', 'S']) 19708 'd' 19709 >>> x = np.array([1.1, 2-3.j]) 19710 >>> np.mintypecode(x) 19711 'D' 19712 19713 >>> np.mintypecode('abceh', default='G') 19714 'G' 19715 19716 """ 19717 return str() 19718 def mirr(values, finance_rate, reinvest_rate): 19719 """ 19720 Modified internal rate of return. 19721 19722 Parameters 19723 ---------- 19724 values : array_like 19725 Cash flows (must contain at least one positive and one negative value) 19726 or nan is returned. The first value is considered a sunk cost at time zero. 19727 finance_rate : scalar 19728 Interest rate paid on the cash flows 19729 reinvest_rate : scalar 19730 Interest rate received on the cash flows upon reinvestment 19731 19732 Returns 19733 ------- 19734 out : float 19735 Modified internal rate of return 19736 19737 """ 19738 return float() 19739 def remainder(x1, x2, out): 19740 """remainder(x1, x2[, out]) 19741 19742 Return element-wise remainder of division. 19743 19744 Computes ``x1 - floor(x1 / x2) * x2``. 19745 19746 Parameters 19747 ---------- 19748 x1 : array_like 19749 Dividend array. 19750 x2 : array_like 19751 Divisor array. 19752 out : ndarray, optional 19753 Array into which the output is placed. Its type is preserved and it 19754 must be of the right shape to hold the output. See doc.ufuncs. 19755 19756 Returns 19757 ------- 19758 y : ndarray 19759 The remainder of the quotient ``x1/x2``, element-wise. Returns a scalar 19760 if both `x1` and `x2` are scalars. 19761 19762 See Also 19763 -------- 19764 divide, floor 19765 19766 Notes 19767 ----- 19768 Returns 0 when `x2` is 0 and both `x1` and `x2` are (arrays of) integers. 19769 19770 Examples 19771 -------- 19772 >>> np.remainder([4, 7], [2, 3]) 19773 array([0, 1]) 19774 >>> np.remainder(np.arange(7), 5) 19775 array([0, 1, 2, 3, 4, 0, 1])""" 19776 return ndarray() 19777 def modf(x, out1=None, out2=None): 19778 """modf(x[, out1, out2]) 19779 19780 Return the fractional and integral parts of an array, element-wise. 19781 19782 The fractional and integral parts are negative if the given number is 19783 negative. 19784 19785 Parameters 19786 ---------- 19787 x : array_like 19788 Input array. 19789 19790 Returns 19791 ------- 19792 y1 : ndarray 19793 Fractional part of `x`. 19794 y2 : ndarray 19795 Integral part of `x`. 19796 19797 Notes 19798 ----- 19799 For integer input the return values are floats. 19800 19801 Examples 19802 -------- 19803 >>> np.modf([0, 3.5]) 19804 (array([ 0. , 0.5]), array([ 0., 3.])) 19805 >>> np.modf(-0.5) 19806 (-0.5, -0)""" 19807 return ndarray() 19808 def msort(a): 19809 """ 19810 Return a copy of an array sorted along the first axis. 19811 19812 Parameters 19813 ---------- 19814 a : array_like 19815 Array to be sorted. 19816 19817 Returns 19818 ------- 19819 sorted_array : ndarray 19820 Array of the same type and shape as `a`. 19821 19822 See Also 19823 -------- 19824 sort 19825 19826 Notes 19827 ----- 19828 ``np.msort(a)`` is equivalent to ``np.sort(a, axis=0)``. 19829 19830 """ 19831 return ndarray() 19832 def multiply(x1, x2, out=None): 19833 """multiply(x1, x2[, out]) 19834 19835 Multiply arguments element-wise. 19836 19837 Parameters 19838 ---------- 19839 x1, x2 : array_like 19840 Input arrays to be multiplied. 19841 19842 Returns 19843 ------- 19844 y : ndarray 19845 The product of `x1` and `x2`, element-wise. Returns a scalar if 19846 both `x1` and `x2` are scalars. 19847 19848 Notes 19849 ----- 19850 Equivalent to `x1` * `x2` in terms of array broadcasting. 19851 19852 Examples 19853 -------- 19854 >>> np.multiply(2.0, 4.0) 19855 8.0 19856 19857 >>> x1 = np.arange(9.0).reshape((3, 3)) 19858 >>> x2 = np.arange(3.0) 19859 >>> np.multiply(x1, x2) 19860 array([[ 0., 1., 4.], 19861 [ 0., 4., 10.], 19862 [ 0., 7., 16.]])""" 19863 return ndarray() 19864 nan = float() 19865 def nan_to_num(x): 19866 """ 19867 Replace nan with zero and inf with finite numbers. 19868 19869 Returns an array or scalar replacing Not a Number (NaN) with zero, 19870 (positive) infinity with a very large number and negative infinity 19871 with a very small (or negative) number. 19872 19873 Parameters 19874 ---------- 19875 x : array_like 19876 Input data. 19877 19878 Returns 19879 ------- 19880 out : ndarray, float 19881 Array with the same shape as `x` and dtype of the element in `x` with 19882 the greatest precision. NaN is replaced by zero, and infinity 19883 (-infinity) is replaced by the largest (smallest or most negative) 19884 floating point value that fits in the output dtype. All finite numbers 19885 are upcast to the output dtype (default float64). 19886 19887 See Also 19888 -------- 19889 isinf : Shows which elements are negative or negative infinity. 19890 isneginf : Shows which elements are negative infinity. 19891 isposinf : Shows which elements are positive infinity. 19892 isnan : Shows which elements are Not a Number (NaN). 19893 isfinite : Shows which elements are finite (not NaN, not infinity) 19894 19895 Notes 19896 ----- 19897 Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic 19898 (IEEE 754). This means that Not a Number is not equivalent to infinity. 19899 19900 19901 Examples 19902 -------- 19903 >>> np.set_printoptions(precision=8) 19904 >>> x = np.array([np.inf, -np.inf, np.nan, -128, 128]) 19905 >>> np.nan_to_num(x) 19906 array([ 1.79769313e+308, -1.79769313e+308, 0.00000000e+000, 19907 -1.28000000e+002, 1.28000000e+002]) 19908 19909 """ 19910 return ndarray() 19911 def nanargmax(a=None, axis=None): 19912 """ 19913 Return the indices of the maximum values in the specified axis ignoring 19914 NaNs. For all-NaN slices ``ValueError`` is raised. Warning: the 19915 results cannot be trusted if a slice contains only NaNs and -Infs. 19916 19917 19918 Parameters 19919 ---------- 19920 a : array_like 19921 Input data. 19922 axis : int, optional 19923 Axis along which to operate. By default flattened input is used. 19924 19925 Returns 19926 ------- 19927 index_array : ndarray 19928 An array of indices or a single index value. 19929 19930 See Also 19931 -------- 19932 argmax, nanargmin 19933 19934 Examples 19935 -------- 19936 >>> a = np.array([[np.nan, 4], [2, 3]]) 19937 >>> np.argmax(a) 19938 0 19939 >>> np.nanargmax(a) 19940 1 19941 >>> np.nanargmax(a, axis=0) 19942 array([1, 0]) 19943 >>> np.nanargmax(a, axis=1) 19944 array([1, 1]) 19945 19946 """ 19947 return ndarray() 19948 def nanargmin(a=None, axis=None): 19949 """ 19950 Return the indices of the minimum values in the specified axis ignoring 19951 NaNs. For all-NaN slices ``ValueError`` is raised. Warning: the results 19952 cannot be trusted if a slice contains only NaNs and Infs. 19953 19954 Parameters 19955 ---------- 19956 a : array_like 19957 Input data. 19958 axis : int, optional 19959 Axis along which to operate. By default flattened input is used. 19960 19961 Returns 19962 ------- 19963 index_array : ndarray 19964 An array of indices or a single index value. 19965 19966 See Also 19967 -------- 19968 argmin, nanargmax 19969 19970 Examples 19971 -------- 19972 >>> a = np.array([[np.nan, 4], [2, 3]]) 19973 >>> np.argmin(a) 19974 0 19975 >>> np.nanargmin(a) 19976 2 19977 >>> np.nanargmin(a, axis=0) 19978 array([1, 1]) 19979 >>> np.nanargmin(a, axis=1) 19980 array([1, 0]) 19981 19982 """ 19983 return ndarray() 19984 def nanmax(a=False, axis=None, out=None, keepdims=False): 19985 """ 19986 Return the maximum of an array or maximum along an axis, ignoring any 19987 NaNs. When all-NaN slices are encountered a ``RuntimeWarning`` is 19988 raised and NaN is returned for that slice. 19989 19990 Parameters 19991 ---------- 19992 a : array_like 19993 Array containing numbers whose maximum is desired. If `a` is not an 19994 array, a conversion is attempted. 19995 axis : int, optional 19996 Axis along which the maximum is computed. The default is to compute 19997 the maximum of the flattened array. 19998 out : ndarray, optional 19999 Alternate output array in which to place the result. The default 20000 is ``None``; if provided, it must have the same shape as the 20001 expected output, but the type will be cast if necessary. See 20002 `doc.ufuncs` for details. 20003 20004 .. versionadded:: 1.8.0 20005 keepdims : bool, optional 20006 If this is set to True, the axes which are reduced are left in the 20007 result as dimensions with size one. With this option, the result 20008 will broadcast correctly against the original `a`. 20009 20010 .. versionadded:: 1.8.0 20011 20012 Returns 20013 ------- 20014 nanmax : ndarray 20015 An array with the same shape as `a`, with the specified axis removed. 20016 If `a` is a 0-d array, or if axis is None, an ndarray scalar is 20017 returned. The same dtype as `a` is returned. 20018 20019 See Also 20020 -------- 20021 nanmin : 20022 The minimum value of an array along a given axis, ignoring any NaNs. 20023 amax : 20024 The maximum value of an array along a given axis, propagating any NaNs. 20025 fmax : 20026 Element-wise maximum of two arrays, ignoring any NaNs. 20027 maximum : 20028 Element-wise maximum of two arrays, propagating any NaNs. 20029 isnan : 20030 Shows which elements are Not a Number (NaN). 20031 isfinite: 20032 Shows which elements are neither NaN nor infinity. 20033 20034 amin, fmin, minimum 20035 20036 Notes 20037 ----- 20038 Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic 20039 (IEEE 754). This means that Not a Number is not equivalent to infinity. 20040 Positive infinity is treated as a very large number and negative 20041 infinity is treated as a very small (i.e. negative) number. 20042 20043 If the input has a integer type the function is equivalent to np.max. 20044 20045 Examples 20046 -------- 20047 >>> a = np.array([[1, 2], [3, np.nan]]) 20048 >>> np.nanmax(a) 20049 3.0 20050 >>> np.nanmax(a, axis=0) 20051 array([ 3., 2.]) 20052 >>> np.nanmax(a, axis=1) 20053 array([ 2., 3.]) 20054 20055 When positive infinity and negative infinity are present: 20056 20057 >>> np.nanmax([1, 2, np.nan, np.NINF]) 20058 2.0 20059 >>> np.nanmax([1, 2, np.nan, np.inf]) 20060 inf 20061 20062 """ 20063 return ndarray() 20064 def nanmean(a=False, axis=None, dtype=None, out=None, keepdims=False): 20065 """ 20066 Compute the arithmetic mean along the specified axis, ignoring NaNs. 20067 20068 Returns the average of the array elements. The average is taken over 20069 the flattened array by default, otherwise over the specified axis. 20070 `float64` intermediate and return values are used for integer inputs. 20071 20072 For all-NaN slices, NaN is returned and a `RuntimeWarning` is raised. 20073 20074 .. versionadded:: 1.8.0 20075 20076 Parameters 20077 ---------- 20078 a : array_like 20079 Array containing numbers whose mean is desired. If `a` is not an 20080 array, a conversion is attempted. 20081 axis : int, optional 20082 Axis along which the means are computed. The default is to compute 20083 the mean of the flattened array. 20084 dtype : data-type, optional 20085 Type to use in computing the mean. For integer inputs, the default 20086 is `float64`; for inexact inputs, it is the same as the input 20087 dtype. 20088 out : ndarray, optional 20089 Alternate output array in which to place the result. The default 20090 is ``None``; if provided, it must have the same shape as the 20091 expected output, but the type will be cast if necessary. See 20092 `doc.ufuncs` for details. 20093 keepdims : bool, optional 20094 If this is set to True, the axes which are reduced are left in the 20095 result as dimensions with size one. With this option, the result 20096 will broadcast correctly against the original `arr`. 20097 20098 Returns 20099 ------- 20100 m : ndarray, see dtype parameter above 20101 If `out=None`, returns a new array containing the mean values, 20102 otherwise a reference to the output array is returned. Nan is 20103 returned for slices that contain only NaNs. 20104 20105 See Also 20106 -------- 20107 average : Weighted average 20108 mean : Arithmetic mean taken while not ignoring NaNs 20109 var, nanvar 20110 20111 Notes 20112 ----- 20113 The arithmetic mean is the sum of the non-NaN elements along the axis 20114 divided by the number of non-NaN elements. 20115 20116 Note that for floating-point input, the mean is computed using the same 20117 precision the input has. Depending on the input data, this can cause 20118 the results to be inaccurate, especially for `float32`. Specifying a 20119 higher-precision accumulator using the `dtype` keyword can alleviate 20120 this issue. 20121 20122 Examples 20123 -------- 20124 >>> a = np.array([[1, np.nan], [3, 4]]) 20125 >>> np.nanmean(a) 20126 2.6666666666666665 20127 >>> np.nanmean(a, axis=0) 20128 array([ 2., 4.]) 20129 >>> np.nanmean(a, axis=1) 20130 array([ 1., 3.5]) 20131 20132 """ 20133 return ndarray() 20134 def nanmin(a=False, axis=None, out=None, keepdims=False): 20135 """ 20136 Return minimum of an array or minimum along an axis, ignoring any NaNs. 20137 When all-NaN slices are encountered a ``RuntimeWarning`` is raised and 20138 Nan is returned for that slice. 20139 20140 Parameters 20141 ---------- 20142 a : array_like 20143 Array containing numbers whose minimum is desired. If `a` is not an 20144 array, a conversion is attempted. 20145 axis : int, optional 20146 Axis along which the minimum is computed. The default is to compute 20147 the minimum of the flattened array. 20148 out : ndarray, optional 20149 Alternate output array in which to place the result. The default 20150 is ``None``; if provided, it must have the same shape as the 20151 expected output, but the type will be cast if necessary. See 20152 `doc.ufuncs` for details. 20153 20154 .. versionadded:: 1.8.0 20155 keepdims : bool, optional 20156 If this is set to True, the axes which are reduced are left in the 20157 result as dimensions with size one. With this option, the result 20158 will broadcast correctly against the original `a`. 20159 20160 .. versionadded:: 1.8.0 20161 20162 Returns 20163 ------- 20164 nanmin : ndarray 20165 An array with the same shape as `a`, with the specified axis 20166 removed. If `a` is a 0-d array, or if axis is None, an ndarray 20167 scalar is returned. The same dtype as `a` is returned. 20168 20169 See Also 20170 -------- 20171 nanmax : 20172 The maximum value of an array along a given axis, ignoring any NaNs. 20173 amin : 20174 The minimum value of an array along a given axis, propagating any NaNs. 20175 fmin : 20176 Element-wise minimum of two arrays, ignoring any NaNs. 20177 minimum : 20178 Element-wise minimum of two arrays, propagating any NaNs. 20179 isnan : 20180 Shows which elements are Not a Number (NaN). 20181 isfinite: 20182 Shows which elements are neither NaN nor infinity. 20183 20184 amax, fmax, maximum 20185 20186 Notes 20187 ----- 20188 Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic 20189 (IEEE 754). This means that Not a Number is not equivalent to infinity. 20190 Positive infinity is treated as a very large number and negative 20191 infinity is treated as a very small (i.e. negative) number. 20192 20193 If the input has a integer type the function is equivalent to np.min. 20194 20195 Examples 20196 -------- 20197 >>> a = np.array([[1, 2], [3, np.nan]]) 20198 >>> np.nanmin(a) 20199 1.0 20200 >>> np.nanmin(a, axis=0) 20201 array([ 1., 2.]) 20202 >>> np.nanmin(a, axis=1) 20203 array([ 1., 3.]) 20204 20205 When positive infinity and negative infinity are present: 20206 20207 >>> np.nanmin([1, 2, np.nan, np.inf]) 20208 1.0 20209 >>> np.nanmin([1, 2, np.nan, np.NINF]) 20210 -inf 20211 20212 """ 20213 return ndarray() 20214 def nanstd(a=False, axis=None, dtype=None, out=None, ddof=0, keepdims=False): 20215 """ 20216 Compute the standard deviation along the specified axis, while 20217 ignoring NaNs. 20218 20219 Returns the standard deviation, a measure of the spread of a 20220 distribution, of the non-NaN array elements. The standard deviation is 20221 computed for the flattened array by default, otherwise over the 20222 specified axis. 20223 20224 For all-NaN slices or slices with zero degrees of freedom, NaN is 20225 returned and a `RuntimeWarning` is raised. 20226 20227 .. versionadded:: 1.8.0 20228 20229 Parameters 20230 ---------- 20231 a : array_like 20232 Calculate the standard deviation of the non-NaN values. 20233 axis : int, optional 20234 Axis along which the standard deviation is computed. The default is 20235 to compute the standard deviation of the flattened array. 20236 dtype : dtype, optional 20237 Type to use in computing the standard deviation. For arrays of 20238 integer type the default is float64, for arrays of float types it 20239 is the same as the array type. 20240 out : ndarray, optional 20241 Alternative output array in which to place the result. It must have 20242 the same shape as the expected output but the type (of the 20243 calculated values) will be cast if necessary. 20244 ddof : int, optional 20245 Means Delta Degrees of Freedom. The divisor used in calculations 20246 is ``N - ddof``, where ``N`` represents the number of non-NaN 20247 elements. By default `ddof` is zero. 20248 keepdims : bool, optional 20249 If this is set to True, the axes which are reduced are left 20250 in the result as dimensions with size one. With this option, 20251 the result will broadcast correctly against the original `arr`. 20252 20253 Returns 20254 ------- 20255 standard_deviation : ndarray, see dtype parameter above. 20256 If `out` is None, return a new array containing the standard 20257 deviation, otherwise return a reference to the output array. If 20258 ddof is >= the number of non-NaN elements in a slice or the slice 20259 contains only NaNs, then the result for that slice is NaN. 20260 20261 See Also 20262 -------- 20263 var, mean, std 20264 nanvar, nanmean 20265 numpy.doc.ufuncs : Section "Output arguments" 20266 20267 Notes 20268 ----- 20269 The standard deviation is the square root of the average of the squared 20270 deviations from the mean: ``std = sqrt(mean(abs(x - x.mean())**2))``. 20271 20272 The average squared deviation is normally calculated as 20273 ``x.sum() / N``, where ``N = len(x)``. If, however, `ddof` is 20274 specified, the divisor ``N - ddof`` is used instead. In standard 20275 statistical practice, ``ddof=1`` provides an unbiased estimator of the 20276 variance of the infinite population. ``ddof=0`` provides a maximum 20277 likelihood estimate of the variance for normally distributed variables. 20278 The standard deviation computed in this function is the square root of 20279 the estimated variance, so even with ``ddof=1``, it will not be an 20280 unbiased estimate of the standard deviation per se. 20281 20282 Note that, for complex numbers, `std` takes the absolute value before 20283 squaring, so that the result is always real and nonnegative. 20284 20285 For floating-point input, the *std* is computed using the same 20286 precision the input has. Depending on the input data, this can cause 20287 the results to be inaccurate, especially for float32 (see example 20288 below). Specifying a higher-accuracy accumulator using the `dtype` 20289 keyword can alleviate this issue. 20290 20291 Examples 20292 -------- 20293 >>> a = np.array([[1, np.nan], [3, 4]]) 20294 >>> np.nanstd(a) 20295 1.247219128924647 20296 >>> np.nanstd(a, axis=0) 20297 array([ 1., 0.]) 20298 >>> np.nanstd(a, axis=1) 20299 array([ 0., 0.5]) 20300 20301 """ 20302 return ndarray() 20303 def nansum(a=0, axis=None, dtype=None, out=None, keepdims=0): 20304 """ 20305 Return the sum of array elements over a given axis treating Not a 20306 Numbers (NaNs) as zero. 20307 20308 FutureWarning: In Numpy versions <= 1.8 Nan is returned for slices that 20309 are all-NaN or empty. In later versions zero will be returned. 20310 20311 Parameters 20312 ---------- 20313 a : array_like 20314 Array containing numbers whose sum is desired. If `a` is not an 20315 array, a conversion is attempted. 20316 axis : int, optional 20317 Axis along which the sum is computed. The default is to compute the 20318 sum of the flattened array. 20319 dtype : data-type, optional 20320 The type of the returned array and of the accumulator in which the 20321 elements are summed. By default, the dtype of `a` is used. An 20322 exception is when `a` has an integer type with less precision than 20323 the platform (u)intp. In that case, the default will be either 20324 (u)int32 or (u)int64 depending on whether the platform is 32 or 64 20325 bits. For inexact inputs, dtype must be inexact. 20326 20327 .. versionadded:: 1.8.0 20328 out : ndarray, optional 20329 Alternate output array in which to place the result. The default 20330 is ``None``. If provided, it must have the same shape as the 20331 expected output, but the type will be cast if necessary. See 20332 `doc.ufuncs` for details. The casting of NaN to integer can yield 20333 unexpected results. 20334 20335 .. versionadded:: 1.8.0 20336 keepdims : bool, optional 20337 If True, the axes which are reduced are left in the result as 20338 dimensions with size one. With this option, the result will 20339 broadcast correctly against the original `arr`. 20340 20341 .. versionadded:: 1.8.0 20342 20343 Returns 20344 ------- 20345 y : ndarray or numpy scalar 20346 20347 See Also 20348 -------- 20349 numpy.sum : Sum across array propagating NaNs. 20350 isnan : Show which elements are NaN. 20351 isfinite: Show which elements are not NaN or +/-inf. 20352 20353 Notes 20354 ----- 20355 If both positive and negative infinity are present, the sum will be Not 20356 A Number (NaN). 20357 20358 Numpy integer arithmetic is modular. If the size of a sum exceeds the 20359 size of an integer accumulator, its value will wrap around and the 20360 result will be incorrect. Specifying ``dtype=double`` can alleviate 20361 that problem. 20362 20363 Examples 20364 -------- 20365 >>> np.nansum(1) 20366 1 20367 >>> np.nansum([1]) 20368 1 20369 >>> np.nansum([1, np.nan]) 20370 1.0 20371 >>> a = np.array([[1, 1], [1, np.nan]]) 20372 >>> np.nansum(a) 20373 3.0 20374 >>> np.nansum(a, axis=0) 20375 array([ 2., 1.]) 20376 >>> np.nansum([1, np.nan, np.inf]) 20377 inf 20378 >>> np.nansum([1, np.nan, np.NINF]) 20379 -inf 20380 >>> np.nansum([1, np.nan, np.inf, -np.inf]) # both +/- infinity present 20381 nan 20382 20383 """ 20384 return ndarray() if False else numpy() 20385 def nanvar(a=False, axis=None, dtype=None, out=None, ddof=0, keepdims=False): 20386 """ 20387 Compute the variance along the specified axis, while ignoring NaNs. 20388 20389 Returns the variance of the array elements, a measure of the spread of 20390 a distribution. The variance is computed for the flattened array by 20391 default, otherwise over the specified axis. 20392 20393 For all-NaN slices or slices with zero degrees of freedom, NaN is 20394 returned and a `RuntimeWarning` is raised. 20395 20396 .. versionadded:: 1.8.0 20397 20398 Parameters 20399 ---------- 20400 a : array_like 20401 Array containing numbers whose variance is desired. If `a` is not an 20402 array, a conversion is attempted. 20403 axis : int, optional 20404 Axis along which the variance is computed. The default is to compute 20405 the variance of the flattened array. 20406 dtype : data-type, optional 20407 Type to use in computing the variance. For arrays of integer type 20408 the default is `float32`; for arrays of float types it is the same as 20409 the array type. 20410 out : ndarray, optional 20411 Alternate output array in which to place the result. It must have 20412 the same shape as the expected output, but the type is cast if 20413 necessary. 20414 ddof : int, optional 20415 "Delta Degrees of Freedom": the divisor used in the calculation is 20416 ``N - ddof``, where ``N`` represents the number of non-NaN 20417 elements. By default `ddof` is zero. 20418 keepdims : bool, optional 20419 If this is set to True, the axes which are reduced are left 20420 in the result as dimensions with size one. With this option, 20421 the result will broadcast correctly against the original `arr`. 20422 20423 Returns 20424 ------- 20425 variance : ndarray, see dtype parameter above 20426 If `out` is None, return a new array containing the variance, 20427 otherwise return a reference to the output array. If ddof is >= the 20428 number of non-NaN elements in a slice or the slice contains only 20429 NaNs, then the result for that slice is NaN. 20430 20431 See Also 20432 -------- 20433 std : Standard deviation 20434 mean : Average 20435 var : Variance while not ignoring NaNs 20436 nanstd, nanmean 20437 numpy.doc.ufuncs : Section "Output arguments" 20438 20439 Notes 20440 ----- 20441 The variance is the average of the squared deviations from the mean, 20442 i.e., ``var = mean(abs(x - x.mean())**2)``. 20443 20444 The mean is normally calculated as ``x.sum() / N``, where ``N = len(x)``. 20445 If, however, `ddof` is specified, the divisor ``N - ddof`` is used 20446 instead. In standard statistical practice, ``ddof=1`` provides an 20447 unbiased estimator of the variance of a hypothetical infinite 20448 population. ``ddof=0`` provides a maximum likelihood estimate of the 20449 variance for normally distributed variables. 20450 20451 Note that for complex numbers, the absolute value is taken before 20452 squaring, so that the result is always real and nonnegative. 20453 20454 For floating-point input, the variance is computed using the same 20455 precision the input has. Depending on the input data, this can cause 20456 the results to be inaccurate, especially for `float32` (see example 20457 below). Specifying a higher-accuracy accumulator using the ``dtype`` 20458 keyword can alleviate this issue. 20459 20460 Examples 20461 -------- 20462 >>> a = np.array([[1, np.nan], [3, 4]]) 20463 >>> np.var(a) 20464 1.5555555555555554 20465 >>> np.nanvar(a, axis=0) 20466 array([ 1., 0.]) 20467 >>> np.nanvar(a, axis=1) 20468 array([ 0., 0.25]) 20469 20470 """ 20471 return ndarray() 20472 nbytes = _typedict() 20473 class ndarray: 20474 T = getset_descriptor() 20475 __array_finalize__ = getset_descriptor() 20476 __array_interface__ = getset_descriptor() 20477 __array_priority__ = getset_descriptor() 20478 __array_struct__ = getset_descriptor() 20479 __doc__ = str() 20480 def all(self, axis=None, out=None): 20481 """a.all(axis=None, out=None) 20482 20483 Returns True if all elements evaluate to True. 20484 20485 Refer to `numpy.all` for full documentation. 20486 20487 See Also 20488 -------- 20489 numpy.all : equivalent function""" 20490 return None 20491 def any(self, axis=None, out=None): 20492 """a.any(axis=None, out=None) 20493 20494 Returns True if any of the elements of `a` evaluate to True. 20495 20496 Refer to `numpy.any` for full documentation. 20497 20498 See Also 20499 -------- 20500 numpy.any : equivalent function""" 20501 return None 20502 def argmax(self, axis=None, out=None): 20503 """a.argmax(axis=None, out=None) 20504 20505 Return indices of the maximum values along the given axis. 20506 20507 Refer to `numpy.argmax` for full documentation. 20508 20509 See Also 20510 -------- 20511 numpy.argmax : equivalent function""" 20512 return None 20513 def argmin(self, axis=None, out=None): 20514 """a.argmin(axis=None, out=None) 20515 20516 Return indices of the minimum values along the given axis of `a`. 20517 20518 Refer to `numpy.argmin` for detailed documentation. 20519 20520 See Also 20521 -------- 20522 numpy.argmin : equivalent function""" 20523 return None 20524 def argpartition(self, kth, axis=_1, kind=quickselect, order=None): 20525 """a.argpartition(kth, axis=-1, kind='quickselect', order=None) 20526 20527 Returns the indices that would partition this array. 20528 20529 Refer to `numpy.argpartition` for full documentation. 20530 20531 .. versionadded:: 1.8.0 20532 20533 See Also 20534 -------- 20535 numpy.argpartition : equivalent function""" 20536 return None 20537 def argsort(self, axis=_1, kind=quicksort, order=None): 20538 """a.argsort(axis=-1, kind='quicksort', order=None) 20539 20540 Returns the indices that would sort this array. 20541 20542 Refer to `numpy.argsort` for full documentation. 20543 20544 See Also 20545 -------- 20546 numpy.argsort : equivalent function""" 20547 return None 20548 def astype(self, dtype, order, casting, subok, copy): 20549 """a.astype(dtype, order='K', casting='unsafe', subok=True, copy=True) 20550 20551 Copy of the array, cast to a specified type. 20552 20553 Parameters 20554 ---------- 20555 dtype : str or dtype 20556 Typecode or data-type to which the array is cast. 20557 order : {'C', 'F', 'A', 'K'}, optional 20558 Controls the memory layout order of the result. 20559 'C' means C order, 'F' means Fortran order, 'A' 20560 means 'F' order if all the arrays are Fortran contiguous, 20561 'C' order otherwise, and 'K' means as close to the 20562 order the array elements appear in memory as possible. 20563 Default is 'K'. 20564 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional 20565 Controls what kind of data casting may occur. Defaults to 'unsafe' 20566 for backwards compatibility. 20567 20568 * 'no' means the data types should not be cast at all. 20569 * 'equiv' means only byte-order changes are allowed. 20570 * 'safe' means only casts which can preserve values are allowed. 20571 * 'same_kind' means only safe casts or casts within a kind, 20572 like float64 to float32, are allowed. 20573 * 'unsafe' means any data conversions may be done. 20574 subok : bool, optional 20575 If True, then sub-classes will be passed-through (default), otherwise 20576 the returned array will be forced to be a base-class array. 20577 copy : bool, optional 20578 By default, astype always returns a newly allocated array. If this 20579 is set to false, and the `dtype`, `order`, and `subok` 20580 requirements are satisfied, the input array is returned instead 20581 of a copy. 20582 20583 Returns 20584 ------- 20585 arr_t : ndarray 20586 Unless `copy` is False and the other conditions for returning the input 20587 array are satisfied (see description for `copy` input paramter), `arr_t` 20588 is a new array of the same shape as the input array, with dtype, order 20589 given by `dtype`, `order`. 20590 20591 Raises 20592 ------ 20593 ComplexWarning 20594 When casting from complex to float or int. To avoid this, 20595 one should use ``a.real.astype(t)``. 20596 20597 Examples 20598 -------- 20599 >>> x = np.array([1, 2, 2.5]) 20600 >>> x 20601 array([ 1. , 2. , 2.5]) 20602 20603 >>> x.astype(int) 20604 array([1, 2, 2])""" 20605 return ndarray() 20606 base = getset_descriptor() 20607 def byteswap(self, inplace): 20608 """a.byteswap(inplace) 20609 20610 Swap the bytes of the array elements 20611 20612 Toggle between low-endian and big-endian data representation by 20613 returning a byteswapped array, optionally swapped in-place. 20614 20615 Parameters 20616 ---------- 20617 inplace : bool, optional 20618 If ``True``, swap bytes in-place, default is ``False``. 20619 20620 Returns 20621 ------- 20622 out : ndarray 20623 The byteswapped array. If `inplace` is ``True``, this is 20624 a view to self. 20625 20626 Examples 20627 -------- 20628 >>> A = np.array([1, 256, 8755], dtype=np.int16) 20629 >>> map(hex, A) 20630 ['0x1', '0x100', '0x2233'] 20631 >>> A.byteswap(True) 20632 array([ 256, 1, 13090], dtype=int16) 20633 >>> map(hex, A) 20634 ['0x100', '0x1', '0x3322'] 20635 20636 Arrays of strings are not swapped 20637 20638 >>> A = np.array(['ceg', 'fac']) 20639 >>> A.byteswap() 20640 array(['ceg', 'fac'], 20641 dtype='|S3')""" 20642 return ndarray() 20643 def choose(self, choices, out=None, mode=_raise): 20644 """a.choose(choices, out=None, mode='raise') 20645 20646 Use an index array to construct a new array from a set of choices. 20647 20648 Refer to `numpy.choose` for full documentation. 20649 20650 See Also 20651 -------- 20652 numpy.choose : equivalent function""" 20653 return None 20654 def clip(self, a_min, a_max, out=None): 20655 """a.clip(a_min, a_max, out=None) 20656 20657 Return an array whose values are limited to ``[a_min, a_max]``. 20658 20659 Refer to `numpy.clip` for full documentation. 20660 20661 See Also 20662 -------- 20663 numpy.clip : equivalent function""" 20664 return None 20665 def compress(self, condition, axis=None, out=None): 20666 """a.compress(condition, axis=None, out=None) 20667 20668 Return selected slices of this array along given axis. 20669 20670 Refer to `numpy.compress` for full documentation. 20671 20672 See Also 20673 -------- 20674 numpy.compress : equivalent function""" 20675 return None 20676 def conj(self, _): 20677 """a.conj() 20678 20679 Complex-conjugate all elements. 20680 20681 Refer to `numpy.conjugate` for full documentation. 20682 20683 See Also 20684 -------- 20685 numpy.conjugate : equivalent function""" 20686 return None 20687 def conjugate(self, _): 20688 """a.conjugate() 20689 20690 Return the complex conjugate, element-wise. 20691 20692 Refer to `numpy.conjugate` for full documentation. 20693 20694 See Also 20695 -------- 20696 numpy.conjugate : equivalent function""" 20697 return None 20698 def copy(self, order): 20699 """a.copy(order='C') 20700 20701 Return a copy of the array. 20702 20703 Parameters 20704 ---------- 20705 order : {'C', 'F', 'A', 'K'}, optional 20706 Controls the memory layout of the copy. 'C' means C-order, 20707 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, 20708 'C' otherwise. 'K' means match the layout of `a` as closely 20709 as possible. (Note that this function and :func:numpy.copy are very 20710 similar, but have different default values for their order= 20711 arguments.) 20712 20713 See also 20714 -------- 20715 numpy.copy 20716 numpy.copyto 20717 20718 Examples 20719 -------- 20720 >>> x = np.array([[1,2,3],[4,5,6]], order='F') 20721 20722 >>> y = x.copy() 20723 20724 >>> x.fill(0) 20725 20726 >>> x 20727 array([[0, 0, 0], 20728 [0, 0, 0]]) 20729 20730 >>> y 20731 array([[1, 2, 3], 20732 [4, 5, 6]]) 20733 20734 >>> y.flags['C_CONTIGUOUS'] 20735 True""" 20736 return None 20737 ctypes = getset_descriptor() 20738 def cumprod(self, axis=None, dtype=None, out=None): 20739 """a.cumprod(axis=None, dtype=None, out=None) 20740 20741 Return the cumulative product of the elements along the given axis. 20742 20743 Refer to `numpy.cumprod` for full documentation. 20744 20745 See Also 20746 -------- 20747 numpy.cumprod : equivalent function""" 20748 return None 20749 def cumsum(self, axis=None, dtype=None, out=None): 20750 """a.cumsum(axis=None, dtype=None, out=None) 20751 20752 Return the cumulative sum of the elements along the given axis. 20753 20754 Refer to `numpy.cumsum` for full documentation. 20755 20756 See Also 20757 -------- 20758 numpy.cumsum : equivalent function""" 20759 return None 20760 data = getset_descriptor() 20761 def diagonal(self, offset=0, axis1=0, axis2=1): 20762 """a.diagonal(offset=0, axis1=0, axis2=1) 20763 20764 Return specified diagonals. 20765 20766 Refer to :func:`numpy.diagonal` for full documentation. 20767 20768 See Also 20769 -------- 20770 numpy.diagonal : equivalent function""" 20771 return None 20772 def dot(self, b, out=None): 20773 """a.dot(b, out=None) 20774 20775 Dot product of two arrays. 20776 20777 Refer to `numpy.dot` for full documentation. 20778 20779 See Also 20780 -------- 20781 numpy.dot : equivalent function 20782 20783 Examples 20784 -------- 20785 >>> a = np.eye(2) 20786 >>> b = np.ones((2, 2)) * 2 20787 >>> a.dot(b) 20788 array([[ 2., 2.], 20789 [ 2., 2.]]) 20790 20791 This array method can be conveniently chained: 20792 20793 >>> a.dot(b).dot(b) 20794 array([[ 8., 8.], 20795 [ 8., 8.]])""" 20796 return None 20797 dtype = getset_descriptor() 20798 def dump(self, file): 20799 """a.dump(file) 20800 20801 Dump a pickle of the array to the specified file. 20802 The array can be read back with pickle.load or numpy.load. 20803 20804 Parameters 20805 ---------- 20806 file : str 20807 A string naming the dump file.""" 20808 return None 20809 def dumps(self, _): 20810 """a.dumps() 20811 20812 Returns the pickle of the array as a string. 20813 pickle.loads or numpy.loads will convert the string back to an array. 20814 20815 Parameters 20816 ---------- 20817 None""" 20818 return None 20819 def fill(self, value): 20820 """a.fill(value) 20821 20822 Fill the array with a scalar value. 20823 20824 Parameters 20825 ---------- 20826 value : scalar 20827 All elements of `a` will be assigned this value. 20828 20829 Examples 20830 -------- 20831 >>> a = np.array([1, 2]) 20832 >>> a.fill(0) 20833 >>> a 20834 array([0, 0]) 20835 >>> a = np.empty(2) 20836 >>> a.fill(1) 20837 >>> a 20838 array([ 1., 1.])""" 20839 return None 20840 flags = getset_descriptor() 20841 flat = getset_descriptor() 20842 def flatten(self, order): 20843 """a.flatten(order='C') 20844 20845 Return a copy of the array collapsed into one dimension. 20846 20847 Parameters 20848 ---------- 20849 order : {'C', 'F', 'A'}, optional 20850 Whether to flatten in C (row-major), Fortran (column-major) order, 20851 or preserve the C/Fortran ordering from `a`. 20852 The default is 'C'. 20853 20854 Returns 20855 ------- 20856 y : ndarray 20857 A copy of the input array, flattened to one dimension. 20858 20859 See Also 20860 -------- 20861 ravel : Return a flattened array. 20862 flat : A 1-D flat iterator over the array. 20863 20864 Examples 20865 -------- 20866 >>> a = np.array([[1,2], [3,4]]) 20867 >>> a.flatten() 20868 array([1, 2, 3, 4]) 20869 >>> a.flatten('F') 20870 array([1, 3, 2, 4])""" 20871 return ndarray() 20872 def getfield(self, dtype, offset): 20873 """a.getfield(dtype, offset=0) 20874 20875 Returns a field of the given array as a certain type. 20876 20877 A field is a view of the array data with a given data-type. The values in 20878 the view are determined by the given type and the offset into the current 20879 array in bytes. The offset needs to be such that the view dtype fits in the 20880 array dtype; for example an array of dtype complex128 has 16-byte elements. 20881 If taking a view with a 32-bit integer (4 bytes), the offset needs to be 20882 between 0 and 12 bytes. 20883 20884 Parameters 20885 ---------- 20886 dtype : str or dtype 20887 The data type of the view. The dtype size of the view can not be larger 20888 than that of the array itself. 20889 offset : int 20890 Number of bytes to skip before beginning the element view. 20891 20892 Examples 20893 -------- 20894 >>> x = np.diag([1.+1.j]*2) 20895 >>> x[1, 1] = 2 + 4.j 20896 >>> x 20897 array([[ 1.+1.j, 0.+0.j], 20898 [ 0.+0.j, 2.+4.j]]) 20899 >>> x.getfield(np.float64) 20900 array([[ 1., 0.], 20901 [ 0., 2.]]) 20902 20903 By choosing an offset of 8 bytes we can select the complex part of the 20904 array for our view: 20905 20906 >>> x.getfield(np.float64, offset=8) 20907 array([[ 1., 0.], 20908 [ 0., 4.]])""" 20909 return array() 20910 imag = getset_descriptor() 20911 def item(self, ESCargs): 20912 """a.item(*args) 20913 20914 Copy an element of an array to a standard Python scalar and return it. 20915 20916 Parameters 20917 ---------- 20918 \*args : Arguments (variable number and type) 20919 20920 * none: in this case, the method only works for arrays 20921 with one element (`a.size == 1`), which element is 20922 copied into a standard Python scalar object and returned. 20923 20924 * int_type: this argument is interpreted as a flat index into 20925 the array, specifying which element to copy and return. 20926 20927 * tuple of int_types: functions as does a single int_type argument, 20928 except that the argument is interpreted as an nd-index into the 20929 array. 20930 20931 Returns 20932 ------- 20933 z : Standard Python scalar object 20934 A copy of the specified element of the array as a suitable 20935 Python scalar 20936 20937 Notes 20938 ----- 20939 When the data type of `a` is longdouble or clongdouble, item() returns 20940 a scalar array object because there is no available Python scalar that 20941 would not lose information. Void arrays return a buffer object for item(), 20942 unless fields are defined, in which case a tuple is returned. 20943 20944 `item` is very similar to a[args], except, instead of an array scalar, 20945 a standard Python scalar is returned. This can be useful for speeding up 20946 access to elements of the array and doing arithmetic on elements of the 20947 array using Python's optimized math. 20948 20949 Examples 20950 -------- 20951 >>> x = np.random.randint(9, size=(3, 3)) 20952 >>> x 20953 array([[3, 1, 7], 20954 [2, 8, 3], 20955 [8, 5, 3]]) 20956 >>> x.item(3) 20957 2 20958 >>> x.item(7) 20959 5 20960 >>> x.item((0, 1)) 20961 1 20962 >>> x.item((2, 2)) 20963 3""" 20964 return Standard() 20965 def itemset(self, ESCargs): 20966 """a.itemset(*args) 20967 20968 Insert scalar into an array (scalar is cast to array's dtype, if possible) 20969 20970 There must be at least 1 argument, and define the last argument 20971 as *item*. Then, ``a.itemset(*args)`` is equivalent to but faster 20972 than ``a[args] = item``. The item should be a scalar value and `args` 20973 must select a single item in the array `a`. 20974 20975 Parameters 20976 ---------- 20977 \*args : Arguments 20978 If one argument: a scalar, only used in case `a` is of size 1. 20979 If two arguments: the last argument is the value to be set 20980 and must be a scalar, the first argument specifies a single array 20981 element location. It is either an int or a tuple. 20982 20983 Notes 20984 ----- 20985 Compared to indexing syntax, `itemset` provides some speed increase 20986 for placing a scalar into a particular location in an `ndarray`, 20987 if you must do this. However, generally this is discouraged: 20988 among other problems, it complicates the appearance of the code. 20989 Also, when using `itemset` (and `item`) inside a loop, be sure 20990 to assign the methods to a local variable to avoid the attribute 20991 look-up at each loop iteration. 20992 20993 Examples 20994 -------- 20995 >>> x = np.random.randint(9, size=(3, 3)) 20996 >>> x 20997 array([[3, 1, 7], 20998 [2, 8, 3], 20999 [8, 5, 3]]) 21000 >>> x.itemset(4, 0) 21001 >>> x.itemset((2, 2), 9) 21002 >>> x 21003 array([[3, 1, 7], 21004 [2, 0, 3], 21005 [8, 5, 9]])""" 21006 return None 21007 itemsize = getset_descriptor() 21008 def max(self, axis=None, out=None): 21009 """a.max(axis=None, out=None) 21010 21011 Return the maximum along a given axis. 21012 21013 Refer to `numpy.amax` for full documentation. 21014 21015 See Also 21016 -------- 21017 numpy.amax : equivalent function""" 21018 return None 21019 def mean(self, axis=None, dtype=None, out=None): 21020 """a.mean(axis=None, dtype=None, out=None) 21021 21022 Returns the average of the array elements along given axis. 21023 21024 Refer to `numpy.mean` for full documentation. 21025 21026 See Also 21027 -------- 21028 numpy.mean : equivalent function""" 21029 return None 21030 def min(self, axis=None, out=None): 21031 """a.min(axis=None, out=None) 21032 21033 Return the minimum along a given axis. 21034 21035 Refer to `numpy.amin` for full documentation. 21036 21037 See Also 21038 -------- 21039 numpy.amin : equivalent function""" 21040 return None 21041 nbytes = getset_descriptor() 21042 ndim = getset_descriptor() 21043 def newbyteorder(self, new_order): 21044 """arr.newbyteorder(new_order='S') 21045 21046 Return the array with the same data viewed with a different byte order. 21047 21048 Equivalent to:: 21049 21050 arr.view(arr.dtype.newbytorder(new_order)) 21051 21052 Changes are also made in all fields and sub-arrays of the array data 21053 type. 21054 21055 21056 21057 Parameters 21058 ---------- 21059 new_order : string, optional 21060 Byte order to force; a value from the byte order specifications 21061 above. `new_order` codes can be any of:: 21062 21063 * 'S' - swap dtype from current to opposite endian 21064 * {'<', 'L'} - little endian 21065 * {'>', 'B'} - big endian 21066 * {'=', 'N'} - native order 21067 * {'|', 'I'} - ignore (no change to byte order) 21068 21069 The default value ('S') results in swapping the current 21070 byte order. The code does a case-insensitive check on the first 21071 letter of `new_order` for the alternatives above. For example, 21072 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 21073 21074 21075 Returns 21076 ------- 21077 new_arr : array 21078 New array object with the dtype reflecting given change to the 21079 byte order.""" 21080 return array() 21081 def nonzero(self, _): 21082 """a.nonzero() 21083 21084 Return the indices of the elements that are non-zero. 21085 21086 Refer to `numpy.nonzero` for full documentation. 21087 21088 See Also 21089 -------- 21090 numpy.nonzero : equivalent function""" 21091 return None 21092 def partition(self, kth, axis, kind, order): 21093 """a.partition(kth, axis=-1, kind='introselect', order=None) 21094 21095 Rearranges the elements in the array in such a way that value of the 21096 element in kth position is in the position it would be in a sorted array. 21097 All elements smaller than the kth element are moved before this element and 21098 all equal or greater are moved behind it. The ordering of the elements in 21099 the two partitions is undefined. 21100 21101 .. versionadded:: 1.8.0 21102 21103 Parameters 21104 ---------- 21105 kth : int or sequence of ints 21106 Element index to partition by. The kth element value will be in its 21107 final sorted position and all smaller elements will be moved before it 21108 and all equal or greater elements behind it. 21109 The order all elements in the partitions is undefined. 21110 If provided with a sequence of kth it will partition all elements 21111 indexed by kth of them into their sorted position at once. 21112 axis : int, optional 21113 Axis along which to sort. Default is -1, which means sort along the 21114 last axis. 21115 kind : {'introselect'}, optional 21116 Selection algorithm. Default is 'introselect'. 21117 order : list, optional 21118 When `a` is an array with fields defined, this argument specifies 21119 which fields to compare first, second, etc. Not all fields need be 21120 specified. 21121 21122 See Also 21123 -------- 21124 numpy.partition : Return a parititioned copy of an array. 21125 argpartition : Indirect partition. 21126 sort : Full sort. 21127 21128 Notes 21129 ----- 21130 See ``np.partition`` for notes on the different algorithms. 21131 21132 Examples 21133 -------- 21134 >>> a = np.array([3, 4, 2, 1]) 21135 >>> a.partition(a, 3) 21136 >>> a 21137 array([2, 1, 3, 4]) 21138 21139 >>> a.partition((1, 3)) 21140 array([1, 2, 3, 4])""" 21141 return None 21142 def prod(self, axis=None, dtype=None, out=None): 21143 """a.prod(axis=None, dtype=None, out=None) 21144 21145 Return the product of the array elements over the given axis 21146 21147 Refer to `numpy.prod` for full documentation. 21148 21149 See Also 21150 -------- 21151 numpy.prod : equivalent function""" 21152 return None 21153 def ptp(self, axis=None, out=None): 21154 """a.ptp(axis=None, out=None) 21155 21156 Peak to peak (maximum - minimum) value along a given axis. 21157 21158 Refer to `numpy.ptp` for full documentation. 21159 21160 See Also 21161 -------- 21162 numpy.ptp : equivalent function""" 21163 return None 21164 def put(self, indices, values, mode=_raise): 21165 """a.put(indices, values, mode='raise') 21166 21167 Set ``a.flat[n] = values[n]`` for all `n` in indices. 21168 21169 Refer to `numpy.put` for full documentation. 21170 21171 See Also 21172 -------- 21173 numpy.put : equivalent function""" 21174 return None 21175 def ravel(self, order): 21176 """a.ravel([order]) 21177 21178 Return a flattened array. 21179 21180 Refer to `numpy.ravel` for full documentation. 21181 21182 See Also 21183 -------- 21184 numpy.ravel : equivalent function 21185 21186 ndarray.flat : a flat iterator on the array.""" 21187 return None 21188 real = getset_descriptor() 21189 def repeat(self, repeats, axis=None): 21190 """a.repeat(repeats, axis=None) 21191 21192 Repeat elements of an array. 21193 21194 Refer to `numpy.repeat` for full documentation. 21195 21196 See Also 21197 -------- 21198 numpy.repeat : equivalent function""" 21199 return None 21200 def reshape(self, shape, order=C): 21201 """a.reshape(shape, order='C') 21202 21203 Returns an array containing the same data with a new shape. 21204 21205 Refer to `numpy.reshape` for full documentation. 21206 21207 See Also 21208 -------- 21209 numpy.reshape : equivalent function""" 21210 return None 21211 def resize(self, new_shape, refcheck): 21212 """a.resize(new_shape, refcheck=True) 21213 21214 Change shape and size of array in-place. 21215 21216 Parameters 21217 ---------- 21218 new_shape : tuple of ints, or `n` ints 21219 Shape of resized array. 21220 refcheck : bool, optional 21221 If False, reference count will not be checked. Default is True. 21222 21223 Returns 21224 ------- 21225 None 21226 21227 Raises 21228 ------ 21229 ValueError 21230 If `a` does not own its own data or references or views to it exist, 21231 and the data memory must be changed. 21232 21233 SystemError 21234 If the `order` keyword argument is specified. This behaviour is a 21235 bug in NumPy. 21236 21237 See Also 21238 -------- 21239 resize : Return a new array with the specified shape. 21240 21241 Notes 21242 ----- 21243 This reallocates space for the data area if necessary. 21244 21245 Only contiguous arrays (data elements consecutive in memory) can be 21246 resized. 21247 21248 The purpose of the reference count check is to make sure you 21249 do not use this array as a buffer for another Python object and then 21250 reallocate the memory. However, reference counts can increase in 21251 other ways so if you are sure that you have not shared the memory 21252 for this array with another Python object, then you may safely set 21253 `refcheck` to False. 21254 21255 Examples 21256 -------- 21257 Shrinking an array: array is flattened (in the order that the data are 21258 stored in memory), resized, and reshaped: 21259 21260 >>> a = np.array([[0, 1], [2, 3]], order='C') 21261 >>> a.resize((2, 1)) 21262 >>> a 21263 array([[0], 21264 [1]]) 21265 21266 >>> a = np.array([[0, 1], [2, 3]], order='F') 21267 >>> a.resize((2, 1)) 21268 >>> a 21269 array([[0], 21270 [2]]) 21271 21272 Enlarging an array: as above, but missing entries are filled with zeros: 21273 21274 >>> b = np.array([[0, 1], [2, 3]]) 21275 >>> b.resize(2, 3) # new_shape parameter doesn't have to be a tuple 21276 >>> b 21277 array([[0, 1, 2], 21278 [3, 0, 0]]) 21279 21280 Referencing an array prevents resizing... 21281 21282 >>> c = a 21283 >>> a.resize((1, 1)) 21284 Traceback (most recent call last): 21285 ... 21286 ValueError: cannot resize an array that has been referenced ... 21287 21288 Unless `refcheck` is False: 21289 21290 >>> a.resize((1, 1), refcheck=False) 21291 >>> a 21292 array([[0]]) 21293 >>> c 21294 array([[0]])""" 21295 return None 21296 def round(self, decimals=0, out=None): 21297 """a.round(decimals=0, out=None) 21298 21299 Return `a` with each element rounded to the given number of decimals. 21300 21301 Refer to `numpy.around` for full documentation. 21302 21303 See Also 21304 -------- 21305 numpy.around : equivalent function""" 21306 return None 21307 def searchsorted(self, v, side=left, sorter=None): 21308 """a.searchsorted(v, side='left', sorter=None) 21309 21310 Find indices where elements of v should be inserted in a to maintain order. 21311 21312 For full documentation, see `numpy.searchsorted` 21313 21314 See Also 21315 -------- 21316 numpy.searchsorted : equivalent function""" 21317 return None 21318 def setfield(self, val, dtype, offset): 21319 """a.setfield(val, dtype, offset=0) 21320 21321 Put a value into a specified place in a field defined by a data-type. 21322 21323 Place `val` into `a`'s field defined by `dtype` and beginning `offset` 21324 bytes into the field. 21325 21326 Parameters 21327 ---------- 21328 val : object 21329 Value to be placed in field. 21330 dtype : dtype object 21331 Data-type of the field in which to place `val`. 21332 offset : int, optional 21333 The number of bytes into the field at which to place `val`. 21334 21335 Returns 21336 ------- 21337 None 21338 21339 See Also 21340 -------- 21341 getfield 21342 21343 Examples 21344 -------- 21345 >>> x = np.eye(3) 21346 >>> x.getfield(np.float64) 21347 array([[ 1., 0., 0.], 21348 [ 0., 1., 0.], 21349 [ 0., 0., 1.]]) 21350 >>> x.setfield(3, np.int32) 21351 >>> x.getfield(np.int32) 21352 array([[3, 3, 3], 21353 [3, 3, 3], 21354 [3, 3, 3]]) 21355 >>> x 21356 array([[ 1.00000000e+000, 1.48219694e-323, 1.48219694e-323], 21357 [ 1.48219694e-323, 1.00000000e+000, 1.48219694e-323], 21358 [ 1.48219694e-323, 1.48219694e-323, 1.00000000e+000]]) 21359 >>> x.setfield(np.eye(3), np.int32) 21360 >>> x 21361 array([[ 1., 0., 0.], 21362 [ 0., 1., 0.], 21363 [ 0., 0., 1.]])""" 21364 return None 21365 def setflags(self, write, align, uic): 21366 """a.setflags(write=None, align=None, uic=None) 21367 21368 Set array flags WRITEABLE, ALIGNED, and UPDATEIFCOPY, respectively. 21369 21370 These Boolean-valued flags affect how numpy interprets the memory 21371 area used by `a` (see Notes below). The ALIGNED flag can only 21372 be set to True if the data is actually aligned according to the type. 21373 The UPDATEIFCOPY flag can never be set to True. The flag WRITEABLE 21374 can only be set to True if the array owns its own memory, or the 21375 ultimate owner of the memory exposes a writeable buffer interface, 21376 or is a string. (The exception for string is made so that unpickling 21377 can be done without copying memory.) 21378 21379 Parameters 21380 ---------- 21381 write : bool, optional 21382 Describes whether or not `a` can be written to. 21383 align : bool, optional 21384 Describes whether or not `a` is aligned properly for its type. 21385 uic : bool, optional 21386 Describes whether or not `a` is a copy of another "base" array. 21387 21388 Notes 21389 ----- 21390 Array flags provide information about how the memory area used 21391 for the array is to be interpreted. There are 6 Boolean flags 21392 in use, only three of which can be changed by the user: 21393 UPDATEIFCOPY, WRITEABLE, and ALIGNED. 21394 21395 WRITEABLE (W) the data area can be written to; 21396 21397 ALIGNED (A) the data and strides are aligned appropriately for the hardware 21398 (as determined by the compiler); 21399 21400 UPDATEIFCOPY (U) this array is a copy of some other array (referenced 21401 by .base). When this array is deallocated, the base array will be 21402 updated with the contents of this array. 21403 21404 All flags can be accessed using their first (upper case) letter as well 21405 as the full name. 21406 21407 Examples 21408 -------- 21409 >>> y 21410 array([[3, 1, 7], 21411 [2, 0, 0], 21412 [8, 5, 9]]) 21413 >>> y.flags 21414 C_CONTIGUOUS : True 21415 F_CONTIGUOUS : False 21416 OWNDATA : True 21417 WRITEABLE : True 21418 ALIGNED : True 21419 UPDATEIFCOPY : False 21420 >>> y.setflags(write=0, align=0) 21421 >>> y.flags 21422 C_CONTIGUOUS : True 21423 F_CONTIGUOUS : False 21424 OWNDATA : True 21425 WRITEABLE : False 21426 ALIGNED : False 21427 UPDATEIFCOPY : False 21428 >>> y.setflags(uic=1) 21429 Traceback (most recent call last): 21430 File "<stdin>", line 1, in <module> 21431 ValueError: cannot set UPDATEIFCOPY flag to True""" 21432 return None 21433 shape = getset_descriptor() 21434 size = getset_descriptor() 21435 def sort(self, axis, kind, order): 21436 """a.sort(axis=-1, kind='quicksort', order=None) 21437 21438 Sort an array, in-place. 21439 21440 Parameters 21441 ---------- 21442 axis : int, optional 21443 Axis along which to sort. Default is -1, which means sort along the 21444 last axis. 21445 kind : {'quicksort', 'mergesort', 'heapsort'}, optional 21446 Sorting algorithm. Default is 'quicksort'. 21447 order : list, optional 21448 When `a` is an array with fields defined, this argument specifies 21449 which fields to compare first, second, etc. Not all fields need be 21450 specified. 21451 21452 See Also 21453 -------- 21454 numpy.sort : Return a sorted copy of an array. 21455 argsort : Indirect sort. 21456 lexsort : Indirect stable sort on multiple keys. 21457 searchsorted : Find elements in sorted array. 21458 partition: Partial sort. 21459 21460 Notes 21461 ----- 21462 See ``sort`` for notes on the different sorting algorithms. 21463 21464 Examples 21465 -------- 21466 >>> a = np.array([[1,4], [3,1]]) 21467 >>> a.sort(axis=1) 21468 >>> a 21469 array([[1, 4], 21470 [1, 3]]) 21471 >>> a.sort(axis=0) 21472 >>> a 21473 array([[1, 3], 21474 [1, 4]]) 21475 21476 Use the `order` keyword to specify a field to use when sorting a 21477 structured array: 21478 21479 >>> a = np.array([('a', 2), ('c', 1)], dtype=[('x', 'S1'), ('y', int)]) 21480 >>> a.sort(order='y') 21481 >>> a 21482 array([('c', 1), ('a', 2)], 21483 dtype=[('x', '|S1'), ('y', '<i4')])""" 21484 return None 21485 def squeeze(self, axis=None): 21486 """a.squeeze(axis=None) 21487 21488 Remove single-dimensional entries from the shape of `a`. 21489 21490 Refer to `numpy.squeeze` for full documentation. 21491 21492 See Also 21493 -------- 21494 numpy.squeeze : equivalent function""" 21495 return None 21496 def std(self, axis=None, dtype=None, out=None, ddof=0): 21497 """a.std(axis=None, dtype=None, out=None, ddof=0) 21498 21499 Returns the standard deviation of the array elements along given axis. 21500 21501 Refer to `numpy.std` for full documentation. 21502 21503 See Also 21504 -------- 21505 numpy.std : equivalent function""" 21506 return None 21507 strides = getset_descriptor() 21508 def sum(self, axis=None, dtype=None, out=None): 21509 """a.sum(axis=None, dtype=None, out=None) 21510 21511 Return the sum of the array elements over the given axis. 21512 21513 Refer to `numpy.sum` for full documentation. 21514 21515 See Also 21516 -------- 21517 numpy.sum : equivalent function""" 21518 return None 21519 def swapaxes(self, axis1, axis2): 21520 """a.swapaxes(axis1, axis2) 21521 21522 Return a view of the array with `axis1` and `axis2` interchanged. 21523 21524 Refer to `numpy.swapaxes` for full documentation. 21525 21526 See Also 21527 -------- 21528 numpy.swapaxes : equivalent function""" 21529 return None 21530 def take(self, indices, axis=None, out=None, mode=_raise): 21531 """a.take(indices, axis=None, out=None, mode='raise') 21532 21533 Return an array formed from the elements of `a` at the given indices. 21534 21535 Refer to `numpy.take` for full documentation. 21536 21537 See Also 21538 -------- 21539 numpy.take : equivalent function""" 21540 return None 21541 def tofile(self, fid, sep, format): 21542 """a.tofile(fid, sep="", format="%s") 21543 21544 Write array to a file as text or binary (default). 21545 21546 Data is always written in 'C' order, independent of the order of `a`. 21547 The data produced by this method can be recovered using the function 21548 fromfile(). 21549 21550 Parameters 21551 ---------- 21552 fid : file or str 21553 An open file object, or a string containing a filename. 21554 sep : str 21555 Separator between array items for text output. 21556 If "" (empty), a binary file is written, equivalent to 21557 ``file.write(a.tostring())``. 21558 format : str 21559 Format string for text file output. 21560 Each entry in the array is formatted to text by first converting 21561 it to the closest Python type, and then using "format" % item. 21562 21563 Notes 21564 ----- 21565 This is a convenience function for quick storage of array data. 21566 Information on endianness and precision is lost, so this method is not a 21567 good choice for files intended to archive data or transport data between 21568 machines with different endianness. Some of these problems can be overcome 21569 by outputting the data as text files, at the expense of speed and file 21570 size.""" 21571 return None 21572 def tolist(self, _): 21573 """a.tolist() 21574 21575 Return the array as a (possibly nested) list. 21576 21577 Return a copy of the array data as a (nested) Python list. 21578 Data items are converted to the nearest compatible Python type. 21579 21580 Parameters 21581 ---------- 21582 none 21583 21584 Returns 21585 ------- 21586 y : list 21587 The possibly nested list of array elements. 21588 21589 Notes 21590 ----- 21591 The array may be recreated, ``a = np.array(a.tolist())``. 21592 21593 Examples 21594 -------- 21595 >>> a = np.array([1, 2]) 21596 >>> a.tolist() 21597 [1, 2] 21598 >>> a = np.array([[1, 2], [3, 4]]) 21599 >>> list(a) 21600 [array([1, 2]), array([3, 4])] 21601 >>> a.tolist() 21602 [[1, 2], [3, 4]]""" 21603 return list() 21604 def tostring(self, order): 21605 """a.tostring(order='C') 21606 21607 Construct a Python string containing the raw data bytes in the array. 21608 21609 Constructs a Python string showing a copy of the raw contents of 21610 data memory. The string can be produced in either 'C' or 'Fortran', 21611 or 'Any' order (the default is 'C'-order). 'Any' order means C-order 21612 unless the F_CONTIGUOUS flag in the array is set, in which case it 21613 means 'Fortran' order. 21614 21615 Parameters 21616 ---------- 21617 order : {'C', 'F', None}, optional 21618 Order of the data for multidimensional arrays: 21619 C, Fortran, or the same as for the original array. 21620 21621 Returns 21622 ------- 21623 s : str 21624 A Python string exhibiting a copy of `a`'s raw data. 21625 21626 Examples 21627 -------- 21628 >>> x = np.array([[0, 1], [2, 3]]) 21629 >>> x.tostring() 21630 '\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00' 21631 >>> x.tostring('C') == x.tostring() 21632 True 21633 >>> x.tostring('F') 21634 '\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00'""" 21635 return str() 21636 def trace(self, offset=0, axis1=0, axis2=1, dtype=None, out=None): 21637 """a.trace(offset=0, axis1=0, axis2=1, dtype=None, out=None) 21638 21639 Return the sum along diagonals of the array. 21640 21641 Refer to `numpy.trace` for full documentation. 21642 21643 See Also 21644 -------- 21645 numpy.trace : equivalent function""" 21646 return None 21647 def transpose(self, axes): 21648 """a.transpose(*axes) 21649 21650 Returns a view of the array with axes transposed. 21651 21652 For a 1-D array, this has no effect. (To change between column and 21653 row vectors, first cast the 1-D array into a matrix object.) 21654 For a 2-D array, this is the usual matrix transpose. 21655 For an n-D array, if axes are given, their order indicates how the 21656 axes are permuted (see Examples). If axes are not provided and 21657 ``a.shape = (i[0], i[1], ... i[n-2], i[n-1])``, then 21658 ``a.transpose().shape = (i[n-1], i[n-2], ... i[1], i[0])``. 21659 21660 Parameters 21661 ---------- 21662 axes : None, tuple of ints, or `n` ints 21663 21664 * None or no argument: reverses the order of the axes. 21665 21666 * tuple of ints: `i` in the `j`-th place in the tuple means `a`'s 21667 `i`-th axis becomes `a.transpose()`'s `j`-th axis. 21668 21669 * `n` ints: same as an n-tuple of the same ints (this form is 21670 intended simply as a "convenience" alternative to the tuple form) 21671 21672 Returns 21673 ------- 21674 out : ndarray 21675 View of `a`, with axes suitably permuted. 21676 21677 See Also 21678 -------- 21679 ndarray.T : Array property returning the array transposed. 21680 21681 Examples 21682 -------- 21683 >>> a = np.array([[1, 2], [3, 4]]) 21684 >>> a 21685 array([[1, 2], 21686 [3, 4]]) 21687 >>> a.transpose() 21688 array([[1, 3], 21689 [2, 4]]) 21690 >>> a.transpose((1, 0)) 21691 array([[1, 3], 21692 [2, 4]]) 21693 >>> a.transpose(1, 0) 21694 array([[1, 3], 21695 [2, 4]])""" 21696 return ndarray() 21697 def var(self, axis=None, dtype=None, out=None, ddof=0): 21698 """a.var(axis=None, dtype=None, out=None, ddof=0) 21699 21700 Returns the variance of the array elements, along given axis. 21701 21702 Refer to `numpy.var` for full documentation. 21703 21704 See Also 21705 -------- 21706 numpy.var : equivalent function""" 21707 return None 21708 def view(self, dtype, type): 21709 """a.view(dtype=None, type=None) 21710 21711 New view of array with the same data. 21712 21713 Parameters 21714 ---------- 21715 dtype : data-type or ndarray sub-class, optional 21716 Data-type descriptor of the returned view, e.g., float32 or int16. The 21717 default, None, results in the view having the same data-type as `a`. 21718 This argument can also be specified as an ndarray sub-class, which 21719 then specifies the type of the returned object (this is equivalent to 21720 setting the ``type`` parameter). 21721 type : Python type, optional 21722 Type of the returned view, e.g., ndarray or matrix. Again, the 21723 default None results in type preservation. 21724 21725 Notes 21726 ----- 21727 ``a.view()`` is used two different ways: 21728 21729 ``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view 21730 of the array's memory with a different data-type. This can cause a 21731 reinterpretation of the bytes of memory. 21732 21733 ``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just 21734 returns an instance of `ndarray_subclass` that looks at the same array 21735 (same shape, dtype, etc.) This does not cause a reinterpretation of the 21736 memory. 21737 21738 For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of 21739 bytes per entry than the previous dtype (for example, converting a 21740 regular array to a structured array), then the behavior of the view 21741 cannot be predicted just from the superficial appearance of ``a`` (shown 21742 by ``print(a)``). It also depends on exactly how ``a`` is stored in 21743 memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus 21744 defined as a slice or transpose, etc., the view may give different 21745 results. 21746 21747 21748 Examples 21749 -------- 21750 >>> x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)]) 21751 21752 Viewing array data using a different type and dtype: 21753 21754 >>> y = x.view(dtype=np.int16, type=np.matrix) 21755 >>> y 21756 matrix([[513]], dtype=int16) 21757 >>> print type(y) 21758 <class 'numpy.matrixlib.defmatrix.matrix'> 21759 21760 Creating a view on a structured array so it can be used in calculations 21761 21762 >>> x = np.array([(1, 2),(3,4)], dtype=[('a', np.int8), ('b', np.int8)]) 21763 >>> xv = x.view(dtype=np.int8).reshape(-1,2) 21764 >>> xv 21765 array([[1, 2], 21766 [3, 4]], dtype=int8) 21767 >>> xv.mean(0) 21768 array([ 2., 3.]) 21769 21770 Making changes to the view changes the underlying array 21771 21772 >>> xv[0,1] = 20 21773 >>> print x 21774 [(1, 20) (3, 4)] 21775 21776 Using a view to convert an array to a record array: 21777 21778 >>> z = x.view(np.recarray) 21779 >>> z.a 21780 array([1], dtype=int8) 21781 21782 Views share data: 21783 21784 >>> x[0] = (9, 10) 21785 >>> z[0] 21786 (9, 10) 21787 21788 Views that change the dtype size (bytes per entry) should normally be 21789 avoided on arrays defined by slices, transposes, fortran-ordering, etc.: 21790 21791 >>> x = np.array([[1,2,3],[4,5,6]], dtype=np.int16) 21792 >>> y = x[:, 0:2] 21793 >>> y 21794 array([[1, 2], 21795 [4, 5]], dtype=int16) 21796 >>> y.view(dtype=[('width', np.int16), ('length', np.int16)]) 21797 Traceback (most recent call last): 21798 File "<stdin>", line 1, in <module> 21799 ValueError: new type not compatible with array. 21800 >>> z = y.copy() 21801 >>> z.view(dtype=[('width', np.int16), ('length', np.int16)]) 21802 array([[(1, 2)], 21803 [(4, 5)]], dtype=[('width', '<i2'), ('length', '<i2')])""" 21804 return None 21805 class ndenumerate: 21806 __dict__ = dictproxy() 21807 __doc__ = str() 21808 __module__ = str() 21809 __weakref__ = getset_descriptor() 21810 def nd_fromtxt(fnamekwargs): 21811 """ 21812 Load ASCII data stored in a file and return it as a single array. 21813 21814 Parameters 21815 ---------- 21816 fname, kwargs : For a description of input parameters, see `genfromtxt`. 21817 21818 See Also 21819 -------- 21820 numpy.genfromtxt : generic function. 21821 21822 """ 21823 return None 21824 def ndim(a): 21825 """ 21826 Return the number of dimensions of an array. 21827 21828 Parameters 21829 ---------- 21830 a : array_like 21831 Input array. If it is not already an ndarray, a conversion is 21832 attempted. 21833 21834 Returns 21835 ------- 21836 number_of_dimensions : int 21837 The number of dimensions in `a`. Scalars are zero-dimensional. 21838 21839 See Also 21840 -------- 21841 ndarray.ndim : equivalent method 21842 shape : dimensions of array 21843 ndarray.shape : dimensions of array 21844 21845 Examples 21846 -------- 21847 >>> np.ndim([[1,2,3],[4,5,6]]) 21848 2 21849 >>> np.ndim(np.array([[1,2,3],[4,5,6]])) 21850 2 21851 >>> np.ndim(1) 21852 0 21853 21854 """ 21855 return int() 21856 class ndindex: 21857 __dict__ = dictproxy() 21858 __doc__ = str() 21859 __module__ = str() 21860 __weakref__ = getset_descriptor() 21861 def ndincr(self, _): 21862 """ 21863 Increment the multi-dimensional index by one. 21864 21865 This method is for backward compatibility only: do not use. 21866 """ 21867 return None 21868 class nditer: 21869 __doc__ = str() 21870 def copy(self, _): 21871 """copy() 21872 21873 Get a copy of the iterator in its current state. 21874 21875 Examples 21876 -------- 21877 >>> x = np.arange(10) 21878 >>> y = x + 1 21879 >>> it = np.nditer([x, y]) 21880 >>> it.next() 21881 (array(0), array(1)) 21882 >>> it2 = it.copy() 21883 >>> it2.next() 21884 (array(1), array(2))""" 21885 return None 21886 def debug_print(self, _): 21887 """debug_print() 21888 21889 Print the current state of the `nditer` instance and debug info to stdout.""" 21890 return None 21891 dtypes = getset_descriptor() 21892 def enable_external_loop(self, _): 21893 """enable_external_loop() 21894 21895 When the "external_loop" was not used during construction, but 21896 is desired, this modifies the iterator to behave as if the flag 21897 was specified.""" 21898 return None 21899 finished = getset_descriptor() 21900 has_delayed_bufalloc = getset_descriptor() 21901 has_index = getset_descriptor() 21902 has_multi_index = getset_descriptor() 21903 index = getset_descriptor() 21904 iterationneedsapi = getset_descriptor() 21905 iterindex = getset_descriptor() 21906 def iternext(self, _): 21907 """iternext() 21908 21909 Check whether iterations are left, and perform a single internal iteration 21910 without returning the result. Used in the C-style pattern do-while 21911 pattern. For an example, see `nditer`. 21912 21913 Returns 21914 ------- 21915 iternext : bool 21916 Whether or not there are iterations left.""" 21917 return None 21918 iterrange = getset_descriptor() 21919 itersize = getset_descriptor() 21920 itviews = getset_descriptor() 21921 multi_index = getset_descriptor() 21922 ndim = getset_descriptor() 21923 def next(self, _): 21924 """x.next() -> the next value, or raise StopIteration""" 21925 return None 21926 nop = getset_descriptor() 21927 operands = getset_descriptor() 21928 def remove_axis(self, i): 21929 """remove_axis(i) 21930 21931 Removes axis `i` from the iterator. Requires that the flag "multi_index" 21932 be enabled.""" 21933 return None 21934 def remove_multi_index(self, _): 21935 """remove_multi_index() 21936 21937 When the "multi_index" flag was specified, this removes it, allowing 21938 the internal iteration structure to be optimized further.""" 21939 return None 21940 def reset(self, _): 21941 """reset() 21942 21943 Reset the iterator to its initial state.""" 21944 return None 21945 shape = getset_descriptor() 21946 value = getset_descriptor() 21947 def negative(x, out=None): 21948 """negative(x[, out]) 21949 21950 Returns an array with the negative of each element of the original array. 21951 21952 Parameters 21953 ---------- 21954 x : array_like or scalar 21955 Input array. 21956 21957 Returns 21958 ------- 21959 y : ndarray or scalar 21960 Returned array or scalar: `y = -x`. 21961 21962 Examples 21963 -------- 21964 >>> np.negative([1.,-1.]) 21965 array([-1., 1.])""" 21966 return ndarray() if False else float() 21967 def nested_iters(): 21968 """None""" 21969 return None 21970 newaxis = None 21971 def newbuffer(size): 21972 """newbuffer(size) 21973 21974 Return a new uninitialized buffer object. 21975 21976 Parameters 21977 ---------- 21978 size : int 21979 Size in bytes of returned buffer object. 21980 21981 Returns 21982 ------- 21983 newbuffer : buffer object 21984 Returned, uninitialized buffer object of `size` bytes.""" 21985 return buffer() 21986 def nextafter(x1, x2, out): 21987 """nextafter(x1, x2[, out]) 21988 21989 Return the next representable floating-point value after x1 in the direction 21990 of x2 element-wise. 21991 21992 Parameters 21993 ---------- 21994 x1 : array_like 21995 Values to find the next representable value of. 21996 x2 : array_like 21997 The direction where to look for the next representable value of `x1`. 21998 out : ndarray, optional 21999 Array into which the output is placed. Its type is preserved and it 22000 must be of the right shape to hold the output. See `doc.ufuncs`. 22001 22002 Returns 22003 ------- 22004 out : array_like 22005 The next representable values of `x1` in the direction of `x2`. 22006 22007 Examples 22008 -------- 22009 >>> eps = np.finfo(np.float64).eps 22010 >>> np.nextafter(1, 2) == eps + 1 22011 True 22012 >>> np.nextafter([1, 2], [2, 1]) == [eps + 1, 2 - eps] 22013 array([ True, True], dtype=bool)""" 22014 return ndarray() 22015 def nonzero(a): 22016 """ 22017 Return the indices of the elements that are non-zero. 22018 22019 Returns a tuple of arrays, one for each dimension of `a`, containing 22020 the indices of the non-zero elements in that dimension. The 22021 corresponding non-zero values can be obtained with:: 22022 22023 a[nonzero(a)] 22024 22025 To group the indices by element, rather than dimension, use:: 22026 22027 transpose(nonzero(a)) 22028 22029 The result of this is always a 2-D array, with a row for 22030 each non-zero element. 22031 22032 Parameters 22033 ---------- 22034 a : array_like 22035 Input array. 22036 22037 Returns 22038 ------- 22039 tuple_of_arrays : tuple 22040 Indices of elements that are non-zero. 22041 22042 See Also 22043 -------- 22044 flatnonzero : 22045 Return indices that are non-zero in the flattened version of the input 22046 array. 22047 ndarray.nonzero : 22048 Equivalent ndarray method. 22049 count_nonzero : 22050 Counts the number of non-zero elements in the input array. 22051 22052 Examples 22053 -------- 22054 >>> x = np.eye(3) 22055 >>> x 22056 array([[ 1., 0., 0.], 22057 [ 0., 1., 0.], 22058 [ 0., 0., 1.]]) 22059 >>> np.nonzero(x) 22060 (array([0, 1, 2]), array([0, 1, 2])) 22061 22062 >>> x[np.nonzero(x)] 22063 array([ 1., 1., 1.]) 22064 >>> np.transpose(np.nonzero(x)) 22065 array([[0, 0], 22066 [1, 1], 22067 [2, 2]]) 22068 22069 A common use for ``nonzero`` is to find the indices of an array, where 22070 a condition is True. Given an array `a`, the condition `a` > 3 is a 22071 boolean array and since False is interpreted as 0, np.nonzero(a > 3) 22072 yields the indices of the `a` where the condition is true. 22073 22074 >>> a = np.array([[1,2,3],[4,5,6],[7,8,9]]) 22075 >>> a > 3 22076 array([[False, False, False], 22077 [ True, True, True], 22078 [ True, True, True]], dtype=bool) 22079 >>> np.nonzero(a > 3) 22080 (array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2])) 22081 22082 The ``nonzero`` method of the boolean array can also be called. 22083 22084 >>> (a > 3).nonzero() 22085 (array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2])) 22086 22087 """ 22088 return tuple() 22089 def not_equal(x1, x2, out=None): 22090 """not_equal(x1, x2[, out]) 22091 22092 Return (x1 != x2) element-wise. 22093 22094 Parameters 22095 ---------- 22096 x1, x2 : array_like 22097 Input arrays. 22098 out : ndarray, optional 22099 A placeholder the same shape as `x1` to store the result. 22100 See `doc.ufuncs` (Section "Output arguments") for more details. 22101 22102 Returns 22103 ------- 22104 not_equal : ndarray bool, scalar bool 22105 For each element in `x1, x2`, return True if `x1` is not equal 22106 to `x2` and False otherwise. 22107 22108 22109 See Also 22110 -------- 22111 equal, greater, greater_equal, less, less_equal 22112 22113 Examples 22114 -------- 22115 >>> np.not_equal([1.,2.], [1., 3.]) 22116 array([False, True], dtype=bool) 22117 >>> np.not_equal([1, 2], [[1, 3],[1, 4]]) 22118 array([[False, True], 22119 [False, True]], dtype=bool)""" 22120 return ndarray() 22121 def nper(rate, pmt, pv="end", fv=0, when="end"): 22122 """ 22123 Compute the number of periodic payments. 22124 22125 Parameters 22126 ---------- 22127 rate : array_like 22128 Rate of interest (per period) 22129 pmt : array_like 22130 Payment 22131 pv : array_like 22132 Present value 22133 fv : array_like, optional 22134 Future value 22135 when : {{'begin', 1}, {'end', 0}}, {string, int}, optional 22136 When payments are due ('begin' (1) or 'end' (0)) 22137 22138 Notes 22139 ----- 22140 The number of periods ``nper`` is computed by solving the equation:: 22141 22142 fv + pv*(1+rate)**nper + pmt*(1+rate*when)/rate*((1+rate)**nper-1) = 0 22143 22144 but if ``rate = 0`` then:: 22145 22146 fv + pv + pmt*nper = 0 22147 22148 Examples 22149 -------- 22150 If you only had $150/month to pay towards the loan, how long would it take 22151 to pay-off a loan of $8,000 at 7% annual interest? 22152 22153 >>> print round(np.nper(0.07/12, -150, 8000), 5) 22154 64.07335 22155 22156 So, over 64 months would be required to pay off the loan. 22157 22158 The same analysis could be done with several different interest rates 22159 and/or payments and/or total amounts to produce an entire table. 22160 22161 >>> np.nper(*(np.ogrid[0.07/12: 0.08/12: 0.01/12, 22162 ... -150 : -99 : 50 , 22163 ... 8000 : 9001 : 1000])) 22164 array([[[ 64.07334877, 74.06368256], 22165 [ 108.07548412, 127.99022654]], 22166 [[ 66.12443902, 76.87897353], 22167 [ 114.70165583, 137.90124779]]]) 22168 22169 """ 22170 return None 22171 def npv(rate, values): 22172 """ 22173 Returns the NPV (Net Present Value) of a cash flow series. 22174 22175 Parameters 22176 ---------- 22177 rate : scalar 22178 The discount rate. 22179 values : array_like, shape(M, ) 22180 The values of the time series of cash flows. The (fixed) time 22181 interval between cash flow "events" must be the same as that 22182 for which `rate` is given (i.e., if `rate` is per year, then 22183 precisely a year is understood to elapse between each cash flow 22184 event). By convention, investments or "deposits" are negative, 22185 income or "withdrawals" are positive; `values` must begin with 22186 the initial investment, thus `values[0]` will typically be 22187 negative. 22188 22189 Returns 22190 ------- 22191 out : float 22192 The NPV of the input cash flow series `values` at the discount `rate`. 22193 22194 Notes 22195 ----- 22196 Returns the result of: [G]_ 22197 22198 .. math :: \sum_{t=0}^{M-1}{\frac{values_t}{(1+rate)^{t}}} 22199 22200 References 22201 ---------- 22202 .. [G] L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed., 22203 Addison-Wesley, 2003, pg. 346. 22204 22205 Examples 22206 -------- 22207 >>> np.npv(0.281,[-100, 39, 59, 55, 20]) 22208 -0.0084785916384548798 22209 22210 (Compare with the Example given for numpy.lib.financial.irr) 22211 22212 """ 22213 return float() 22214 class number: 22215 T = getset_descriptor() 22216 __array_interface__ = getset_descriptor() 22217 __array_priority__ = getset_descriptor() 22218 __array_struct__ = getset_descriptor() 22219 __doc__ = None 22220 base = getset_descriptor() 22221 def conj(self, _): 22222 """None""" 22223 return None 22224 data = getset_descriptor() 22225 dtype = getset_descriptor() 22226 flags = getset_descriptor() 22227 flat = getset_descriptor() 22228 imag = getset_descriptor() 22229 itemsize = getset_descriptor() 22230 nbytes = getset_descriptor() 22231 ndim = getset_descriptor() 22232 def newbyteorder(self, new_order): 22233 """newbyteorder(new_order='S') 22234 22235 Return a new `dtype` with a different byte order. 22236 22237 Changes are also made in all fields and sub-arrays of the data type. 22238 22239 The `new_order` code can be any from the following: 22240 22241 * {'<', 'L'} - little endian 22242 * {'>', 'B'} - big endian 22243 * {'=', 'N'} - native order 22244 * 'S' - swap dtype from current to opposite endian 22245 * {'|', 'I'} - ignore (no change to byte order) 22246 22247 Parameters 22248 ---------- 22249 new_order : str, optional 22250 Byte order to force; a value from the byte order specifications 22251 above. The default value ('S') results in swapping the current 22252 byte order. The code does a case-insensitive check on the first 22253 letter of `new_order` for the alternatives above. For example, 22254 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 22255 22256 22257 Returns 22258 ------- 22259 new_dtype : dtype 22260 New `dtype` object with the given change to the byte order.""" 22261 return dtype() 22262 real = getset_descriptor() 22263 shape = getset_descriptor() 22264 size = getset_descriptor() 22265 strides = getset_descriptor() 22266 def obj2sctype(rep=None, default=None): 22267 """ 22268 Return the scalar dtype or NumPy equivalent of Python type of an object. 22269 22270 Parameters 22271 ---------- 22272 rep : any 22273 The object of which the type is returned. 22274 default : any, optional 22275 If given, this is returned for objects whose types can not be 22276 determined. If not given, None is returned for those objects. 22277 22278 Returns 22279 ------- 22280 dtype : dtype or Python type 22281 The data type of `rep`. 22282 22283 See Also 22284 -------- 22285 sctype2char, issctype, issubsctype, issubdtype, maximum_sctype 22286 22287 Examples 22288 -------- 22289 >>> np.obj2sctype(np.int32) 22290 <type 'numpy.int32'> 22291 >>> np.obj2sctype(np.array([1., 2.])) 22292 <type 'numpy.float64'> 22293 >>> np.obj2sctype(np.array([1.j])) 22294 <type 'numpy.complex128'> 22295 22296 >>> np.obj2sctype(dict) 22297 <type 'numpy.object_'> 22298 >>> np.obj2sctype('string') 22299 <type 'numpy.string_'> 22300 22301 >>> np.obj2sctype(1, default=list) 22302 <type 'list'> 22303 22304 """ 22305 return dtype() if False else Python() 22306 class object: 22307 __doc__ = str() 22308 class object_: 22309 T = getset_descriptor() 22310 __array_interface__ = getset_descriptor() 22311 __array_priority__ = getset_descriptor() 22312 __array_struct__ = getset_descriptor() 22313 __doc__ = str() 22314 base = getset_descriptor() 22315 def conj(self, _): 22316 """None""" 22317 return None 22318 data = getset_descriptor() 22319 dtype = getset_descriptor() 22320 flags = getset_descriptor() 22321 flat = getset_descriptor() 22322 imag = getset_descriptor() 22323 itemsize = getset_descriptor() 22324 nbytes = getset_descriptor() 22325 ndim = getset_descriptor() 22326 def newbyteorder(self, new_order): 22327 """newbyteorder(new_order='S') 22328 22329 Return a new `dtype` with a different byte order. 22330 22331 Changes are also made in all fields and sub-arrays of the data type. 22332 22333 The `new_order` code can be any from the following: 22334 22335 * {'<', 'L'} - little endian 22336 * {'>', 'B'} - big endian 22337 * {'=', 'N'} - native order 22338 * 'S' - swap dtype from current to opposite endian 22339 * {'|', 'I'} - ignore (no change to byte order) 22340 22341 Parameters 22342 ---------- 22343 new_order : str, optional 22344 Byte order to force; a value from the byte order specifications 22345 above. The default value ('S') results in swapping the current 22346 byte order. The code does a case-insensitive check on the first 22347 letter of `new_order` for the alternatives above. For example, 22348 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 22349 22350 22351 Returns 22352 ------- 22353 new_dtype : dtype 22354 New `dtype` object with the given change to the byte order.""" 22355 return dtype() 22356 real = getset_descriptor() 22357 shape = getset_descriptor() 22358 size = getset_descriptor() 22359 strides = getset_descriptor() 22360 class object_: 22361 T = getset_descriptor() 22362 __array_interface__ = getset_descriptor() 22363 __array_priority__ = getset_descriptor() 22364 __array_struct__ = getset_descriptor() 22365 __doc__ = str() 22366 base = getset_descriptor() 22367 def conj(self, _): 22368 """None""" 22369 return None 22370 data = getset_descriptor() 22371 dtype = getset_descriptor() 22372 flags = getset_descriptor() 22373 flat = getset_descriptor() 22374 imag = getset_descriptor() 22375 itemsize = getset_descriptor() 22376 nbytes = getset_descriptor() 22377 ndim = getset_descriptor() 22378 def newbyteorder(self, new_order): 22379 """newbyteorder(new_order='S') 22380 22381 Return a new `dtype` with a different byte order. 22382 22383 Changes are also made in all fields and sub-arrays of the data type. 22384 22385 The `new_order` code can be any from the following: 22386 22387 * {'<', 'L'} - little endian 22388 * {'>', 'B'} - big endian 22389 * {'=', 'N'} - native order 22390 * 'S' - swap dtype from current to opposite endian 22391 * {'|', 'I'} - ignore (no change to byte order) 22392 22393 Parameters 22394 ---------- 22395 new_order : str, optional 22396 Byte order to force; a value from the byte order specifications 22397 above. The default value ('S') results in swapping the current 22398 byte order. The code does a case-insensitive check on the first 22399 letter of `new_order` for the alternatives above. For example, 22400 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 22401 22402 22403 Returns 22404 ------- 22405 new_dtype : dtype 22406 New `dtype` object with the given change to the byte order.""" 22407 return dtype() 22408 real = getset_descriptor() 22409 shape = getset_descriptor() 22410 size = getset_descriptor() 22411 strides = getset_descriptor() 22412 ogrid = nd_grid() 22413 def ones(shape="C", dtype=None, order="C"): 22414 """ 22415 Return a new array of given shape and type, filled with ones. 22416 22417 Parameters 22418 ---------- 22419 shape : int or sequence of ints 22420 Shape of the new array, e.g., ``(2, 3)`` or ``2``. 22421 dtype : data-type, optional 22422 The desired data-type for the array, e.g., `numpy.int8`. Default is 22423 `numpy.float64`. 22424 order : {'C', 'F'}, optional 22425 Whether to store multidimensional data in C- or Fortran-contiguous 22426 (row- or column-wise) order in memory. 22427 22428 Returns 22429 ------- 22430 out : ndarray 22431 Array of ones with the given shape, dtype, and order. 22432 22433 See Also 22434 -------- 22435 zeros, ones_like 22436 22437 Examples 22438 -------- 22439 >>> np.ones(5) 22440 array([ 1., 1., 1., 1., 1.]) 22441 22442 >>> np.ones((5,), dtype=np.int) 22443 array([1, 1, 1, 1, 1]) 22444 22445 >>> np.ones((2, 1)) 22446 array([[ 1.], 22447 [ 1.]]) 22448 22449 >>> s = (2,2) 22450 >>> np.ones(s) 22451 array([[ 1., 1.], 22452 [ 1., 1.]]) 22453 22454 """ 22455 return ndarray() 22456 def ones_like(a=True, dtype=None, order="K", subok=True): 22457 """ 22458 Return an array of ones with the same shape and type as a given array. 22459 22460 Parameters 22461 ---------- 22462 a : array_like 22463 The shape and data-type of `a` define these same attributes of 22464 the returned array. 22465 dtype : data-type, optional 22466 .. versionadded:: 1.6.0 22467 Overrides the data type of the result. 22468 order : {'C', 'F', 'A', or 'K'}, optional 22469 .. versionadded:: 1.6.0 22470 Overrides the memory layout of the result. 'C' means C-order, 22471 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, 22472 'C' otherwise. 'K' means match the layout of `a` as closely 22473 as possible. 22474 subok : bool, optional. 22475 If True, then the newly created array will use the sub-class 22476 type of 'a', otherwise it will be a base-class array. Defaults 22477 to True. 22478 22479 Returns 22480 ------- 22481 out : ndarray 22482 Array of ones with the same shape and type as `a`. 22483 22484 See Also 22485 -------- 22486 zeros_like : Return an array of zeros with shape and type of input. 22487 empty_like : Return an empty array with shape and type of input. 22488 zeros : Return a new array setting values to zero. 22489 ones : Return a new array setting values to one. 22490 empty : Return a new uninitialized array. 22491 22492 Examples 22493 -------- 22494 >>> x = np.arange(6) 22495 >>> x = x.reshape((2, 3)) 22496 >>> x 22497 array([[0, 1, 2], 22498 [3, 4, 5]]) 22499 >>> np.ones_like(x) 22500 array([[1, 1, 1], 22501 [1, 1, 1]]) 22502 22503 >>> y = np.arange(3, dtype=np.float) 22504 >>> y 22505 array([ 0., 1., 2.]) 22506 >>> np.ones_like(y) 22507 array([ 1., 1., 1.]) 22508 22509 """ 22510 return ndarray() 22511 def outer(a, b): 22512 """ 22513 Compute the outer product of two vectors. 22514 22515 Given two vectors, ``a = [a0, a1, ..., aM]`` and 22516 ``b = [b0, b1, ..., bN]``, 22517 the outer product [1]_ is:: 22518 22519 [[a0*b0 a0*b1 ... a0*bN ] 22520 [a1*b0 . 22521 [ ... . 22522 [aM*b0 aM*bN ]] 22523 22524 Parameters 22525 ---------- 22526 a : (M,) array_like 22527 First input vector. Input is flattened if 22528 not already 1-dimensional. 22529 b : (N,) array_like 22530 Second input vector. Input is flattened if 22531 not already 1-dimensional. 22532 22533 Returns 22534 ------- 22535 out : (M, N) ndarray 22536 ``out[i, j] = a[i] * b[j]`` 22537 22538 See also 22539 -------- 22540 inner, einsum 22541 22542 References 22543 ---------- 22544 .. [1] : G. H. Golub and C. F. van Loan, *Matrix Computations*, 3rd 22545 ed., Baltimore, MD, Johns Hopkins University Press, 1996, 22546 pg. 8. 22547 22548 Examples 22549 -------- 22550 Make a (*very* coarse) grid for computing a Mandelbrot set: 22551 22552 >>> rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5)) 22553 >>> rl 22554 array([[-2., -1., 0., 1., 2.], 22555 [-2., -1., 0., 1., 2.], 22556 [-2., -1., 0., 1., 2.], 22557 [-2., -1., 0., 1., 2.], 22558 [-2., -1., 0., 1., 2.]]) 22559 >>> im = np.outer(1j*np.linspace(2, -2, 5), np.ones((5,))) 22560 >>> im 22561 array([[ 0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j], 22562 [ 0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j], 22563 [ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], 22564 [ 0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j], 22565 [ 0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j]]) 22566 >>> grid = rl + im 22567 >>> grid 22568 array([[-2.+2.j, -1.+2.j, 0.+2.j, 1.+2.j, 2.+2.j], 22569 [-2.+1.j, -1.+1.j, 0.+1.j, 1.+1.j, 2.+1.j], 22570 [-2.+0.j, -1.+0.j, 0.+0.j, 1.+0.j, 2.+0.j], 22571 [-2.-1.j, -1.-1.j, 0.-1.j, 1.-1.j, 2.-1.j], 22572 [-2.-2.j, -1.-2.j, 0.-2.j, 1.-2.j, 2.-2.j]]) 22573 22574 An example using a "vector" of letters: 22575 22576 >>> x = np.array(['a', 'b', 'c'], dtype=object) 22577 >>> np.outer(x, [1, 2, 3]) 22578 array([[a, aa, aaa], 22579 [b, bb, bbb], 22580 [c, cc, ccc]], dtype=object) 22581 22582 """ 22583 return M() 22584 def packbits(myarray, axis): 22585 """packbits(myarray, axis=None) 22586 22587 Packs the elements of a binary-valued array into bits in a uint8 array. 22588 22589 The result is padded to full bytes by inserting zero bits at the end. 22590 22591 Parameters 22592 ---------- 22593 myarray : array_like 22594 An integer type array whose elements should be packed to bits. 22595 axis : int, optional 22596 The dimension over which bit-packing is done. 22597 ``None`` implies packing the flattened array. 22598 22599 Returns 22600 ------- 22601 packed : ndarray 22602 Array of type uint8 whose elements represent bits corresponding to the 22603 logical (0 or nonzero) value of the input elements. The shape of 22604 `packed` has the same number of dimensions as the input (unless `axis` 22605 is None, in which case the output is 1-D). 22606 22607 See Also 22608 -------- 22609 unpackbits: Unpacks elements of a uint8 array into a binary-valued output 22610 array. 22611 22612 Examples 22613 -------- 22614 >>> a = np.array([[[1,0,1], 22615 ... [0,1,0]], 22616 ... [[1,1,0], 22617 ... [0,0,1]]]) 22618 >>> b = np.packbits(a, axis=-1) 22619 >>> b 22620 array([[[160],[64]],[[192],[32]]], dtype=uint8) 22621 22622 Note that in binary 160 = 1010 0000, 64 = 0100 0000, 192 = 1100 0000, 22623 and 32 = 0010 0000.""" 22624 return ndarray() 22625 def pad(array, pad_width=None, mode=None): 22626 """ 22627 Pads an array. 22628 22629 Parameters 22630 ---------- 22631 array : array_like of rank N 22632 Input array 22633 pad_width : {sequence, int} 22634 Number of values padded to the edges of each axis. 22635 ((before_1, after_1), ... (before_N, after_N)) unique pad widths 22636 for each axis. 22637 ((before, after),) yields same before and after pad for each axis. 22638 (pad,) or int is a shortcut for before = after = pad width for all 22639 axes. 22640 mode : {str, function} 22641 One of the following string values or a user supplied function. 22642 22643 'constant' Pads with a constant value. 22644 'edge' Pads with the edge values of array. 22645 'linear_ramp' Pads with the linear ramp between end_value and the 22646 array edge value. 22647 'maximum' Pads with the maximum value of all or part of the 22648 vector along each axis. 22649 'mean' Pads with the mean value of all or part of the 22650 vector along each axis. 22651 'median' Pads with the median value of all or part of the 22652 vector along each axis. 22653 'minimum' Pads with the minimum value of all or part of the 22654 vector along each axis. 22655 'reflect' Pads with the reflection of the vector mirrored on 22656 the first and last values of the vector along each 22657 axis. 22658 'symmetric' Pads with the reflection of the vector mirrored 22659 along the edge of the array. 22660 'wrap' Pads with the wrap of the vector along the axis. 22661 The first values are used to pad the end and the 22662 end values are used to pad the beginning. 22663 <function> Padding function, see Notes. 22664 stat_length : {sequence, int}, optional 22665 Used in 'maximum', 'mean', 'median', and 'minimum'. Number of 22666 values at edge of each axis used to calculate the statistic value. 22667 22668 ((before_1, after_1), ... (before_N, after_N)) unique statistic 22669 lengths for each axis. 22670 22671 ((before, after),) yields same before and after statistic lengths 22672 for each axis. 22673 22674 (stat_length,) or int is a shortcut for before = after = statistic 22675 length for all axes. 22676 22677 Default is ``None``, to use the entire axis. 22678 constant_values : {sequence, int}, optional 22679 Used in 'constant'. The values to set the padded values for each 22680 axis. 22681 22682 ((before_1, after_1), ... (before_N, after_N)) unique pad constants 22683 for each axis. 22684 22685 ((before, after),) yields same before and after constants for each 22686 axis. 22687 22688 (constant,) or int is a shortcut for before = after = constant for 22689 all axes. 22690 22691 Default is 0. 22692 end_values : {sequence, int}, optional 22693 Used in 'linear_ramp'. The values used for the ending value of the 22694 linear_ramp and that will form the edge of the padded array. 22695 22696 ((before_1, after_1), ... (before_N, after_N)) unique end values 22697 for each axis. 22698 22699 ((before, after),) yields same before and after end values for each 22700 axis. 22701 22702 (constant,) or int is a shortcut for before = after = end value for 22703 all axes. 22704 22705 Default is 0. 22706 reflect_type : str {'even', 'odd'}, optional 22707 Used in 'reflect', and 'symmetric'. The 'even' style is the 22708 default with an unaltered reflection around the edge value. For 22709 the 'odd' style, the extented part of the array is created by 22710 subtracting the reflected values from two times the edge value. 22711 22712 Returns 22713 ------- 22714 pad : ndarray 22715 Padded array of rank equal to `array` with shape increased 22716 according to `pad_width`. 22717 22718 Notes 22719 ----- 22720 .. versionadded:: 1.7.0 22721 22722 For an array with rank greater than 1, some of the padding of later 22723 axes is calculated from padding of previous axes. This is easiest to 22724 think about with a rank 2 array where the corners of the padded array 22725 are calculated by using padded values from the first axis. 22726 22727 The padding function, if used, should return a rank 1 array equal in 22728 length to the vector argument with padded values replaced. It has the 22729 following signature: 22730 22731 padding_func(vector, iaxis_pad_width, iaxis, **kwargs) 22732 22733 where 22734 22735 vector : ndarray 22736 A rank 1 array already padded with zeros. Padded values are 22737 vector[:pad_tuple[0]] and vector[-pad_tuple[1]:]. 22738 iaxis_pad_width : tuple 22739 A 2-tuple of ints, iaxis_pad_width[0] represents the number of 22740 values padded at the beginning of vector where 22741 iaxis_pad_width[1] represents the number of values padded at 22742 the end of vector. 22743 iaxis : int 22744 The axis currently being calculated. 22745 kwargs : misc 22746 Any keyword arguments the function requires. 22747 22748 Examples 22749 -------- 22750 >>> a = [1, 2, 3, 4, 5] 22751 >>> np.lib.pad(a, (2,3), 'constant', constant_values=(4,6)) 22752 array([4, 4, 1, 2, 3, 4, 5, 6, 6, 6]) 22753 22754 >>> np.lib.pad(a, (2,3), 'edge') 22755 array([1, 1, 1, 2, 3, 4, 5, 5, 5, 5]) 22756 22757 >>> np.lib.pad(a, (2,3), 'linear_ramp', end_values=(5,-4)) 22758 array([ 5, 3, 1, 2, 3, 4, 5, 2, -1, -4]) 22759 22760 >>> np.lib.pad(a, (2,), 'maximum') 22761 array([5, 5, 1, 2, 3, 4, 5, 5, 5]) 22762 22763 >>> np.lib.pad(a, (2,), 'mean') 22764 array([3, 3, 1, 2, 3, 4, 5, 3, 3]) 22765 22766 >>> np.lib.pad(a, (2,), 'median') 22767 array([3, 3, 1, 2, 3, 4, 5, 3, 3]) 22768 22769 >>> a = [[1,2], [3,4]] 22770 >>> np.lib.pad(a, ((3, 2), (2, 3)), 'minimum') 22771 array([[1, 1, 1, 2, 1, 1, 1], 22772 [1, 1, 1, 2, 1, 1, 1], 22773 [1, 1, 1, 2, 1, 1, 1], 22774 [1, 1, 1, 2, 1, 1, 1], 22775 [3, 3, 3, 4, 3, 3, 3], 22776 [1, 1, 1, 2, 1, 1, 1], 22777 [1, 1, 1, 2, 1, 1, 1]]) 22778 22779 >>> a = [1, 2, 3, 4, 5] 22780 >>> np.lib.pad(a, (2,3), 'reflect') 22781 array([3, 2, 1, 2, 3, 4, 5, 4, 3, 2]) 22782 22783 >>> np.lib.pad(a, (2,3), 'reflect', reflect_type='odd') 22784 array([-1, 0, 1, 2, 3, 4, 5, 6, 7, 8]) 22785 22786 >>> np.lib.pad(a, (2,3), 'symmetric') 22787 array([2, 1, 1, 2, 3, 4, 5, 5, 4, 3]) 22788 22789 >>> np.lib.pad(a, (2,3), 'symmetric', reflect_type='odd') 22790 array([0, 1, 1, 2, 3, 4, 5, 5, 6, 7]) 22791 22792 >>> np.lib.pad(a, (2,3), 'wrap') 22793 array([4, 5, 1, 2, 3, 4, 5, 1, 2, 3]) 22794 22795 >>> def padwithtens(vector, pad_width, iaxis, kwargs): 22796 ... vector[:pad_width[0]] = 10 22797 ... vector[-pad_width[1]:] = 10 22798 ... return vector 22799 22800 >>> a = np.arange(6) 22801 >>> a = a.reshape((2,3)) 22802 22803 >>> np.lib.pad(a, 2, padwithtens) 22804 array([[10, 10, 10, 10, 10, 10, 10], 22805 [10, 10, 10, 10, 10, 10, 10], 22806 [10, 10, 0, 1, 2, 10, 10], 22807 [10, 10, 3, 4, 5, 10, 10], 22808 [10, 10, 10, 10, 10, 10, 10], 22809 [10, 10, 10, 10, 10, 10, 10]]) 22810 22811 """ 22812 return ndarray() 22813 def partition(a, kth=None, axis=-1, kind="introselect", order=None): 22814 """ 22815 Return a partitioned copy of an array. 22816 22817 Creates a copy of the array with its elements rearranged in such a way that 22818 the value of the element in kth position is in the position it would be in 22819 a sorted array. All elements smaller than the kth element are moved before 22820 this element and all equal or greater are moved behind it. The ordering of 22821 the elements in the two partitions is undefined. 22822 22823 .. versionadded:: 1.8.0 22824 22825 Parameters 22826 ---------- 22827 a : array_like 22828 Array to be sorted. 22829 kth : int or sequence of ints 22830 Element index to partition by. The kth value of the element will be in 22831 its final sorted position and all smaller elements will be moved before 22832 it and all equal or greater elements behind it. 22833 The order all elements in the partitions is undefined. 22834 If provided with a sequence of kth it will partition all elements 22835 indexed by kth of them into their sorted position at once. 22836 axis : int or None, optional 22837 Axis along which to sort. If None, the array is flattened before 22838 sorting. The default is -1, which sorts along the last axis. 22839 kind : {'introselect'}, optional 22840 Selection algorithm. Default is 'introselect'. 22841 order : list, optional 22842 When `a` is a structured array, this argument specifies which fields 22843 to compare first, second, and so on. This list does not need to 22844 include all of the fields. 22845 22846 Returns 22847 ------- 22848 partitioned_array : ndarray 22849 Array of the same type and shape as `a`. 22850 22851 See Also 22852 -------- 22853 ndarray.partition : Method to sort an array in-place. 22854 argpartition : Indirect partition. 22855 sort : Full sorting 22856 22857 Notes 22858 ----- 22859 The various selection algorithms are characterized by their average speed, 22860 worst case performance, work space size, and whether they are stable. A 22861 stable sort keeps items with the same key in the same relative order. The 22862 three available algorithms have the following properties: 22863 22864 ================= ======= ============= ============ ======= 22865 kind speed worst case work space stable 22866 ================= ======= ============= ============ ======= 22867 'introselect' 1 O(n) 0 no 22868 ================= ======= ============= ============ ======= 22869 22870 All the partition algorithms make temporary copies of the data when 22871 partitioning along any but the last axis. Consequently, partitioning 22872 along the last axis is faster and uses less space than partitioning 22873 along any other axis. 22874 22875 The sort order for complex numbers is lexicographic. If both the real 22876 and imaginary parts are non-nan then the order is determined by the 22877 real parts except when they are equal, in which case the order is 22878 determined by the imaginary parts. 22879 22880 Examples 22881 -------- 22882 >>> a = np.array([3, 4, 2, 1]) 22883 >>> np.partition(a, 3) 22884 array([2, 1, 3, 4]) 22885 22886 >>> np.partition(a, (1, 3)) 22887 array([1, 2, 3, 4]) 22888 22889 """ 22890 return ndarray() 22891 def percentile(a, q=False, axis=None, out=None, overwrite_input=False): 22892 """ 22893 Compute the qth percentile of the data along the specified axis. 22894 22895 Returns the qth percentile of the array elements. 22896 22897 Parameters 22898 ---------- 22899 a : array_like 22900 Input array or object that can be converted to an array. 22901 q : float in range of [0,100] (or sequence of floats) 22902 Percentile to compute which must be between 0 and 100 inclusive. 22903 axis : int, optional 22904 Axis along which the percentiles are computed. The default (None) 22905 is to compute the median along a flattened version of the array. 22906 out : ndarray, optional 22907 Alternative output array in which to place the result. It must 22908 have the same shape and buffer length as the expected output, 22909 but the type (of the output) will be cast if necessary. 22910 overwrite_input : bool, optional 22911 If True, then allow use of memory of input array `a` for 22912 calculations. The input array will be modified by the call to 22913 median. This will save memory when you do not need to preserve 22914 the contents of the input array. Treat the input as undefined, 22915 but it will probably be fully or partially sorted. 22916 Default is False. Note that, if `overwrite_input` is True and the 22917 input is not already an array, an error will be raised. 22918 22919 Returns 22920 ------- 22921 pcntile : ndarray 22922 A new array holding the result (unless `out` is specified, in 22923 which case that array is returned instead). If the input contains 22924 integers, or floats of smaller precision than 64, then the output 22925 data-type is float64. Otherwise, the output data-type is the same 22926 as that of the input. 22927 22928 See Also 22929 -------- 22930 mean, median 22931 22932 Notes 22933 ----- 22934 Given a vector V of length N, the qth percentile of V is the qth ranked 22935 value in a sorted copy of V. A weighted average of the two nearest 22936 neighbors is used if the normalized ranking does not match q exactly. 22937 The same as the median if ``q=50``, the same as the minimum if ``q=0`` 22938 and the same as the maximum if ``q=100``. 22939 22940 Examples 22941 -------- 22942 >>> a = np.array([[10, 7, 4], [3, 2, 1]]) 22943 >>> a 22944 array([[10, 7, 4], 22945 [ 3, 2, 1]]) 22946 >>> np.percentile(a, 50) 22947 3.5 22948 >>> np.percentile(a, 50, axis=0) 22949 array([ 6.5, 4.5, 2.5]) 22950 >>> np.percentile(a, 50, axis=1) 22951 array([ 7., 2.]) 22952 22953 >>> m = np.percentile(a, 50, axis=0) 22954 >>> out = np.zeros_like(m) 22955 >>> np.percentile(a, 50, axis=0, out=m) 22956 array([ 6.5, 4.5, 2.5]) 22957 >>> m 22958 array([ 6.5, 4.5, 2.5]) 22959 22960 >>> b = a.copy() 22961 >>> np.percentile(b, 50, axis=1, overwrite_input=True) 22962 array([ 7., 2.]) 22963 >>> assert not np.all(a==b) 22964 >>> b = a.copy() 22965 >>> np.percentile(b, 50, axis=None, overwrite_input=True) 22966 3.5 22967 22968 """ 22969 return ndarray() 22970 pi = float() 22971 def piecewise(x, condlist, funclist, args, kw): 22972 """ 22973 Evaluate a piecewise-defined function. 22974 22975 Given a set of conditions and corresponding functions, evaluate each 22976 function on the input data wherever its condition is true. 22977 22978 Parameters 22979 ---------- 22980 x : ndarray 22981 The input domain. 22982 condlist : list of bool arrays 22983 Each boolean array corresponds to a function in `funclist`. Wherever 22984 `condlist[i]` is True, `funclist[i](x)` is used as the output value. 22985 22986 Each boolean array in `condlist` selects a piece of `x`, 22987 and should therefore be of the same shape as `x`. 22988 22989 The length of `condlist` must correspond to that of `funclist`. 22990 If one extra function is given, i.e. if 22991 ``len(funclist) - len(condlist) == 1``, then that extra function 22992 is the default value, used wherever all conditions are false. 22993 funclist : list of callables, f(x,*args,**kw), or scalars 22994 Each function is evaluated over `x` wherever its corresponding 22995 condition is True. It should take an array as input and give an array 22996 or a scalar value as output. If, instead of a callable, 22997 a scalar is provided then a constant function (``lambda x: scalar``) is 22998 assumed. 22999 args : tuple, optional 23000 Any further arguments given to `piecewise` are passed to the functions 23001 upon execution, i.e., if called ``piecewise(..., ..., 1, 'a')``, then 23002 each function is called as ``f(x, 1, 'a')``. 23003 kw : dict, optional 23004 Keyword arguments used in calling `piecewise` are passed to the 23005 functions upon execution, i.e., if called 23006 ``piecewise(..., ..., lambda=1)``, then each function is called as 23007 ``f(x, lambda=1)``. 23008 23009 Returns 23010 ------- 23011 out : ndarray 23012 The output is the same shape and type as x and is found by 23013 calling the functions in `funclist` on the appropriate portions of `x`, 23014 as defined by the boolean arrays in `condlist`. Portions not covered 23015 by any condition have undefined values. 23016 23017 23018 See Also 23019 -------- 23020 choose, select, where 23021 23022 Notes 23023 ----- 23024 This is similar to choose or select, except that functions are 23025 evaluated on elements of `x` that satisfy the corresponding condition from 23026 `condlist`. 23027 23028 The result is:: 23029 23030 |-- 23031 |funclist[0](x[condlist[0]]) 23032 out = |funclist[1](x[condlist[1]]) 23033 |... 23034 |funclist[n2](x[condlist[n2]]) 23035 |-- 23036 23037 Examples 23038 -------- 23039 Define the sigma function, which is -1 for ``x < 0`` and +1 for ``x >= 0``. 23040 23041 >>> x = np.linspace(-2.5, 2.5, 6) 23042 >>> np.piecewise(x, [x < 0, x >= 0], [-1, 1]) 23043 array([-1., -1., -1., 1., 1., 1.]) 23044 23045 Define the absolute value, which is ``-x`` for ``x <0`` and ``x`` for 23046 ``x >= 0``. 23047 23048 >>> np.piecewise(x, [x < 0, x >= 0], [lambda x: -x, lambda x: x]) 23049 array([ 2.5, 1.5, 0.5, 0.5, 1.5, 2.5]) 23050 23051 """ 23052 return ndarray() 23053 def pkgload(): 23054 """Load one or more packages into parent package top-level namespace. 23055 23056 This function is intended to shorten the need to import many 23057 subpackages, say of scipy, constantly with statements such as 23058 23059 import scipy.linalg, scipy.fftpack, scipy.etc... 23060 23061 Instead, you can say: 23062 23063 import scipy 23064 scipy.pkgload('linalg','fftpack',...) 23065 23066 or 23067 23068 scipy.pkgload() 23069 23070 to load all of them in one call. 23071 23072 If a name which doesn't exist in scipy's namespace is 23073 given, a warning is shown. 23074 23075 Parameters 23076 ---------- 23077 *packages : arg-tuple 23078 the names (one or more strings) of all the modules one 23079 wishes to load into the top-level namespace. 23080 verbose= : integer 23081 verbosity level [default: -1]. 23082 verbose=-1 will suspend also warnings. 23083 force= : bool 23084 when True, force reloading loaded packages [default: False]. 23085 postpone= : bool 23086 when True, don't load packages [default: False] 23087 23088 """ 23089 return None 23090 def place(arr, mask, vals): 23091 """ 23092 Change elements of an array based on conditional and input values. 23093 23094 Similar to ``np.copyto(arr, vals, where=mask)``, the difference is that 23095 `place` uses the first N elements of `vals`, where N is the number of 23096 True values in `mask`, while `copyto` uses the elements where `mask` 23097 is True. 23098 23099 Note that `extract` does the exact opposite of `place`. 23100 23101 Parameters 23102 ---------- 23103 arr : array_like 23104 Array to put data into. 23105 mask : array_like 23106 Boolean mask array. Must have the same size as `a`. 23107 vals : 1-D sequence 23108 Values to put into `a`. Only the first N elements are used, where 23109 N is the number of True values in `mask`. If `vals` is smaller 23110 than N it will be repeated. 23111 23112 See Also 23113 -------- 23114 copyto, put, take, extract 23115 23116 Examples 23117 -------- 23118 >>> arr = np.arange(6).reshape(2, 3) 23119 >>> np.place(arr, arr>2, [44, 55]) 23120 >>> arr 23121 array([[ 0, 1, 2], 23122 [44, 55, 44]]) 23123 23124 """ 23125 return None 23126 def pmt(rate, nper, pv="end", fv=0, when="end"): 23127 """ 23128 Compute the payment against loan principal plus interest. 23129 23130 Given: 23131 * a present value, `pv` (e.g., an amount borrowed) 23132 * a future value, `fv` (e.g., 0) 23133 * an interest `rate` compounded once per period, of which 23134 there are 23135 * `nper` total 23136 * and (optional) specification of whether payment is made 23137 at the beginning (`when` = {'begin', 1}) or the end 23138 (`when` = {'end', 0}) of each period 23139 23140 Return: 23141 the (fixed) periodic payment. 23142 23143 Parameters 23144 ---------- 23145 rate : array_like 23146 Rate of interest (per period) 23147 nper : array_like 23148 Number of compounding periods 23149 pv : array_like 23150 Present value 23151 fv : array_like (optional) 23152 Future value (default = 0) 23153 when : {{'begin', 1}, {'end', 0}}, {string, int} 23154 When payments are due ('begin' (1) or 'end' (0)) 23155 23156 Returns 23157 ------- 23158 out : ndarray 23159 Payment against loan plus interest. If all input is scalar, returns a 23160 scalar float. If any input is array_like, returns payment for each 23161 input element. If multiple inputs are array_like, they all must have 23162 the same shape. 23163 23164 Notes 23165 ----- 23166 The payment is computed by solving the equation:: 23167 23168 fv + 23169 pv*(1 + rate)**nper + 23170 pmt*(1 + rate*when)/rate*((1 + rate)**nper - 1) == 0 23171 23172 or, when ``rate == 0``:: 23173 23174 fv + pv + pmt * nper == 0 23175 23176 for ``pmt``. 23177 23178 Note that computing a monthly mortgage payment is only 23179 one use for this function. For example, pmt returns the 23180 periodic deposit one must make to achieve a specified 23181 future balance given an initial deposit, a fixed, 23182 periodically compounded interest rate, and the total 23183 number of periods. 23184 23185 References 23186 ---------- 23187 .. [WRW] Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May). 23188 Open Document Format for Office Applications (OpenDocument)v1.2, 23189 Part 2: Recalculated Formula (OpenFormula) Format - Annotated Version, 23190 Pre-Draft 12. Organization for the Advancement of Structured Information 23191 Standards (OASIS). Billerica, MA, USA. [ODT Document]. 23192 Available: 23193 http://www.oasis-open.org/committees/documents.php 23194 ?wg_abbrev=office-formulaOpenDocument-formula-20090508.odt 23195 23196 Examples 23197 -------- 23198 What is the monthly payment needed to pay off a $200,000 loan in 15 23199 years at an annual interest rate of 7.5%? 23200 23201 >>> np.pmt(0.075/12, 12*15, 200000) 23202 -1854.0247200054619 23203 23204 In order to pay-off (i.e., have a future-value of 0) the $200,000 obtained 23205 today, a monthly payment of $1,854.02 would be required. Note that this 23206 example illustrates usage of `fv` having a default value of 0. 23207 23208 """ 23209 return ndarray() 23210 def poly(seq_of_zeros): 23211 """ 23212 Find the coefficients of a polynomial with the given sequence of roots. 23213 23214 Returns the coefficients of the polynomial whose leading coefficient 23215 is one for the given sequence of zeros (multiple roots must be included 23216 in the sequence as many times as their multiplicity; see Examples). 23217 A square matrix (or array, which will be treated as a matrix) can also 23218 be given, in which case the coefficients of the characteristic polynomial 23219 of the matrix are returned. 23220 23221 Parameters 23222 ---------- 23223 seq_of_zeros : array_like, shape (N,) or (N, N) 23224 A sequence of polynomial roots, or a square array or matrix object. 23225 23226 Returns 23227 ------- 23228 c : ndarray 23229 1D array of polynomial coefficients from highest to lowest degree: 23230 23231 ``c[0] * x**(N) + c[1] * x**(N-1) + ... + c[N-1] * x + c[N]`` 23232 where c[0] always equals 1. 23233 23234 Raises 23235 ------ 23236 ValueError 23237 If input is the wrong shape (the input must be a 1-D or square 23238 2-D array). 23239 23240 See Also 23241 -------- 23242 polyval : Evaluate a polynomial at a point. 23243 roots : Return the roots of a polynomial. 23244 polyfit : Least squares polynomial fit. 23245 poly1d : A one-dimensional polynomial class. 23246 23247 Notes 23248 ----- 23249 Specifying the roots of a polynomial still leaves one degree of 23250 freedom, typically represented by an undetermined leading 23251 coefficient. [1]_ In the case of this function, that coefficient - 23252 the first one in the returned array - is always taken as one. (If 23253 for some reason you have one other point, the only automatic way 23254 presently to leverage that information is to use ``polyfit``.) 23255 23256 The characteristic polynomial, :math:`p_a(t)`, of an `n`-by-`n` 23257 matrix **A** is given by 23258 23259 :math:`p_a(t) = \mathrm{det}(t\, \mathbf{I} - \mathbf{A})`, 23260 23261 where **I** is the `n`-by-`n` identity matrix. [2]_ 23262 23263 References 23264 ---------- 23265 .. [1] M. Sullivan and M. Sullivan, III, "Algebra and Trignometry, 23266 Enhanced With Graphing Utilities," Prentice-Hall, pg. 318, 1996. 23267 23268 .. [2] G. Strang, "Linear Algebra and Its Applications, 2nd Edition," 23269 Academic Press, pg. 182, 1980. 23270 23271 Examples 23272 -------- 23273 Given a sequence of a polynomial's zeros: 23274 23275 >>> np.poly((0, 0, 0)) # Multiple root example 23276 array([1, 0, 0, 0]) 23277 23278 The line above represents z**3 + 0*z**2 + 0*z + 0. 23279 23280 >>> np.poly((-1./2, 0, 1./2)) 23281 array([ 1. , 0. , -0.25, 0. ]) 23282 23283 The line above represents z**3 - z/4 23284 23285 >>> np.poly((np.random.random(1.)[0], 0, np.random.random(1.)[0])) 23286 array([ 1. , -0.77086955, 0.08618131, 0. ]) #random 23287 23288 Given a square array object: 23289 23290 >>> P = np.array([[0, 1./3], [-1./2, 0]]) 23291 >>> np.poly(P) 23292 array([ 1. , 0. , 0.16666667]) 23293 23294 Or a square matrix object: 23295 23296 >>> np.poly(np.matrix(P)) 23297 array([ 1. , 0. , 0.16666667]) 23298 23299 Note how in all cases the leading coefficient is always 1. 23300 23301 """ 23302 return ndarray() 23303 class poly1d: 23304 __dict__ = dictproxy() 23305 __doc__ = str() 23306 __hash__ = None 23307 __module__ = str() 23308 __weakref__ = getset_descriptor() 23309 coeffs = None 23310 def deriv(self=1, m=1): 23311 """ 23312 Return a derivative of this polynomial. 23313 23314 Refer to `polyder` for full documentation. 23315 23316 See Also 23317 -------- 23318 polyder : equivalent function 23319 23320 """ 23321 return None 23322 def integ(self=0, m=1, k=0): 23323 """ 23324 Return an antiderivative (indefinite integral) of this polynomial. 23325 23326 Refer to `polyint` for full documentation. 23327 23328 See Also 23329 -------- 23330 polyint : equivalent function 23331 23332 """ 23333 return None 23334 order = None 23335 variable = None 23336 def polyadd(a1a2): 23337 """ 23338 Find the sum of two polynomials. 23339 23340 Returns the polynomial resulting from the sum of two input polynomials. 23341 Each input must be either a poly1d object or a 1D sequence of polynomial 23342 coefficients, from highest to lowest degree. 23343 23344 Parameters 23345 ---------- 23346 a1, a2 : array_like or poly1d object 23347 Input polynomials. 23348 23349 Returns 23350 ------- 23351 out : ndarray or poly1d object 23352 The sum of the inputs. If either input is a poly1d object, then the 23353 output is also a poly1d object. Otherwise, it is a 1D array of 23354 polynomial coefficients from highest to lowest degree. 23355 23356 See Also 23357 -------- 23358 poly1d : A one-dimensional polynomial class. 23359 poly, polyadd, polyder, polydiv, polyfit, polyint, polysub, polyval 23360 23361 Examples 23362 -------- 23363 >>> np.polyadd([1, 2], [9, 5, 4]) 23364 array([9, 6, 6]) 23365 23366 Using poly1d objects: 23367 23368 >>> p1 = np.poly1d([1, 2]) 23369 >>> p2 = np.poly1d([9, 5, 4]) 23370 >>> print p1 23371 1 x + 2 23372 >>> print p2 23373 2 23374 9 x + 5 x + 4 23375 >>> print np.polyadd(p1, p2) 23376 2 23377 9 x + 6 x + 6 23378 23379 """ 23380 return ndarray() if False else poly1d() 23381 def polyder(p=1, m=1): 23382 """ 23383 Return the derivative of the specified order of a polynomial. 23384 23385 Parameters 23386 ---------- 23387 p : poly1d or sequence 23388 Polynomial to differentiate. 23389 A sequence is interpreted as polynomial coefficients, see `poly1d`. 23390 m : int, optional 23391 Order of differentiation (default: 1) 23392 23393 Returns 23394 ------- 23395 der : poly1d 23396 A new polynomial representing the derivative. 23397 23398 See Also 23399 -------- 23400 polyint : Anti-derivative of a polynomial. 23401 poly1d : Class for one-dimensional polynomials. 23402 23403 Examples 23404 -------- 23405 The derivative of the polynomial :math:`x^3 + x^2 + x^1 + 1` is: 23406 23407 >>> p = np.poly1d([1,1,1,1]) 23408 >>> p2 = np.polyder(p) 23409 >>> p2 23410 poly1d([3, 2, 1]) 23411 23412 which evaluates to: 23413 23414 >>> p2(2.) 23415 17.0 23416 23417 We can verify this, approximating the derivative with 23418 ``(f(x + h) - f(x))/h``: 23419 23420 >>> (p(2. + 0.001) - p(2.)) / 0.001 23421 17.007000999997857 23422 23423 The fourth-order derivative of a 3rd-order polynomial is zero: 23424 23425 >>> np.polyder(p, 2) 23426 poly1d([6, 2]) 23427 >>> np.polyder(p, 3) 23428 poly1d([6]) 23429 >>> np.polyder(p, 4) 23430 poly1d([ 0.]) 23431 23432 """ 23433 return poly1d() 23434 def polydiv(u, v): 23435 """ 23436 Returns the quotient and remainder of polynomial division. 23437 23438 The input arrays are the coefficients (including any coefficients 23439 equal to zero) of the "numerator" (dividend) and "denominator" 23440 (divisor) polynomials, respectively. 23441 23442 Parameters 23443 ---------- 23444 u : array_like or poly1d 23445 Dividend polynomial's coefficients. 23446 23447 v : array_like or poly1d 23448 Divisor polynomial's coefficients. 23449 23450 Returns 23451 ------- 23452 q : ndarray 23453 Coefficients, including those equal to zero, of the quotient. 23454 r : ndarray 23455 Coefficients, including those equal to zero, of the remainder. 23456 23457 See Also 23458 -------- 23459 poly, polyadd, polyder, polydiv, polyfit, polyint, polymul, polysub, 23460 polyval 23461 23462 Notes 23463 ----- 23464 Both `u` and `v` must be 0-d or 1-d (ndim = 0 or 1), but `u.ndim` need 23465 not equal `v.ndim`. In other words, all four possible combinations - 23466 ``u.ndim = v.ndim = 0``, ``u.ndim = v.ndim = 1``, 23467 ``u.ndim = 1, v.ndim = 0``, and ``u.ndim = 0, v.ndim = 1`` - work. 23468 23469 Examples 23470 -------- 23471 .. math:: \frac{3x^2 + 5x + 2}{2x + 1} = 1.5x + 1.75, remainder 0.25 23472 23473 >>> x = np.array([3.0, 5.0, 2.0]) 23474 >>> y = np.array([2.0, 1.0]) 23475 >>> np.polydiv(x, y) 23476 (array([ 1.5 , 1.75]), array([ 0.25])) 23477 23478 """ 23479 return ndarray() 23480 def polyfit(x, y, deg=False, rcond=None, full=False, w=None, cov=False): 23481 """ 23482 Least squares polynomial fit. 23483 23484 Fit a polynomial ``p(x) = p[0] * x**deg + ... + p[deg]`` of degree `deg` 23485 to points `(x, y)`. Returns a vector of coefficients `p` that minimises 23486 the squared error. 23487 23488 Parameters 23489 ---------- 23490 x : array_like, shape (M,) 23491 x-coordinates of the M sample points ``(x[i], y[i])``. 23492 y : array_like, shape (M,) or (M, K) 23493 y-coordinates of the sample points. Several data sets of sample 23494 points sharing the same x-coordinates can be fitted at once by 23495 passing in a 2D-array that contains one dataset per column. 23496 deg : int 23497 Degree of the fitting polynomial 23498 rcond : float, optional 23499 Relative condition number of the fit. Singular values smaller than this 23500 relative to the largest singular value will be ignored. The default 23501 value is len(x)*eps, where eps is the relative precision of the float 23502 type, about 2e-16 in most cases. 23503 full : bool, optional 23504 Switch determining nature of return value. When it is 23505 False (the default) just the coefficients are returned, when True 23506 diagnostic information from the singular value decomposition is also 23507 returned. 23508 w : array_like, shape (M,), optional 23509 weights to apply to the y-coordinates of the sample points. 23510 cov : bool, optional 23511 Return the estimate and the covariance matrix of the estimate 23512 If full is True, then cov is not returned. 23513 23514 Returns 23515 ------- 23516 p : ndarray, shape (M,) or (M, K) 23517 Polynomial coefficients, highest power first. 23518 If `y` was 2-D, the coefficients for `k`-th data set are in ``p[:,k]``. 23519 23520 residuals, rank, singular_values, rcond : present only if `full` = True 23521 Residuals of the least-squares fit, the effective rank of the scaled 23522 Vandermonde coefficient matrix, its singular values, and the specified 23523 value of `rcond`. For more details, see `linalg.lstsq`. 23524 23525 V : ndaray, shape (M,M) or (M,M,K) : present only if `full` = False and `cov`=True 23526 The covariance matrix of the polynomial coefficient estimates. The diagonal 23527 of this matrix are the variance estimates for each coefficient. If y is a 2-d 23528 array, then the covariance matrix for the `k`-th data set are in ``V[:,:,k]`` 23529 23530 23531 Warns 23532 ----- 23533 RankWarning 23534 The rank of the coefficient matrix in the least-squares fit is 23535 deficient. The warning is only raised if `full` = False. 23536 23537 The warnings can be turned off by 23538 23539 >>> import warnings 23540 >>> warnings.simplefilter('ignore', np.RankWarning) 23541 23542 See Also 23543 -------- 23544 polyval : Computes polynomial values. 23545 linalg.lstsq : Computes a least-squares fit. 23546 scipy.interpolate.UnivariateSpline : Computes spline fits. 23547 23548 Notes 23549 ----- 23550 The solution minimizes the squared error 23551 23552 .. math :: 23553 E = \sum_{j=0}^k |p(x_j) - y_j|^2 23554 23555 in the equations:: 23556 23557 x[0]**n * p[n] + ... + x[0] * p[1] + p[0] = y[0] 23558 x[1]**n * p[n] + ... + x[1] * p[1] + p[0] = y[1] 23559 ... 23560 x[k]**n * p[n] + ... + x[k] * p[1] + p[0] = y[k] 23561 23562 The coefficient matrix of the coefficients `p` is a Vandermonde matrix. 23563 23564 `polyfit` issues a `RankWarning` when the least-squares fit is badly 23565 conditioned. This implies that the best fit is not well-defined due 23566 to numerical error. The results may be improved by lowering the polynomial 23567 degree or by replacing `x` by `x` - `x`.mean(). The `rcond` parameter 23568 can also be set to a value smaller than its default, but the resulting 23569 fit may be spurious: including contributions from the small singular 23570 values can add numerical noise to the result. 23571 23572 Note that fitting polynomial coefficients is inherently badly conditioned 23573 when the degree of the polynomial is large or the interval of sample points 23574 is badly centered. The quality of the fit should always be checked in these 23575 cases. When polynomial fits are not satisfactory, splines may be a good 23576 alternative. 23577 23578 References 23579 ---------- 23580 .. [1] Wikipedia, "Curve fitting", 23581 http://en.wikipedia.org/wiki/Curve_fitting 23582 .. [2] Wikipedia, "Polynomial interpolation", 23583 http://en.wikipedia.org/wiki/Polynomial_interpolation 23584 23585 Examples 23586 -------- 23587 >>> x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) 23588 >>> y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0]) 23589 >>> z = np.polyfit(x, y, 3) 23590 >>> z 23591 array([ 0.08703704, -0.81349206, 1.69312169, -0.03968254]) 23592 23593 It is convenient to use `poly1d` objects for dealing with polynomials: 23594 23595 >>> p = np.poly1d(z) 23596 >>> p(0.5) 23597 0.6143849206349179 23598 >>> p(3.5) 23599 -0.34732142857143039 23600 >>> p(10) 23601 22.579365079365115 23602 23603 High-order polynomials may oscillate wildly: 23604 23605 >>> p30 = np.poly1d(np.polyfit(x, y, 30)) 23606 /... RankWarning: Polyfit may be poorly conditioned... 23607 >>> p30(4) 23608 -0.80000000000000204 23609 >>> p30(5) 23610 -0.99999999999999445 23611 >>> p30(4.5) 23612 -0.10547061179440398 23613 23614 Illustration: 23615 23616 >>> import matplotlib.pyplot as plt 23617 >>> xp = np.linspace(-2, 6, 100) 23618 >>> plt.plot(x, y, '.', xp, p(xp), '-', xp, p30(xp), '--') 23619 [<matplotlib.lines.Line2D object at 0x...>, <matplotlib.lines.Line2D object at 0x...>, <matplotlib.lines.Line2D object at 0x...>] 23620 >>> plt.ylim(-2,2) 23621 (-2, 2) 23622 >>> plt.show() 23623 23624 """ 23625 return ndarray() if False else M() 23626 def polyint(p=None, m=1, k=None): 23627 """ 23628 Return an antiderivative (indefinite integral) of a polynomial. 23629 23630 The returned order `m` antiderivative `P` of polynomial `p` satisfies 23631 :math:`\frac{d^m}{dx^m}P(x) = p(x)` and is defined up to `m - 1` 23632 integration constants `k`. The constants determine the low-order 23633 polynomial part 23634 23635 .. math:: \frac{k_{m-1}}{0!} x^0 + \ldots + \frac{k_0}{(m-1)!}x^{m-1} 23636 23637 of `P` so that :math:`P^{(j)}(0) = k_{m-j-1}`. 23638 23639 Parameters 23640 ---------- 23641 p : {array_like, poly1d} 23642 Polynomial to differentiate. 23643 A sequence is interpreted as polynomial coefficients, see `poly1d`. 23644 m : int, optional 23645 Order of the antiderivative. (Default: 1) 23646 k : {None, list of `m` scalars, scalar}, optional 23647 Integration constants. They are given in the order of integration: 23648 those corresponding to highest-order terms come first. 23649 23650 If ``None`` (default), all constants are assumed to be zero. 23651 If `m = 1`, a single scalar can be given instead of a list. 23652 23653 See Also 23654 -------- 23655 polyder : derivative of a polynomial 23656 poly1d.integ : equivalent method 23657 23658 Examples 23659 -------- 23660 The defining property of the antiderivative: 23661 23662 >>> p = np.poly1d([1,1,1]) 23663 >>> P = np.polyint(p) 23664 >>> P 23665 poly1d([ 0.33333333, 0.5 , 1. , 0. ]) 23666 >>> np.polyder(P) == p 23667 True 23668 23669 The integration constants default to zero, but can be specified: 23670 23671 >>> P = np.polyint(p, 3) 23672 >>> P(0) 23673 0.0 23674 >>> np.polyder(P)(0) 23675 0.0 23676 >>> np.polyder(P, 2)(0) 23677 0.0 23678 >>> P = np.polyint(p, 3, k=[6,5,3]) 23679 >>> P 23680 poly1d([ 0.01666667, 0.04166667, 0.16666667, 3. , 5. , 3. ]) 23681 23682 Note that 3 = 6 / 2!, and that the constants are given in the order of 23683 integrations. Constant of the highest-order polynomial term comes first: 23684 23685 >>> np.polyder(P, 2)(0) 23686 6.0 23687 >>> np.polyder(P, 1)(0) 23688 5.0 23689 >>> P(0) 23690 3.0 23691 23692 """ 23693 return None 23694 def polymul(a1a2): 23695 """ 23696 Find the product of two polynomials. 23697 23698 Finds the polynomial resulting from the multiplication of the two input 23699 polynomials. Each input must be either a poly1d object or a 1D sequence 23700 of polynomial coefficients, from highest to lowest degree. 23701 23702 Parameters 23703 ---------- 23704 a1, a2 : array_like or poly1d object 23705 Input polynomials. 23706 23707 Returns 23708 ------- 23709 out : ndarray or poly1d object 23710 The polynomial resulting from the multiplication of the inputs. If 23711 either inputs is a poly1d object, then the output is also a poly1d 23712 object. Otherwise, it is a 1D array of polynomial coefficients from 23713 highest to lowest degree. 23714 23715 See Also 23716 -------- 23717 poly1d : A one-dimensional polynomial class. 23718 poly, polyadd, polyder, polydiv, polyfit, polyint, polysub, 23719 polyval 23720 23721 Examples 23722 -------- 23723 >>> np.polymul([1, 2, 3], [9, 5, 1]) 23724 array([ 9, 23, 38, 17, 3]) 23725 23726 Using poly1d objects: 23727 23728 >>> p1 = np.poly1d([1, 2, 3]) 23729 >>> p2 = np.poly1d([9, 5, 1]) 23730 >>> print p1 23731 2 23732 1 x + 2 x + 3 23733 >>> print p2 23734 2 23735 9 x + 5 x + 1 23736 >>> print np.polymul(p1, p2) 23737 4 3 2 23738 9 x + 23 x + 38 x + 17 x + 3 23739 23740 """ 23741 return ndarray() if False else poly1d() 23742 def polysub(a1a2): 23743 """ 23744 Difference (subtraction) of two polynomials. 23745 23746 Given two polynomials `a1` and `a2`, returns ``a1 - a2``. 23747 `a1` and `a2` can be either array_like sequences of the polynomials' 23748 coefficients (including coefficients equal to zero), or `poly1d` objects. 23749 23750 Parameters 23751 ---------- 23752 a1, a2 : array_like or poly1d 23753 Minuend and subtrahend polynomials, respectively. 23754 23755 Returns 23756 ------- 23757 out : ndarray or poly1d 23758 Array or `poly1d` object of the difference polynomial's coefficients. 23759 23760 See Also 23761 -------- 23762 polyval, polydiv, polymul, polyadd 23763 23764 Examples 23765 -------- 23766 .. math:: (2 x^2 + 10 x - 2) - (3 x^2 + 10 x -4) = (-x^2 + 2) 23767 23768 >>> np.polysub([2, 10, -2], [3, 10, -4]) 23769 array([-1, 0, 2]) 23770 23771 """ 23772 return ndarray() if False else poly1d() 23773 def polyval(p, x): 23774 """ 23775 Evaluate a polynomial at specific values. 23776 23777 If `p` is of length N, this function returns the value: 23778 23779 ``p[0]*x**(N-1) + p[1]*x**(N-2) + ... + p[N-2]*x + p[N-1]`` 23780 23781 If `x` is a sequence, then `p(x)` is returned for each element of `x`. 23782 If `x` is another polynomial then the composite polynomial `p(x(t))` 23783 is returned. 23784 23785 Parameters 23786 ---------- 23787 p : array_like or poly1d object 23788 1D array of polynomial coefficients (including coefficients equal 23789 to zero) from highest degree to the constant term, or an 23790 instance of poly1d. 23791 x : array_like or poly1d object 23792 A number, a 1D array of numbers, or an instance of poly1d, "at" 23793 which to evaluate `p`. 23794 23795 Returns 23796 ------- 23797 values : ndarray or poly1d 23798 If `x` is a poly1d instance, the result is the composition of the two 23799 polynomials, i.e., `x` is "substituted" in `p` and the simplified 23800 result is returned. In addition, the type of `x` - array_like or 23801 poly1d - governs the type of the output: `x` array_like => `values` 23802 array_like, `x` a poly1d object => `values` is also. 23803 23804 See Also 23805 -------- 23806 poly1d: A polynomial class. 23807 23808 Notes 23809 ----- 23810 Horner's scheme [1]_ is used to evaluate the polynomial. Even so, 23811 for polynomials of high degree the values may be inaccurate due to 23812 rounding errors. Use carefully. 23813 23814 References 23815 ---------- 23816 .. [1] I. N. Bronshtein, K. A. Semendyayev, and K. A. Hirsch (Eng. 23817 trans. Ed.), *Handbook of Mathematics*, New York, Van Nostrand 23818 Reinhold Co., 1985, pg. 720. 23819 23820 Examples 23821 -------- 23822 >>> np.polyval([3,0,1], 5) # 3 * 5**2 + 0 * 5**1 + 1 23823 76 23824 >>> np.polyval([3,0,1], np.poly1d(5)) 23825 poly1d([ 76.]) 23826 >>> np.polyval(np.poly1d([3,0,1]), 5) 23827 76 23828 >>> np.polyval(np.poly1d([3,0,1]), np.poly1d(5)) 23829 poly1d([ 76.]) 23830 23831 """ 23832 return ndarray() if False else poly1d() 23833 def power(x1, x2, out=None): 23834 """power(x1, x2[, out]) 23835 23836 First array elements raised to powers from second array, element-wise. 23837 23838 Raise each base in `x1` to the positionally-corresponding power in 23839 `x2`. `x1` and `x2` must be broadcastable to the same shape. 23840 23841 Parameters 23842 ---------- 23843 x1 : array_like 23844 The bases. 23845 x2 : array_like 23846 The exponents. 23847 23848 Returns 23849 ------- 23850 y : ndarray 23851 The bases in `x1` raised to the exponents in `x2`. 23852 23853 Examples 23854 -------- 23855 Cube each element in a list. 23856 23857 >>> x1 = range(6) 23858 >>> x1 23859 [0, 1, 2, 3, 4, 5] 23860 >>> np.power(x1, 3) 23861 array([ 0, 1, 8, 27, 64, 125]) 23862 23863 Raise the bases to different exponents. 23864 23865 >>> x2 = [1.0, 2.0, 3.0, 3.0, 2.0, 1.0] 23866 >>> np.power(x1, x2) 23867 array([ 0., 1., 8., 27., 16., 5.]) 23868 23869 The effect of broadcasting. 23870 23871 >>> x2 = np.array([[1, 2, 3, 3, 2, 1], [1, 2, 3, 3, 2, 1]]) 23872 >>> x2 23873 array([[1, 2, 3, 3, 2, 1], 23874 [1, 2, 3, 3, 2, 1]]) 23875 >>> np.power(x1, x2) 23876 array([[ 0, 1, 8, 27, 16, 5], 23877 [ 0, 1, 8, 27, 16, 5]])""" 23878 return ndarray() 23879 def ppmt(rate, per, nper, pv="end", fv=0.0, when="end"): 23880 """ 23881 Compute the payment against loan principal. 23882 23883 Parameters 23884 ---------- 23885 rate : array_like 23886 Rate of interest (per period) 23887 per : array_like, int 23888 Amount paid against the loan changes. The `per` is the period of 23889 interest. 23890 nper : array_like 23891 Number of compounding periods 23892 pv : array_like 23893 Present value 23894 fv : array_like, optional 23895 Future value 23896 when : {{'begin', 1}, {'end', 0}}, {string, int} 23897 When payments are due ('begin' (1) or 'end' (0)) 23898 23899 See Also 23900 -------- 23901 pmt, pv, ipmt 23902 23903 """ 23904 return None 23905 print_function = instance() 23906 def prod(a=False, axis=None, dtype=None, out=None, keepdims=False): 23907 """ 23908 Return the product of array elements over a given axis. 23909 23910 Parameters 23911 ---------- 23912 a : array_like 23913 Input data. 23914 axis : None or int or tuple of ints, optional 23915 Axis or axes along which a product is performed. 23916 The default (`axis` = `None`) is perform a product over all 23917 the dimensions of the input array. `axis` may be negative, in 23918 which case it counts from the last to the first axis. 23919 23920 .. versionadded:: 1.7.0 23921 23922 If this is a tuple of ints, a product is performed on multiple 23923 axes, instead of a single axis or all the axes as before. 23924 dtype : data-type, optional 23925 The data-type of the returned array, as well as of the accumulator 23926 in which the elements are multiplied. By default, if `a` is of 23927 integer type, `dtype` is the default platform integer. (Note: if 23928 the type of `a` is unsigned, then so is `dtype`.) Otherwise, 23929 the dtype is the same as that of `a`. 23930 out : ndarray, optional 23931 Alternative output array in which to place the result. It must have 23932 the same shape as the expected output, but the type of the 23933 output values will be cast if necessary. 23934 keepdims : bool, optional 23935 If this is set to True, the axes which are reduced are left 23936 in the result as dimensions with size one. With this option, 23937 the result will broadcast correctly against the original `arr`. 23938 23939 Returns 23940 ------- 23941 product_along_axis : ndarray, see `dtype` parameter above. 23942 An array shaped as `a` but with the specified axis removed. 23943 Returns a reference to `out` if specified. 23944 23945 See Also 23946 -------- 23947 ndarray.prod : equivalent method 23948 numpy.doc.ufuncs : Section "Output arguments" 23949 23950 Notes 23951 ----- 23952 Arithmetic is modular when using integer types, and no error is 23953 raised on overflow. That means that, on a 32-bit platform: 23954 23955 >>> x = np.array([536870910, 536870910, 536870910, 536870910]) 23956 >>> np.prod(x) #random 23957 16 23958 23959 Examples 23960 -------- 23961 By default, calculate the product of all elements: 23962 23963 >>> np.prod([1.,2.]) 23964 2.0 23965 23966 Even when the input array is two-dimensional: 23967 23968 >>> np.prod([[1.,2.],[3.,4.]]) 23969 24.0 23970 23971 But we can also specify the axis over which to multiply: 23972 23973 >>> np.prod([[1.,2.],[3.,4.]], axis=1) 23974 array([ 2., 12.]) 23975 23976 If the type of `x` is unsigned, then the output type is 23977 the unsigned platform integer: 23978 23979 >>> x = np.array([1, 2, 3], dtype=np.uint8) 23980 >>> np.prod(x).dtype == np.uint 23981 True 23982 23983 If `x` is of a signed integer type, then the output type 23984 is the default platform integer: 23985 23986 >>> x = np.array([1, 2, 3], dtype=np.int8) 23987 >>> np.prod(x).dtype == np.int 23988 True 23989 23990 """ 23991 return ndarray() 23992 def product(a=False, axis=None, dtype=None, out=None, keepdims=False): 23993 """ 23994 Return the product of array elements over a given axis. 23995 23996 See Also 23997 -------- 23998 prod : equivalent function; see for details. 23999 24000 """ 24001 return None 24002 def promote_types(type1, type2): 24003 """promote_types(type1, type2) 24004 24005 Returns the data type with the smallest size and smallest scalar 24006 kind to which both ``type1`` and ``type2`` may be safely cast. 24007 The returned data type is always in native byte order. 24008 24009 This function is symmetric and associative. 24010 24011 Parameters 24012 ---------- 24013 type1 : dtype or dtype specifier 24014 First data type. 24015 type2 : dtype or dtype specifier 24016 Second data type. 24017 24018 Returns 24019 ------- 24020 out : dtype 24021 The promoted data type. 24022 24023 Notes 24024 ----- 24025 .. versionadded:: 1.6.0 24026 24027 See Also 24028 -------- 24029 result_type, dtype, can_cast 24030 24031 Examples 24032 -------- 24033 >>> np.promote_types('f4', 'f8') 24034 dtype('float64') 24035 24036 >>> np.promote_types('i8', 'f4') 24037 dtype('float64') 24038 24039 >>> np.promote_types('>i8', '<c8') 24040 dtype('complex128') 24041 24042 >>> np.promote_types('i1', 'S8') 24043 Traceback (most recent call last): 24044 File "<stdin>", line 1, in <module> 24045 TypeError: invalid type promotion""" 24046 return dtype() 24047 def ptp(a=None, axis=None, out=None): 24048 """ 24049 Range of values (maximum - minimum) along an axis. 24050 24051 The name of the function comes from the acronym for 'peak to peak'. 24052 24053 Parameters 24054 ---------- 24055 a : array_like 24056 Input values. 24057 axis : int, optional 24058 Axis along which to find the peaks. By default, flatten the 24059 array. 24060 out : array_like 24061 Alternative output array in which to place the result. It must 24062 have the same shape and buffer length as the expected output, 24063 but the type of the output values will be cast if necessary. 24064 24065 Returns 24066 ------- 24067 ptp : ndarray 24068 A new array holding the result, unless `out` was 24069 specified, in which case a reference to `out` is returned. 24070 24071 Examples 24072 -------- 24073 >>> x = np.arange(4).reshape((2,2)) 24074 >>> x 24075 array([[0, 1], 24076 [2, 3]]) 24077 24078 >>> np.ptp(x, axis=0) 24079 array([2, 2]) 24080 24081 >>> np.ptp(x, axis=1) 24082 array([1, 1]) 24083 24084 """ 24085 return ndarray() 24086 def put(a, ind, v="raise", mode="raise"): 24087 """ 24088 Replaces specified elements of an array with given values. 24089 24090 The indexing works on the flattened target array. `put` is roughly 24091 equivalent to: 24092 24093 :: 24094 24095 a.flat[ind] = v 24096 24097 Parameters 24098 ---------- 24099 a : ndarray 24100 Target array. 24101 ind : array_like 24102 Target indices, interpreted as integers. 24103 v : array_like 24104 Values to place in `a` at target indices. If `v` is shorter than 24105 `ind` it will be repeated as necessary. 24106 mode : {'raise', 'wrap', 'clip'}, optional 24107 Specifies how out-of-bounds indices will behave. 24108 24109 * 'raise' -- raise an error (default) 24110 * 'wrap' -- wrap around 24111 * 'clip' -- clip to the range 24112 24113 'clip' mode means that all indices that are too large are replaced 24114 by the index that addresses the last element along that axis. Note 24115 that this disables indexing with negative numbers. 24116 24117 See Also 24118 -------- 24119 putmask, place 24120 24121 Examples 24122 -------- 24123 >>> a = np.arange(5) 24124 >>> np.put(a, [0, 2], [-44, -55]) 24125 >>> a 24126 array([-44, 1, -55, 3, 4]) 24127 24128 >>> a = np.arange(5) 24129 >>> np.put(a, 22, -5, mode='clip') 24130 >>> a 24131 array([ 0, 1, 2, 3, -5]) 24132 24133 """ 24134 return None 24135 def putmask(a, mask, values): 24136 """putmask(a, mask, values) 24137 24138 Changes elements of an array based on conditional and input values. 24139 24140 Sets ``a.flat[n] = values[n]`` for each n where ``mask.flat[n]==True``. 24141 24142 If `values` is not the same size as `a` and `mask` then it will repeat. 24143 This gives behavior different from ``a[mask] = values``. 24144 24145 .. note:: The `putmask` functionality is also provided by `copyto`, which 24146 can be significantly faster and in addition is NA-aware 24147 (`preservena` keyword). Replacing `putmask` with 24148 ``np.copyto(a, values, where=mask)`` is recommended. 24149 24150 Parameters 24151 ---------- 24152 a : array_like 24153 Target array. 24154 mask : array_like 24155 Boolean mask array. It has to be the same shape as `a`. 24156 values : array_like 24157 Values to put into `a` where `mask` is True. If `values` is smaller 24158 than `a` it will be repeated. 24159 24160 See Also 24161 -------- 24162 place, put, take, copyto 24163 24164 Examples 24165 -------- 24166 >>> x = np.arange(6).reshape(2, 3) 24167 >>> np.putmask(x, x>2, x**2) 24168 >>> x 24169 array([[ 0, 1, 2], 24170 [ 9, 16, 25]]) 24171 24172 If `values` is smaller than `a` it is repeated: 24173 24174 >>> x = np.arange(5) 24175 >>> np.putmask(x, x>1, [-33, -44]) 24176 >>> x 24177 array([ 0, 1, -33, -44, -33])""" 24178 return None 24179 def pv(rate, nper, pmt="end", fv=0.0, when="end"): 24180 """ 24181 Compute the present value. 24182 24183 Given: 24184 * a future value, `fv` 24185 * an interest `rate` compounded once per period, of which 24186 there are 24187 * `nper` total 24188 * a (fixed) payment, `pmt`, paid either 24189 * at the beginning (`when` = {'begin', 1}) or the end 24190 (`when` = {'end', 0}) of each period 24191 24192 Return: 24193 the value now 24194 24195 Parameters 24196 ---------- 24197 rate : array_like 24198 Rate of interest (per period) 24199 nper : array_like 24200 Number of compounding periods 24201 pmt : array_like 24202 Payment 24203 fv : array_like, optional 24204 Future value 24205 when : {{'begin', 1}, {'end', 0}}, {string, int}, optional 24206 When payments are due ('begin' (1) or 'end' (0)) 24207 24208 Returns 24209 ------- 24210 out : ndarray, float 24211 Present value of a series of payments or investments. 24212 24213 Notes 24214 ----- 24215 The present value is computed by solving the equation:: 24216 24217 fv + 24218 pv*(1 + rate)**nper + 24219 pmt*(1 + rate*when)/rate*((1 + rate)**nper - 1) = 0 24220 24221 or, when ``rate = 0``:: 24222 24223 fv + pv + pmt * nper = 0 24224 24225 for `pv`, which is then returned. 24226 24227 References 24228 ---------- 24229 .. [WRW] Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May). 24230 Open Document Format for Office Applications (OpenDocument)v1.2, 24231 Part 2: Recalculated Formula (OpenFormula) Format - Annotated Version, 24232 Pre-Draft 12. Organization for the Advancement of Structured Information 24233 Standards (OASIS). Billerica, MA, USA. [ODT Document]. 24234 Available: 24235 http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formula 24236 OpenDocument-formula-20090508.odt 24237 24238 Examples 24239 -------- 24240 What is the present value (e.g., the initial investment) 24241 of an investment that needs to total $15692.93 24242 after 10 years of saving $100 every month? Assume the 24243 interest rate is 5% (annually) compounded monthly. 24244 24245 >>> np.pv(0.05/12, 10*12, -100, 15692.93) 24246 -100.00067131625819 24247 24248 By convention, the negative sign represents cash flow out 24249 (i.e., money not available today). Thus, to end up with 24250 $15,692.93 in 10 years saving $100 a month at 5% annual 24251 interest, one's initial deposit should also be $100. 24252 24253 If any input is array_like, ``pv`` returns an array of equal shape. 24254 Let's compare different interest rates in the example above: 24255 24256 >>> a = np.array((0.05, 0.04, 0.03))/12 24257 >>> np.pv(a, 10*12, -100, 15692.93) 24258 array([ -100.00067132, -649.26771385, -1273.78633713]) 24259 24260 So, to end up with the same $15692.93 under the same $100 per month 24261 "savings plan," for annual interest rates of 4% and 3%, one would 24262 need initial investments of $649.27 and $1273.79, respectively. 24263 24264 """ 24265 return ndarray() 24266 r_ = RClass() 24267 def rad2deg(x, out): 24268 """rad2deg(x[, out]) 24269 24270 Convert angles from radians to degrees. 24271 24272 Parameters 24273 ---------- 24274 x : array_like 24275 Angle in radians. 24276 out : ndarray, optional 24277 Array into which the output is placed. Its type is preserved and it 24278 must be of the right shape to hold the output. See doc.ufuncs. 24279 24280 Returns 24281 ------- 24282 y : ndarray 24283 The corresponding angle in degrees. 24284 24285 See Also 24286 -------- 24287 deg2rad : Convert angles from degrees to radians. 24288 unwrap : Remove large jumps in angle by wrapping. 24289 24290 Notes 24291 ----- 24292 .. versionadded:: 1.3.0 24293 24294 rad2deg(x) is ``180 * x / pi``. 24295 24296 Examples 24297 -------- 24298 >>> np.rad2deg(np.pi/2) 24299 90.0""" 24300 return ndarray() 24301 def radians(x, out): 24302 """radians(x[, out]) 24303 24304 Convert angles from degrees to radians. 24305 24306 Parameters 24307 ---------- 24308 x : array_like 24309 Input array in degrees. 24310 out : ndarray, optional 24311 Output array of same shape as `x`. 24312 24313 Returns 24314 ------- 24315 y : ndarray 24316 The corresponding radian values. 24317 24318 See Also 24319 -------- 24320 deg2rad : equivalent function 24321 24322 Examples 24323 -------- 24324 Convert a degree array to radians 24325 24326 >>> deg = np.arange(12.) * 30. 24327 >>> np.radians(deg) 24328 array([ 0. , 0.52359878, 1.04719755, 1.57079633, 2.0943951 , 24329 2.61799388, 3.14159265, 3.66519143, 4.1887902 , 4.71238898, 24330 5.23598776, 5.75958653]) 24331 24332 >>> out = np.zeros((deg.shape)) 24333 >>> ret = np.radians(deg, out) 24334 >>> ret is out 24335 True""" 24336 return ndarray() 24337 def rank(a): 24338 """ 24339 Return the number of dimensions of an array. 24340 24341 If `a` is not already an array, a conversion is attempted. 24342 Scalars are zero dimensional. 24343 24344 Parameters 24345 ---------- 24346 a : array_like 24347 Array whose number of dimensions is desired. If `a` is not an array, 24348 a conversion is attempted. 24349 24350 Returns 24351 ------- 24352 number_of_dimensions : int 24353 The number of dimensions in the array. 24354 24355 See Also 24356 -------- 24357 ndim : equivalent function 24358 ndarray.ndim : equivalent property 24359 shape : dimensions of array 24360 ndarray.shape : dimensions of array 24361 24362 Notes 24363 ----- 24364 In the old Numeric package, `rank` was the term used for the number of 24365 dimensions, but in Numpy `ndim` is used instead. 24366 24367 Examples 24368 -------- 24369 >>> np.rank([1,2,3]) 24370 1 24371 >>> np.rank(np.array([[1,2,3],[4,5,6]])) 24372 2 24373 >>> np.rank(1) 24374 0 24375 24376 """ 24377 return int() 24378 def rate(nper, pmt, pv, fv=100, when="end", guess=0.1, tol=1e-06, maxiter=100): 24379 """ 24380 Compute the rate of interest per period. 24381 24382 Parameters 24383 ---------- 24384 nper : array_like 24385 Number of compounding periods 24386 pmt : array_like 24387 Payment 24388 pv : array_like 24389 Present value 24390 fv : array_like 24391 Future value 24392 when : {{'begin', 1}, {'end', 0}}, {string, int}, optional 24393 When payments are due ('begin' (1) or 'end' (0)) 24394 guess : float, optional 24395 Starting guess for solving the rate of interest 24396 tol : float, optional 24397 Required tolerance for the solution 24398 maxiter : int, optional 24399 Maximum iterations in finding the solution 24400 24401 Notes 24402 ----- 24403 The rate of interest is computed by iteratively solving the 24404 (non-linear) equation:: 24405 24406 fv + pv*(1+rate)**nper + pmt*(1+rate*when)/rate * ((1+rate)**nper - 1) = 0 24407 24408 for ``rate``. 24409 24410 References 24411 ---------- 24412 Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May). Open Document 24413 Format for Office Applications (OpenDocument)v1.2, Part 2: Recalculated 24414 Formula (OpenFormula) Format - Annotated Version, Pre-Draft 12. 24415 Organization for the Advancement of Structured Information Standards 24416 (OASIS). Billerica, MA, USA. [ODT Document]. Available: 24417 http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formula 24418 OpenDocument-formula-20090508.odt 24419 24420 """ 24421 return None 24422 def ravel(a="C", order="C"): 24423 """ 24424 Return a flattened array. 24425 24426 A 1-D array, containing the elements of the input, is returned. A copy is 24427 made only if needed. 24428 24429 Parameters 24430 ---------- 24431 a : array_like 24432 Input array. The elements in `a` are read in the order specified by 24433 `order`, and packed as a 1-D array. 24434 order : {'C','F', 'A', 'K'}, optional 24435 The elements of `a` are read using this index order. 'C' means to 24436 index the elements in C-like order, with the last axis index changing 24437 fastest, back to the first axis index changing slowest. 'F' means to 24438 index the elements in Fortran-like index order, with the first index 24439 changing fastest, and the last index changing slowest. Note that the 'C' 24440 and 'F' options take no account of the memory layout of the underlying 24441 array, and only refer to the order of axis indexing. 'A' means to read 24442 the elements in Fortran-like index order if `a` is Fortran *contiguous* 24443 in memory, C-like order otherwise. 'K' means to read the elements in 24444 the order they occur in memory, except for reversing the data when 24445 strides are negative. By default, 'C' index order is used. 24446 24447 Returns 24448 ------- 24449 1d_array : ndarray 24450 Output of the same dtype as `a`, and of shape ``(a.size,)``. 24451 24452 See Also 24453 -------- 24454 ndarray.flat : 1-D iterator over an array. 24455 ndarray.flatten : 1-D array copy of the elements of an array 24456 in row-major order. 24457 24458 Notes 24459 ----- 24460 In C-like (row-major) order, in two dimensions, the row index varies the 24461 slowest, and the column index the quickest. This can be generalized to 24462 multiple dimensions, where row-major order implies that the index along the 24463 first axis varies slowest, and the index along the last quickest. The 24464 opposite holds for Fortran-like, or column-major, index ordering. 24465 24466 Examples 24467 -------- 24468 It is equivalent to ``reshape(-1, order=order)``. 24469 24470 >>> x = np.array([[1, 2, 3], [4, 5, 6]]) 24471 >>> print np.ravel(x) 24472 [1 2 3 4 5 6] 24473 24474 >>> print x.reshape(-1) 24475 [1 2 3 4 5 6] 24476 24477 >>> print np.ravel(x, order='F') 24478 [1 4 2 5 3 6] 24479 24480 When ``order`` is 'A', it will preserve the array's 'C' or 'F' ordering: 24481 24482 >>> print np.ravel(x.T) 24483 [1 4 2 5 3 6] 24484 >>> print np.ravel(x.T, order='A') 24485 [1 2 3 4 5 6] 24486 24487 When ``order`` is 'K', it will preserve orderings that are neither 'C' 24488 nor 'F', but won't reverse axes: 24489 24490 >>> a = np.arange(3)[::-1]; a 24491 array([2, 1, 0]) 24492 >>> a.ravel(order='C') 24493 array([2, 1, 0]) 24494 >>> a.ravel(order='K') 24495 array([2, 1, 0]) 24496 24497 >>> a = np.arange(12).reshape(2,3,2).swapaxes(1,2); a 24498 array([[[ 0, 2, 4], 24499 [ 1, 3, 5]], 24500 [[ 6, 8, 10], 24501 [ 7, 9, 11]]]) 24502 >>> a.ravel(order='C') 24503 array([ 0, 2, 4, 1, 3, 5, 6, 8, 10, 7, 9, 11]) 24504 >>> a.ravel(order='K') 24505 array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) 24506 24507 """ 24508 return ndarray() 24509 def ravel_multi_index(multi_index, dims, mode, order): 24510 """ravel_multi_index(multi_index, dims, mode='raise', order='C') 24511 24512 Converts a tuple of index arrays into an array of flat 24513 indices, applying boundary modes to the multi-index. 24514 24515 Parameters 24516 ---------- 24517 multi_index : tuple of array_like 24518 A tuple of integer arrays, one array for each dimension. 24519 dims : tuple of ints 24520 The shape of array into which the indices from ``multi_index`` apply. 24521 mode : {'raise', 'wrap', 'clip'}, optional 24522 Specifies how out-of-bounds indices are handled. Can specify 24523 either one mode or a tuple of modes, one mode per index. 24524 24525 * 'raise' -- raise an error (default) 24526 * 'wrap' -- wrap around 24527 * 'clip' -- clip to the range 24528 24529 In 'clip' mode, a negative index which would normally 24530 wrap will clip to 0 instead. 24531 order : {'C', 'F'}, optional 24532 Determines whether the multi-index should be viewed as indexing in 24533 C (row-major) order or FORTRAN (column-major) order. 24534 24535 Returns 24536 ------- 24537 raveled_indices : ndarray 24538 An array of indices into the flattened version of an array 24539 of dimensions ``dims``. 24540 24541 See Also 24542 -------- 24543 unravel_index 24544 24545 Notes 24546 ----- 24547 .. versionadded:: 1.6.0 24548 24549 Examples 24550 -------- 24551 >>> arr = np.array([[3,6,6],[4,5,1]]) 24552 >>> np.ravel_multi_index(arr, (7,6)) 24553 array([22, 41, 37]) 24554 >>> np.ravel_multi_index(arr, (7,6), order='F') 24555 array([31, 41, 13]) 24556 >>> np.ravel_multi_index(arr, (4,6), mode='clip') 24557 array([22, 23, 19]) 24558 >>> np.ravel_multi_index(arr, (4,4), mode=('clip','wrap')) 24559 array([12, 13, 13]) 24560 24561 >>> np.ravel_multi_index((3,1,4,1), (6,7,8,9)) 24562 1621""" 24563 return ndarray() 24564 def real(val): 24565 """ 24566 Return the real part of the elements of the array. 24567 24568 Parameters 24569 ---------- 24570 val : array_like 24571 Input array. 24572 24573 Returns 24574 ------- 24575 out : ndarray 24576 Output array. If `val` is real, the type of `val` is used for the 24577 output. If `val` has complex elements, the returned type is float. 24578 24579 See Also 24580 -------- 24581 real_if_close, imag, angle 24582 24583 Examples 24584 -------- 24585 >>> a = np.array([1+2j, 3+4j, 5+6j]) 24586 >>> a.real 24587 array([ 1., 3., 5.]) 24588 >>> a.real = 9 24589 >>> a 24590 array([ 9.+2.j, 9.+4.j, 9.+6.j]) 24591 >>> a.real = np.array([9, 8, 7]) 24592 >>> a 24593 array([ 9.+2.j, 8.+4.j, 7.+6.j]) 24594 24595 """ 24596 return ndarray() 24597 def real_if_close(a=100, tol=100): 24598 """ 24599 If complex input returns a real array if complex parts are close to zero. 24600 24601 "Close to zero" is defined as `tol` * (machine epsilon of the type for 24602 `a`). 24603 24604 Parameters 24605 ---------- 24606 a : array_like 24607 Input array. 24608 tol : float 24609 Tolerance in machine epsilons for the complex part of the elements 24610 in the array. 24611 24612 Returns 24613 ------- 24614 out : ndarray 24615 If `a` is real, the type of `a` is used for the output. If `a` 24616 has complex elements, the returned type is float. 24617 24618 See Also 24619 -------- 24620 real, imag, angle 24621 24622 Notes 24623 ----- 24624 Machine epsilon varies from machine to machine and between data types 24625 but Python floats on most platforms have a machine epsilon equal to 24626 2.2204460492503131e-16. You can use 'np.finfo(np.float).eps' to print 24627 out the machine epsilon for floats. 24628 24629 Examples 24630 -------- 24631 >>> np.finfo(np.float).eps 24632 2.2204460492503131e-16 24633 24634 >>> np.real_if_close([2.1 + 4e-14j], tol=1000) 24635 array([ 2.1]) 24636 >>> np.real_if_close([2.1 + 4e-13j], tol=1000) 24637 array([ 2.1 +4.00000000e-13j]) 24638 24639 """ 24640 return ndarray() 24641 class recarray: 24642 T = getset_descriptor() 24643 __array_finalize__ = getset_descriptor() 24644 __array_interface__ = getset_descriptor() 24645 __array_priority__ = getset_descriptor() 24646 __array_struct__ = getset_descriptor() 24647 __dict__ = dictproxy() 24648 __doc__ = str() 24649 __module__ = str() 24650 def all(self, axis=None, out=None): 24651 """a.all(axis=None, out=None) 24652 24653 Returns True if all elements evaluate to True. 24654 24655 Refer to `numpy.all` for full documentation. 24656 24657 See Also 24658 -------- 24659 numpy.all : equivalent function""" 24660 return None 24661 def any(self, axis=None, out=None): 24662 """a.any(axis=None, out=None) 24663 24664 Returns True if any of the elements of `a` evaluate to True. 24665 24666 Refer to `numpy.any` for full documentation. 24667 24668 See Also 24669 -------- 24670 numpy.any : equivalent function""" 24671 return None 24672 def argmax(self, axis=None, out=None): 24673 """a.argmax(axis=None, out=None) 24674 24675 Return indices of the maximum values along the given axis. 24676 24677 Refer to `numpy.argmax` for full documentation. 24678 24679 See Also 24680 -------- 24681 numpy.argmax : equivalent function""" 24682 return None 24683 def argmin(self, axis=None, out=None): 24684 """a.argmin(axis=None, out=None) 24685 24686 Return indices of the minimum values along the given axis of `a`. 24687 24688 Refer to `numpy.argmin` for detailed documentation. 24689 24690 See Also 24691 -------- 24692 numpy.argmin : equivalent function""" 24693 return None 24694 def argpartition(self, kth, axis=_1, kind=quickselect, order=None): 24695 """a.argpartition(kth, axis=-1, kind='quickselect', order=None) 24696 24697 Returns the indices that would partition this array. 24698 24699 Refer to `numpy.argpartition` for full documentation. 24700 24701 .. versionadded:: 1.8.0 24702 24703 See Also 24704 -------- 24705 numpy.argpartition : equivalent function""" 24706 return None 24707 def argsort(self, axis=_1, kind=quicksort, order=None): 24708 """a.argsort(axis=-1, kind='quicksort', order=None) 24709 24710 Returns the indices that would sort this array. 24711 24712 Refer to `numpy.argsort` for full documentation. 24713 24714 See Also 24715 -------- 24716 numpy.argsort : equivalent function""" 24717 return None 24718 def astype(self, dtype, order, casting, subok, copy): 24719 """a.astype(dtype, order='K', casting='unsafe', subok=True, copy=True) 24720 24721 Copy of the array, cast to a specified type. 24722 24723 Parameters 24724 ---------- 24725 dtype : str or dtype 24726 Typecode or data-type to which the array is cast. 24727 order : {'C', 'F', 'A', 'K'}, optional 24728 Controls the memory layout order of the result. 24729 'C' means C order, 'F' means Fortran order, 'A' 24730 means 'F' order if all the arrays are Fortran contiguous, 24731 'C' order otherwise, and 'K' means as close to the 24732 order the array elements appear in memory as possible. 24733 Default is 'K'. 24734 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional 24735 Controls what kind of data casting may occur. Defaults to 'unsafe' 24736 for backwards compatibility. 24737 24738 * 'no' means the data types should not be cast at all. 24739 * 'equiv' means only byte-order changes are allowed. 24740 * 'safe' means only casts which can preserve values are allowed. 24741 * 'same_kind' means only safe casts or casts within a kind, 24742 like float64 to float32, are allowed. 24743 * 'unsafe' means any data conversions may be done. 24744 subok : bool, optional 24745 If True, then sub-classes will be passed-through (default), otherwise 24746 the returned array will be forced to be a base-class array. 24747 copy : bool, optional 24748 By default, astype always returns a newly allocated array. If this 24749 is set to false, and the `dtype`, `order`, and `subok` 24750 requirements are satisfied, the input array is returned instead 24751 of a copy. 24752 24753 Returns 24754 ------- 24755 arr_t : ndarray 24756 Unless `copy` is False and the other conditions for returning the input 24757 array are satisfied (see description for `copy` input paramter), `arr_t` 24758 is a new array of the same shape as the input array, with dtype, order 24759 given by `dtype`, `order`. 24760 24761 Raises 24762 ------ 24763 ComplexWarning 24764 When casting from complex to float or int. To avoid this, 24765 one should use ``a.real.astype(t)``. 24766 24767 Examples 24768 -------- 24769 >>> x = np.array([1, 2, 2.5]) 24770 >>> x 24771 array([ 1. , 2. , 2.5]) 24772 24773 >>> x.astype(int) 24774 array([1, 2, 2])""" 24775 return ndarray() 24776 base = getset_descriptor() 24777 def byteswap(self, inplace): 24778 """a.byteswap(inplace) 24779 24780 Swap the bytes of the array elements 24781 24782 Toggle between low-endian and big-endian data representation by 24783 returning a byteswapped array, optionally swapped in-place. 24784 24785 Parameters 24786 ---------- 24787 inplace : bool, optional 24788 If ``True``, swap bytes in-place, default is ``False``. 24789 24790 Returns 24791 ------- 24792 out : ndarray 24793 The byteswapped array. If `inplace` is ``True``, this is 24794 a view to self. 24795 24796 Examples 24797 -------- 24798 >>> A = np.array([1, 256, 8755], dtype=np.int16) 24799 >>> map(hex, A) 24800 ['0x1', '0x100', '0x2233'] 24801 >>> A.byteswap(True) 24802 array([ 256, 1, 13090], dtype=int16) 24803 >>> map(hex, A) 24804 ['0x100', '0x1', '0x3322'] 24805 24806 Arrays of strings are not swapped 24807 24808 >>> A = np.array(['ceg', 'fac']) 24809 >>> A.byteswap() 24810 array(['ceg', 'fac'], 24811 dtype='|S3')""" 24812 return ndarray() 24813 def choose(self, choices, out=None, mode=_raise): 24814 """a.choose(choices, out=None, mode='raise') 24815 24816 Use an index array to construct a new array from a set of choices. 24817 24818 Refer to `numpy.choose` for full documentation. 24819 24820 See Also 24821 -------- 24822 numpy.choose : equivalent function""" 24823 return None 24824 def clip(self, a_min, a_max, out=None): 24825 """a.clip(a_min, a_max, out=None) 24826 24827 Return an array whose values are limited to ``[a_min, a_max]``. 24828 24829 Refer to `numpy.clip` for full documentation. 24830 24831 See Also 24832 -------- 24833 numpy.clip : equivalent function""" 24834 return None 24835 def compress(self, condition, axis=None, out=None): 24836 """a.compress(condition, axis=None, out=None) 24837 24838 Return selected slices of this array along given axis. 24839 24840 Refer to `numpy.compress` for full documentation. 24841 24842 See Also 24843 -------- 24844 numpy.compress : equivalent function""" 24845 return None 24846 def conj(self, _): 24847 """a.conj() 24848 24849 Complex-conjugate all elements. 24850 24851 Refer to `numpy.conjugate` for full documentation. 24852 24853 See Also 24854 -------- 24855 numpy.conjugate : equivalent function""" 24856 return None 24857 def conjugate(self, _): 24858 """a.conjugate() 24859 24860 Return the complex conjugate, element-wise. 24861 24862 Refer to `numpy.conjugate` for full documentation. 24863 24864 See Also 24865 -------- 24866 numpy.conjugate : equivalent function""" 24867 return None 24868 def copy(self, order): 24869 """a.copy(order='C') 24870 24871 Return a copy of the array. 24872 24873 Parameters 24874 ---------- 24875 order : {'C', 'F', 'A', 'K'}, optional 24876 Controls the memory layout of the copy. 'C' means C-order, 24877 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, 24878 'C' otherwise. 'K' means match the layout of `a` as closely 24879 as possible. (Note that this function and :func:numpy.copy are very 24880 similar, but have different default values for their order= 24881 arguments.) 24882 24883 See also 24884 -------- 24885 numpy.copy 24886 numpy.copyto 24887 24888 Examples 24889 -------- 24890 >>> x = np.array([[1,2,3],[4,5,6]], order='F') 24891 24892 >>> y = x.copy() 24893 24894 >>> x.fill(0) 24895 24896 >>> x 24897 array([[0, 0, 0], 24898 [0, 0, 0]]) 24899 24900 >>> y 24901 array([[1, 2, 3], 24902 [4, 5, 6]]) 24903 24904 >>> y.flags['C_CONTIGUOUS'] 24905 True""" 24906 return None 24907 ctypes = getset_descriptor() 24908 def cumprod(self, axis=None, dtype=None, out=None): 24909 """a.cumprod(axis=None, dtype=None, out=None) 24910 24911 Return the cumulative product of the elements along the given axis. 24912 24913 Refer to `numpy.cumprod` for full documentation. 24914 24915 See Also 24916 -------- 24917 numpy.cumprod : equivalent function""" 24918 return None 24919 def cumsum(self, axis=None, dtype=None, out=None): 24920 """a.cumsum(axis=None, dtype=None, out=None) 24921 24922 Return the cumulative sum of the elements along the given axis. 24923 24924 Refer to `numpy.cumsum` for full documentation. 24925 24926 See Also 24927 -------- 24928 numpy.cumsum : equivalent function""" 24929 return None 24930 data = getset_descriptor() 24931 def diagonal(self, offset=0, axis1=0, axis2=1): 24932 """a.diagonal(offset=0, axis1=0, axis2=1) 24933 24934 Return specified diagonals. 24935 24936 Refer to :func:`numpy.diagonal` for full documentation. 24937 24938 See Also 24939 -------- 24940 numpy.diagonal : equivalent function""" 24941 return None 24942 def dot(self, b, out=None): 24943 """a.dot(b, out=None) 24944 24945 Dot product of two arrays. 24946 24947 Refer to `numpy.dot` for full documentation. 24948 24949 See Also 24950 -------- 24951 numpy.dot : equivalent function 24952 24953 Examples 24954 -------- 24955 >>> a = np.eye(2) 24956 >>> b = np.ones((2, 2)) * 2 24957 >>> a.dot(b) 24958 array([[ 2., 2.], 24959 [ 2., 2.]]) 24960 24961 This array method can be conveniently chained: 24962 24963 >>> a.dot(b).dot(b) 24964 array([[ 8., 8.], 24965 [ 8., 8.]])""" 24966 return None 24967 dtype = getset_descriptor() 24968 def dump(self, file): 24969 """a.dump(file) 24970 24971 Dump a pickle of the array to the specified file. 24972 The array can be read back with pickle.load or numpy.load. 24973 24974 Parameters 24975 ---------- 24976 file : str 24977 A string naming the dump file.""" 24978 return None 24979 def dumps(self, _): 24980 """a.dumps() 24981 24982 Returns the pickle of the array as a string. 24983 pickle.loads or numpy.loads will convert the string back to an array. 24984 24985 Parameters 24986 ---------- 24987 None""" 24988 return None 24989 def field(self, attr=None, val=None): 24990 """None""" 24991 return None 24992 def fill(self, value): 24993 """a.fill(value) 24994 24995 Fill the array with a scalar value. 24996 24997 Parameters 24998 ---------- 24999 value : scalar 25000 All elements of `a` will be assigned this value. 25001 25002 Examples 25003 -------- 25004 >>> a = np.array([1, 2]) 25005 >>> a.fill(0) 25006 >>> a 25007 array([0, 0]) 25008 >>> a = np.empty(2) 25009 >>> a.fill(1) 25010 >>> a 25011 array([ 1., 1.])""" 25012 return None 25013 flags = getset_descriptor() 25014 flat = getset_descriptor() 25015 def flatten(self, order): 25016 """a.flatten(order='C') 25017 25018 Return a copy of the array collapsed into one dimension. 25019 25020 Parameters 25021 ---------- 25022 order : {'C', 'F', 'A'}, optional 25023 Whether to flatten in C (row-major), Fortran (column-major) order, 25024 or preserve the C/Fortran ordering from `a`. 25025 The default is 'C'. 25026 25027 Returns 25028 ------- 25029 y : ndarray 25030 A copy of the input array, flattened to one dimension. 25031 25032 See Also 25033 -------- 25034 ravel : Return a flattened array. 25035 flat : A 1-D flat iterator over the array. 25036 25037 Examples 25038 -------- 25039 >>> a = np.array([[1,2], [3,4]]) 25040 >>> a.flatten() 25041 array([1, 2, 3, 4]) 25042 >>> a.flatten('F') 25043 array([1, 3, 2, 4])""" 25044 return ndarray() 25045 def getfield(self, dtype, offset): 25046 """a.getfield(dtype, offset=0) 25047 25048 Returns a field of the given array as a certain type. 25049 25050 A field is a view of the array data with a given data-type. The values in 25051 the view are determined by the given type and the offset into the current 25052 array in bytes. The offset needs to be such that the view dtype fits in the 25053 array dtype; for example an array of dtype complex128 has 16-byte elements. 25054 If taking a view with a 32-bit integer (4 bytes), the offset needs to be 25055 between 0 and 12 bytes. 25056 25057 Parameters 25058 ---------- 25059 dtype : str or dtype 25060 The data type of the view. The dtype size of the view can not be larger 25061 than that of the array itself. 25062 offset : int 25063 Number of bytes to skip before beginning the element view. 25064 25065 Examples 25066 -------- 25067 >>> x = np.diag([1.+1.j]*2) 25068 >>> x[1, 1] = 2 + 4.j 25069 >>> x 25070 array([[ 1.+1.j, 0.+0.j], 25071 [ 0.+0.j, 2.+4.j]]) 25072 >>> x.getfield(np.float64) 25073 array([[ 1., 0.], 25074 [ 0., 2.]]) 25075 25076 By choosing an offset of 8 bytes we can select the complex part of the 25077 array for our view: 25078 25079 >>> x.getfield(np.float64, offset=8) 25080 array([[ 1., 0.], 25081 [ 0., 4.]])""" 25082 return array() 25083 imag = getset_descriptor() 25084 def item(self, ESCargs): 25085 """a.item(*args) 25086 25087 Copy an element of an array to a standard Python scalar and return it. 25088 25089 Parameters 25090 ---------- 25091 \*args : Arguments (variable number and type) 25092 25093 * none: in this case, the method only works for arrays 25094 with one element (`a.size == 1`), which element is 25095 copied into a standard Python scalar object and returned. 25096 25097 * int_type: this argument is interpreted as a flat index into 25098 the array, specifying which element to copy and return. 25099 25100 * tuple of int_types: functions as does a single int_type argument, 25101 except that the argument is interpreted as an nd-index into the 25102 array. 25103 25104 Returns 25105 ------- 25106 z : Standard Python scalar object 25107 A copy of the specified element of the array as a suitable 25108 Python scalar 25109 25110 Notes 25111 ----- 25112 When the data type of `a` is longdouble or clongdouble, item() returns 25113 a scalar array object because there is no available Python scalar that 25114 would not lose information. Void arrays return a buffer object for item(), 25115 unless fields are defined, in which case a tuple is returned. 25116 25117 `item` is very similar to a[args], except, instead of an array scalar, 25118 a standard Python scalar is returned. This can be useful for speeding up 25119 access to elements of the array and doing arithmetic on elements of the 25120 array using Python's optimized math. 25121 25122 Examples 25123 -------- 25124 >>> x = np.random.randint(9, size=(3, 3)) 25125 >>> x 25126 array([[3, 1, 7], 25127 [2, 8, 3], 25128 [8, 5, 3]]) 25129 >>> x.item(3) 25130 2 25131 >>> x.item(7) 25132 5 25133 >>> x.item((0, 1)) 25134 1 25135 >>> x.item((2, 2)) 25136 3""" 25137 return Standard() 25138 def itemset(self, ESCargs): 25139 """a.itemset(*args) 25140 25141 Insert scalar into an array (scalar is cast to array's dtype, if possible) 25142 25143 There must be at least 1 argument, and define the last argument 25144 as *item*. Then, ``a.itemset(*args)`` is equivalent to but faster 25145 than ``a[args] = item``. The item should be a scalar value and `args` 25146 must select a single item in the array `a`. 25147 25148 Parameters 25149 ---------- 25150 \*args : Arguments 25151 If one argument: a scalar, only used in case `a` is of size 1. 25152 If two arguments: the last argument is the value to be set 25153 and must be a scalar, the first argument specifies a single array 25154 element location. It is either an int or a tuple. 25155 25156 Notes 25157 ----- 25158 Compared to indexing syntax, `itemset` provides some speed increase 25159 for placing a scalar into a particular location in an `ndarray`, 25160 if you must do this. However, generally this is discouraged: 25161 among other problems, it complicates the appearance of the code. 25162 Also, when using `itemset` (and `item`) inside a loop, be sure 25163 to assign the methods to a local variable to avoid the attribute 25164 look-up at each loop iteration. 25165 25166 Examples 25167 -------- 25168 >>> x = np.random.randint(9, size=(3, 3)) 25169 >>> x 25170 array([[3, 1, 7], 25171 [2, 8, 3], 25172 [8, 5, 3]]) 25173 >>> x.itemset(4, 0) 25174 >>> x.itemset((2, 2), 9) 25175 >>> x 25176 array([[3, 1, 7], 25177 [2, 0, 3], 25178 [8, 5, 9]])""" 25179 return None 25180 itemsize = getset_descriptor() 25181 def max(self, axis=None, out=None): 25182 """a.max(axis=None, out=None) 25183 25184 Return the maximum along a given axis. 25185 25186 Refer to `numpy.amax` for full documentation. 25187 25188 See Also 25189 -------- 25190 numpy.amax : equivalent function""" 25191 return None 25192 def mean(self, axis=None, dtype=None, out=None): 25193 """a.mean(axis=None, dtype=None, out=None) 25194 25195 Returns the average of the array elements along given axis. 25196 25197 Refer to `numpy.mean` for full documentation. 25198 25199 See Also 25200 -------- 25201 numpy.mean : equivalent function""" 25202 return None 25203 def min(self, axis=None, out=None): 25204 """a.min(axis=None, out=None) 25205 25206 Return the minimum along a given axis. 25207 25208 Refer to `numpy.amin` for full documentation. 25209 25210 See Also 25211 -------- 25212 numpy.amin : equivalent function""" 25213 return None 25214 nbytes = getset_descriptor() 25215 ndim = getset_descriptor() 25216 def newbyteorder(self, new_order): 25217 """arr.newbyteorder(new_order='S') 25218 25219 Return the array with the same data viewed with a different byte order. 25220 25221 Equivalent to:: 25222 25223 arr.view(arr.dtype.newbytorder(new_order)) 25224 25225 Changes are also made in all fields and sub-arrays of the array data 25226 type. 25227 25228 25229 25230 Parameters 25231 ---------- 25232 new_order : string, optional 25233 Byte order to force; a value from the byte order specifications 25234 above. `new_order` codes can be any of:: 25235 25236 * 'S' - swap dtype from current to opposite endian 25237 * {'<', 'L'} - little endian 25238 * {'>', 'B'} - big endian 25239 * {'=', 'N'} - native order 25240 * {'|', 'I'} - ignore (no change to byte order) 25241 25242 The default value ('S') results in swapping the current 25243 byte order. The code does a case-insensitive check on the first 25244 letter of `new_order` for the alternatives above. For example, 25245 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 25246 25247 25248 Returns 25249 ------- 25250 new_arr : array 25251 New array object with the dtype reflecting given change to the 25252 byte order.""" 25253 return array() 25254 def nonzero(self, _): 25255 """a.nonzero() 25256 25257 Return the indices of the elements that are non-zero. 25258 25259 Refer to `numpy.nonzero` for full documentation. 25260 25261 See Also 25262 -------- 25263 numpy.nonzero : equivalent function""" 25264 return None 25265 def partition(self, kth, axis, kind, order): 25266 """a.partition(kth, axis=-1, kind='introselect', order=None) 25267 25268 Rearranges the elements in the array in such a way that value of the 25269 element in kth position is in the position it would be in a sorted array. 25270 All elements smaller than the kth element are moved before this element and 25271 all equal or greater are moved behind it. The ordering of the elements in 25272 the two partitions is undefined. 25273 25274 .. versionadded:: 1.8.0 25275 25276 Parameters 25277 ---------- 25278 kth : int or sequence of ints 25279 Element index to partition by. The kth element value will be in its 25280 final sorted position and all smaller elements will be moved before it 25281 and all equal or greater elements behind it. 25282 The order all elements in the partitions is undefined. 25283 If provided with a sequence of kth it will partition all elements 25284 indexed by kth of them into their sorted position at once. 25285 axis : int, optional 25286 Axis along which to sort. Default is -1, which means sort along the 25287 last axis. 25288 kind : {'introselect'}, optional 25289 Selection algorithm. Default is 'introselect'. 25290 order : list, optional 25291 When `a` is an array with fields defined, this argument specifies 25292 which fields to compare first, second, etc. Not all fields need be 25293 specified. 25294 25295 See Also 25296 -------- 25297 numpy.partition : Return a parititioned copy of an array. 25298 argpartition : Indirect partition. 25299 sort : Full sort. 25300 25301 Notes 25302 ----- 25303 See ``np.partition`` for notes on the different algorithms. 25304 25305 Examples 25306 -------- 25307 >>> a = np.array([3, 4, 2, 1]) 25308 >>> a.partition(a, 3) 25309 >>> a 25310 array([2, 1, 3, 4]) 25311 25312 >>> a.partition((1, 3)) 25313 array([1, 2, 3, 4])""" 25314 return None 25315 def prod(self, axis=None, dtype=None, out=None): 25316 """a.prod(axis=None, dtype=None, out=None) 25317 25318 Return the product of the array elements over the given axis 25319 25320 Refer to `numpy.prod` for full documentation. 25321 25322 See Also 25323 -------- 25324 numpy.prod : equivalent function""" 25325 return None 25326 def ptp(self, axis=None, out=None): 25327 """a.ptp(axis=None, out=None) 25328 25329 Peak to peak (maximum - minimum) value along a given axis. 25330 25331 Refer to `numpy.ptp` for full documentation. 25332 25333 See Also 25334 -------- 25335 numpy.ptp : equivalent function""" 25336 return None 25337 def put(self, indices, values, mode=_raise): 25338 """a.put(indices, values, mode='raise') 25339 25340 Set ``a.flat[n] = values[n]`` for all `n` in indices. 25341 25342 Refer to `numpy.put` for full documentation. 25343 25344 See Also 25345 -------- 25346 numpy.put : equivalent function""" 25347 return None 25348 def ravel(self, order): 25349 """a.ravel([order]) 25350 25351 Return a flattened array. 25352 25353 Refer to `numpy.ravel` for full documentation. 25354 25355 See Also 25356 -------- 25357 numpy.ravel : equivalent function 25358 25359 ndarray.flat : a flat iterator on the array.""" 25360 return None 25361 real = getset_descriptor() 25362 def repeat(self, repeats, axis=None): 25363 """a.repeat(repeats, axis=None) 25364 25365 Repeat elements of an array. 25366 25367 Refer to `numpy.repeat` for full documentation. 25368 25369 See Also 25370 -------- 25371 numpy.repeat : equivalent function""" 25372 return None 25373 def reshape(self, shape, order=C): 25374 """a.reshape(shape, order='C') 25375 25376 Returns an array containing the same data with a new shape. 25377 25378 Refer to `numpy.reshape` for full documentation. 25379 25380 See Also 25381 -------- 25382 numpy.reshape : equivalent function""" 25383 return None 25384 def resize(self, new_shape, refcheck): 25385 """a.resize(new_shape, refcheck=True) 25386 25387 Change shape and size of array in-place. 25388 25389 Parameters 25390 ---------- 25391 new_shape : tuple of ints, or `n` ints 25392 Shape of resized array. 25393 refcheck : bool, optional 25394 If False, reference count will not be checked. Default is True. 25395 25396 Returns 25397 ------- 25398 None 25399 25400 Raises 25401 ------ 25402 ValueError 25403 If `a` does not own its own data or references or views to it exist, 25404 and the data memory must be changed. 25405 25406 SystemError 25407 If the `order` keyword argument is specified. This behaviour is a 25408 bug in NumPy. 25409 25410 See Also 25411 -------- 25412 resize : Return a new array with the specified shape. 25413 25414 Notes 25415 ----- 25416 This reallocates space for the data area if necessary. 25417 25418 Only contiguous arrays (data elements consecutive in memory) can be 25419 resized. 25420 25421 The purpose of the reference count check is to make sure you 25422 do not use this array as a buffer for another Python object and then 25423 reallocate the memory. However, reference counts can increase in 25424 other ways so if you are sure that you have not shared the memory 25425 for this array with another Python object, then you may safely set 25426 `refcheck` to False. 25427 25428 Examples 25429 -------- 25430 Shrinking an array: array is flattened (in the order that the data are 25431 stored in memory), resized, and reshaped: 25432 25433 >>> a = np.array([[0, 1], [2, 3]], order='C') 25434 >>> a.resize((2, 1)) 25435 >>> a 25436 array([[0], 25437 [1]]) 25438 25439 >>> a = np.array([[0, 1], [2, 3]], order='F') 25440 >>> a.resize((2, 1)) 25441 >>> a 25442 array([[0], 25443 [2]]) 25444 25445 Enlarging an array: as above, but missing entries are filled with zeros: 25446 25447 >>> b = np.array([[0, 1], [2, 3]]) 25448 >>> b.resize(2, 3) # new_shape parameter doesn't have to be a tuple 25449 >>> b 25450 array([[0, 1, 2], 25451 [3, 0, 0]]) 25452 25453 Referencing an array prevents resizing... 25454 25455 >>> c = a 25456 >>> a.resize((1, 1)) 25457 Traceback (most recent call last): 25458 ... 25459 ValueError: cannot resize an array that has been referenced ... 25460 25461 Unless `refcheck` is False: 25462 25463 >>> a.resize((1, 1), refcheck=False) 25464 >>> a 25465 array([[0]]) 25466 >>> c 25467 array([[0]])""" 25468 return None 25469 def round(self, decimals=0, out=None): 25470 """a.round(decimals=0, out=None) 25471 25472 Return `a` with each element rounded to the given number of decimals. 25473 25474 Refer to `numpy.around` for full documentation. 25475 25476 See Also 25477 -------- 25478 numpy.around : equivalent function""" 25479 return None 25480 def searchsorted(self, v, side=left, sorter=None): 25481 """a.searchsorted(v, side='left', sorter=None) 25482 25483 Find indices where elements of v should be inserted in a to maintain order. 25484 25485 For full documentation, see `numpy.searchsorted` 25486 25487 See Also 25488 -------- 25489 numpy.searchsorted : equivalent function""" 25490 return None 25491 def setfield(self, val, dtype, offset): 25492 """a.setfield(val, dtype, offset=0) 25493 25494 Put a value into a specified place in a field defined by a data-type. 25495 25496 Place `val` into `a`'s field defined by `dtype` and beginning `offset` 25497 bytes into the field. 25498 25499 Parameters 25500 ---------- 25501 val : object 25502 Value to be placed in field. 25503 dtype : dtype object 25504 Data-type of the field in which to place `val`. 25505 offset : int, optional 25506 The number of bytes into the field at which to place `val`. 25507 25508 Returns 25509 ------- 25510 None 25511 25512 See Also 25513 -------- 25514 getfield 25515 25516 Examples 25517 -------- 25518 >>> x = np.eye(3) 25519 >>> x.getfield(np.float64) 25520 array([[ 1., 0., 0.], 25521 [ 0., 1., 0.], 25522 [ 0., 0., 1.]]) 25523 >>> x.setfield(3, np.int32) 25524 >>> x.getfield(np.int32) 25525 array([[3, 3, 3], 25526 [3, 3, 3], 25527 [3, 3, 3]]) 25528 >>> x 25529 array([[ 1.00000000e+000, 1.48219694e-323, 1.48219694e-323], 25530 [ 1.48219694e-323, 1.00000000e+000, 1.48219694e-323], 25531 [ 1.48219694e-323, 1.48219694e-323, 1.00000000e+000]]) 25532 >>> x.setfield(np.eye(3), np.int32) 25533 >>> x 25534 array([[ 1., 0., 0.], 25535 [ 0., 1., 0.], 25536 [ 0., 0., 1.]])""" 25537 return None 25538 def setflags(self, write, align, uic): 25539 """a.setflags(write=None, align=None, uic=None) 25540 25541 Set array flags WRITEABLE, ALIGNED, and UPDATEIFCOPY, respectively. 25542 25543 These Boolean-valued flags affect how numpy interprets the memory 25544 area used by `a` (see Notes below). The ALIGNED flag can only 25545 be set to True if the data is actually aligned according to the type. 25546 The UPDATEIFCOPY flag can never be set to True. The flag WRITEABLE 25547 can only be set to True if the array owns its own memory, or the 25548 ultimate owner of the memory exposes a writeable buffer interface, 25549 or is a string. (The exception for string is made so that unpickling 25550 can be done without copying memory.) 25551 25552 Parameters 25553 ---------- 25554 write : bool, optional 25555 Describes whether or not `a` can be written to. 25556 align : bool, optional 25557 Describes whether or not `a` is aligned properly for its type. 25558 uic : bool, optional 25559 Describes whether or not `a` is a copy of another "base" array. 25560 25561 Notes 25562 ----- 25563 Array flags provide information about how the memory area used 25564 for the array is to be interpreted. There are 6 Boolean flags 25565 in use, only three of which can be changed by the user: 25566 UPDATEIFCOPY, WRITEABLE, and ALIGNED. 25567 25568 WRITEABLE (W) the data area can be written to; 25569 25570 ALIGNED (A) the data and strides are aligned appropriately for the hardware 25571 (as determined by the compiler); 25572 25573 UPDATEIFCOPY (U) this array is a copy of some other array (referenced 25574 by .base). When this array is deallocated, the base array will be 25575 updated with the contents of this array. 25576 25577 All flags can be accessed using their first (upper case) letter as well 25578 as the full name. 25579 25580 Examples 25581 -------- 25582 >>> y 25583 array([[3, 1, 7], 25584 [2, 0, 0], 25585 [8, 5, 9]]) 25586 >>> y.flags 25587 C_CONTIGUOUS : True 25588 F_CONTIGUOUS : False 25589 OWNDATA : True 25590 WRITEABLE : True 25591 ALIGNED : True 25592 UPDATEIFCOPY : False 25593 >>> y.setflags(write=0, align=0) 25594 >>> y.flags 25595 C_CONTIGUOUS : True 25596 F_CONTIGUOUS : False 25597 OWNDATA : True 25598 WRITEABLE : False 25599 ALIGNED : False 25600 UPDATEIFCOPY : False 25601 >>> y.setflags(uic=1) 25602 Traceback (most recent call last): 25603 File "<stdin>", line 1, in <module> 25604 ValueError: cannot set UPDATEIFCOPY flag to True""" 25605 return None 25606 shape = getset_descriptor() 25607 size = getset_descriptor() 25608 def sort(self, axis, kind, order): 25609 """a.sort(axis=-1, kind='quicksort', order=None) 25610 25611 Sort an array, in-place. 25612 25613 Parameters 25614 ---------- 25615 axis : int, optional 25616 Axis along which to sort. Default is -1, which means sort along the 25617 last axis. 25618 kind : {'quicksort', 'mergesort', 'heapsort'}, optional 25619 Sorting algorithm. Default is 'quicksort'. 25620 order : list, optional 25621 When `a` is an array with fields defined, this argument specifies 25622 which fields to compare first, second, etc. Not all fields need be 25623 specified. 25624 25625 See Also 25626 -------- 25627 numpy.sort : Return a sorted copy of an array. 25628 argsort : Indirect sort. 25629 lexsort : Indirect stable sort on multiple keys. 25630 searchsorted : Find elements in sorted array. 25631 partition: Partial sort. 25632 25633 Notes 25634 ----- 25635 See ``sort`` for notes on the different sorting algorithms. 25636 25637 Examples 25638 -------- 25639 >>> a = np.array([[1,4], [3,1]]) 25640 >>> a.sort(axis=1) 25641 >>> a 25642 array([[1, 4], 25643 [1, 3]]) 25644 >>> a.sort(axis=0) 25645 >>> a 25646 array([[1, 3], 25647 [1, 4]]) 25648 25649 Use the `order` keyword to specify a field to use when sorting a 25650 structured array: 25651 25652 >>> a = np.array([('a', 2), ('c', 1)], dtype=[('x', 'S1'), ('y', int)]) 25653 >>> a.sort(order='y') 25654 >>> a 25655 array([('c', 1), ('a', 2)], 25656 dtype=[('x', '|S1'), ('y', '<i4')])""" 25657 return None 25658 def squeeze(self, axis=None): 25659 """a.squeeze(axis=None) 25660 25661 Remove single-dimensional entries from the shape of `a`. 25662 25663 Refer to `numpy.squeeze` for full documentation. 25664 25665 See Also 25666 -------- 25667 numpy.squeeze : equivalent function""" 25668 return None 25669 def std(self, axis=None, dtype=None, out=None, ddof=0): 25670 """a.std(axis=None, dtype=None, out=None, ddof=0) 25671 25672 Returns the standard deviation of the array elements along given axis. 25673 25674 Refer to `numpy.std` for full documentation. 25675 25676 See Also 25677 -------- 25678 numpy.std : equivalent function""" 25679 return None 25680 strides = getset_descriptor() 25681 def sum(self, axis=None, dtype=None, out=None): 25682 """a.sum(axis=None, dtype=None, out=None) 25683 25684 Return the sum of the array elements over the given axis. 25685 25686 Refer to `numpy.sum` for full documentation. 25687 25688 See Also 25689 -------- 25690 numpy.sum : equivalent function""" 25691 return None 25692 def swapaxes(self, axis1, axis2): 25693 """a.swapaxes(axis1, axis2) 25694 25695 Return a view of the array with `axis1` and `axis2` interchanged. 25696 25697 Refer to `numpy.swapaxes` for full documentation. 25698 25699 See Also 25700 -------- 25701 numpy.swapaxes : equivalent function""" 25702 return None 25703 def take(self, indices, axis=None, out=None, mode=_raise): 25704 """a.take(indices, axis=None, out=None, mode='raise') 25705 25706 Return an array formed from the elements of `a` at the given indices. 25707 25708 Refer to `numpy.take` for full documentation. 25709 25710 See Also 25711 -------- 25712 numpy.take : equivalent function""" 25713 return None 25714 def tofile(self, fid, sep, format): 25715 """a.tofile(fid, sep="", format="%s") 25716 25717 Write array to a file as text or binary (default). 25718 25719 Data is always written in 'C' order, independent of the order of `a`. 25720 The data produced by this method can be recovered using the function 25721 fromfile(). 25722 25723 Parameters 25724 ---------- 25725 fid : file or str 25726 An open file object, or a string containing a filename. 25727 sep : str 25728 Separator between array items for text output. 25729 If "" (empty), a binary file is written, equivalent to 25730 ``file.write(a.tostring())``. 25731 format : str 25732 Format string for text file output. 25733 Each entry in the array is formatted to text by first converting 25734 it to the closest Python type, and then using "format" % item. 25735 25736 Notes 25737 ----- 25738 This is a convenience function for quick storage of array data. 25739 Information on endianness and precision is lost, so this method is not a 25740 good choice for files intended to archive data or transport data between 25741 machines with different endianness. Some of these problems can be overcome 25742 by outputting the data as text files, at the expense of speed and file 25743 size.""" 25744 return None 25745 def tolist(self, _): 25746 """a.tolist() 25747 25748 Return the array as a (possibly nested) list. 25749 25750 Return a copy of the array data as a (nested) Python list. 25751 Data items are converted to the nearest compatible Python type. 25752 25753 Parameters 25754 ---------- 25755 none 25756 25757 Returns 25758 ------- 25759 y : list 25760 The possibly nested list of array elements. 25761 25762 Notes 25763 ----- 25764 The array may be recreated, ``a = np.array(a.tolist())``. 25765 25766 Examples 25767 -------- 25768 >>> a = np.array([1, 2]) 25769 >>> a.tolist() 25770 [1, 2] 25771 >>> a = np.array([[1, 2], [3, 4]]) 25772 >>> list(a) 25773 [array([1, 2]), array([3, 4])] 25774 >>> a.tolist() 25775 [[1, 2], [3, 4]]""" 25776 return list() 25777 def tostring(self, order): 25778 """a.tostring(order='C') 25779 25780 Construct a Python string containing the raw data bytes in the array. 25781 25782 Constructs a Python string showing a copy of the raw contents of 25783 data memory. The string can be produced in either 'C' or 'Fortran', 25784 or 'Any' order (the default is 'C'-order). 'Any' order means C-order 25785 unless the F_CONTIGUOUS flag in the array is set, in which case it 25786 means 'Fortran' order. 25787 25788 Parameters 25789 ---------- 25790 order : {'C', 'F', None}, optional 25791 Order of the data for multidimensional arrays: 25792 C, Fortran, or the same as for the original array. 25793 25794 Returns 25795 ------- 25796 s : str 25797 A Python string exhibiting a copy of `a`'s raw data. 25798 25799 Examples 25800 -------- 25801 >>> x = np.array([[0, 1], [2, 3]]) 25802 >>> x.tostring() 25803 '\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00' 25804 >>> x.tostring('C') == x.tostring() 25805 True 25806 >>> x.tostring('F') 25807 '\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00'""" 25808 return str() 25809 def trace(self, offset=0, axis1=0, axis2=1, dtype=None, out=None): 25810 """a.trace(offset=0, axis1=0, axis2=1, dtype=None, out=None) 25811 25812 Return the sum along diagonals of the array. 25813 25814 Refer to `numpy.trace` for full documentation. 25815 25816 See Also 25817 -------- 25818 numpy.trace : equivalent function""" 25819 return None 25820 def transpose(self, axes): 25821 """a.transpose(*axes) 25822 25823 Returns a view of the array with axes transposed. 25824 25825 For a 1-D array, this has no effect. (To change between column and 25826 row vectors, first cast the 1-D array into a matrix object.) 25827 For a 2-D array, this is the usual matrix transpose. 25828 For an n-D array, if axes are given, their order indicates how the 25829 axes are permuted (see Examples). If axes are not provided and 25830 ``a.shape = (i[0], i[1], ... i[n-2], i[n-1])``, then 25831 ``a.transpose().shape = (i[n-1], i[n-2], ... i[1], i[0])``. 25832 25833 Parameters 25834 ---------- 25835 axes : None, tuple of ints, or `n` ints 25836 25837 * None or no argument: reverses the order of the axes. 25838 25839 * tuple of ints: `i` in the `j`-th place in the tuple means `a`'s 25840 `i`-th axis becomes `a.transpose()`'s `j`-th axis. 25841 25842 * `n` ints: same as an n-tuple of the same ints (this form is 25843 intended simply as a "convenience" alternative to the tuple form) 25844 25845 Returns 25846 ------- 25847 out : ndarray 25848 View of `a`, with axes suitably permuted. 25849 25850 See Also 25851 -------- 25852 ndarray.T : Array property returning the array transposed. 25853 25854 Examples 25855 -------- 25856 >>> a = np.array([[1, 2], [3, 4]]) 25857 >>> a 25858 array([[1, 2], 25859 [3, 4]]) 25860 >>> a.transpose() 25861 array([[1, 3], 25862 [2, 4]]) 25863 >>> a.transpose((1, 0)) 25864 array([[1, 3], 25865 [2, 4]]) 25866 >>> a.transpose(1, 0) 25867 array([[1, 3], 25868 [2, 4]])""" 25869 return ndarray() 25870 def var(self, axis=None, dtype=None, out=None, ddof=0): 25871 """a.var(axis=None, dtype=None, out=None, ddof=0) 25872 25873 Returns the variance of the array elements, along given axis. 25874 25875 Refer to `numpy.var` for full documentation. 25876 25877 See Also 25878 -------- 25879 numpy.var : equivalent function""" 25880 return None 25881 def view(self=None, dtype=None, type=None): 25882 """None""" 25883 return None 25884 def rec_fromcsv(fnamekwargs): 25885 """ 25886 Load ASCII data stored in a comma-separated file. 25887 25888 The returned array is a record array (if ``usemask=False``, see 25889 `recarray`) or a masked record array (if ``usemask=True``, 25890 see `ma.mrecords.MaskedRecords`). 25891 25892 Parameters 25893 ---------- 25894 fname, kwargs : For a description of input parameters, see `genfromtxt`. 25895 25896 See Also 25897 -------- 25898 numpy.genfromtxt : generic function to load ASCII data. 25899 25900 """ 25901 return None 25902 def rec_fromtxt(fnamekwargs): 25903 """ 25904 Load ASCII data from a file and return it in a record array. 25905 25906 If ``usemask=False`` a standard `recarray` is returned, 25907 if ``usemask=True`` a MaskedRecords array is returned. 25908 25909 Parameters 25910 ---------- 25911 fname, kwargs : For a description of input parameters, see `genfromtxt`. 25912 25913 See Also 25914 -------- 25915 numpy.genfromtxt : generic function 25916 25917 Notes 25918 ----- 25919 By default, `dtype` is None, which means that the data-type of the output 25920 array will be determined from the data. 25921 25922 """ 25923 return None 25924 def reciprocal(x, out=None): 25925 """reciprocal(x[, out]) 25926 25927 Return the reciprocal of the argument, element-wise. 25928 25929 Calculates ``1/x``. 25930 25931 Parameters 25932 ---------- 25933 x : array_like 25934 Input array. 25935 25936 Returns 25937 ------- 25938 y : ndarray 25939 Return array. 25940 25941 Notes 25942 ----- 25943 .. note:: 25944 This function is not designed to work with integers. 25945 25946 For integer arguments with absolute value larger than 1 the result is 25947 always zero because of the way Python handles integer division. 25948 For integer zero the result is an overflow. 25949 25950 Examples 25951 -------- 25952 >>> np.reciprocal(2.) 25953 0.5 25954 >>> np.reciprocal([1, 2., 3.33]) 25955 array([ 1. , 0.5 , 0.3003003])""" 25956 return ndarray() 25957 class record: 25958 T = getset_descriptor() 25959 __array_interface__ = getset_descriptor() 25960 __array_priority__ = getset_descriptor() 25961 __array_struct__ = getset_descriptor() 25962 __dict__ = dictproxy() 25963 __doc__ = str() 25964 __module__ = str() 25965 __weakref__ = getset_descriptor() 25966 base = getset_descriptor() 25967 def conj(self, _): 25968 """None""" 25969 return None 25970 data = getset_descriptor() 25971 dtype = getset_descriptor() 25972 flags = getset_descriptor() 25973 flat = getset_descriptor() 25974 def getfield(self, _): 25975 """None""" 25976 return None 25977 imag = getset_descriptor() 25978 itemsize = getset_descriptor() 25979 nbytes = getset_descriptor() 25980 ndim = getset_descriptor() 25981 def newbyteorder(self, new_order): 25982 """newbyteorder(new_order='S') 25983 25984 Return a new `dtype` with a different byte order. 25985 25986 Changes are also made in all fields and sub-arrays of the data type. 25987 25988 The `new_order` code can be any from the following: 25989 25990 * {'<', 'L'} - little endian 25991 * {'>', 'B'} - big endian 25992 * {'=', 'N'} - native order 25993 * 'S' - swap dtype from current to opposite endian 25994 * {'|', 'I'} - ignore (no change to byte order) 25995 25996 Parameters 25997 ---------- 25998 new_order : str, optional 25999 Byte order to force; a value from the byte order specifications 26000 above. The default value ('S') results in swapping the current 26001 byte order. The code does a case-insensitive check on the first 26002 letter of `new_order` for the alternatives above. For example, 26003 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 26004 26005 26006 Returns 26007 ------- 26008 new_dtype : dtype 26009 New `dtype` object with the given change to the byte order.""" 26010 return dtype() 26011 def pprint(self, _): 26012 """Pretty-print all fields.""" 26013 return None 26014 real = getset_descriptor() 26015 def setfield(self, _): 26016 """None""" 26017 return None 26018 shape = getset_descriptor() 26019 size = getset_descriptor() 26020 strides = getset_descriptor() 26021 def remainder(x1, x2, out): 26022 """remainder(x1, x2[, out]) 26023 26024 Return element-wise remainder of division. 26025 26026 Computes ``x1 - floor(x1 / x2) * x2``. 26027 26028 Parameters 26029 ---------- 26030 x1 : array_like 26031 Dividend array. 26032 x2 : array_like 26033 Divisor array. 26034 out : ndarray, optional 26035 Array into which the output is placed. Its type is preserved and it 26036 must be of the right shape to hold the output. See doc.ufuncs. 26037 26038 Returns 26039 ------- 26040 y : ndarray 26041 The remainder of the quotient ``x1/x2``, element-wise. Returns a scalar 26042 if both `x1` and `x2` are scalars. 26043 26044 See Also 26045 -------- 26046 divide, floor 26047 26048 Notes 26049 ----- 26050 Returns 0 when `x2` is 0 and both `x1` and `x2` are (arrays of) integers. 26051 26052 Examples 26053 -------- 26054 >>> np.remainder([4, 7], [2, 3]) 26055 array([0, 1]) 26056 >>> np.remainder(np.arange(7), 5) 26057 array([0, 1, 2, 3, 4, 0, 1])""" 26058 return ndarray() 26059 def repeat(a, repeats=None, axis=None): 26060 """ 26061 Repeat elements of an array. 26062 26063 Parameters 26064 ---------- 26065 a : array_like 26066 Input array. 26067 repeats : {int, array of ints} 26068 The number of repetitions for each element. `repeats` is broadcasted 26069 to fit the shape of the given axis. 26070 axis : int, optional 26071 The axis along which to repeat values. By default, use the 26072 flattened input array, and return a flat output array. 26073 26074 Returns 26075 ------- 26076 repeated_array : ndarray 26077 Output array which has the same shape as `a`, except along 26078 the given axis. 26079 26080 See Also 26081 -------- 26082 tile : Tile an array. 26083 26084 Examples 26085 -------- 26086 >>> x = np.array([[1,2],[3,4]]) 26087 >>> np.repeat(x, 2) 26088 array([1, 1, 2, 2, 3, 3, 4, 4]) 26089 >>> np.repeat(x, 3, axis=1) 26090 array([[1, 1, 1, 2, 2, 2], 26091 [3, 3, 3, 4, 4, 4]]) 26092 >>> np.repeat(x, [1, 2], axis=0) 26093 array([[1, 2], 26094 [3, 4], 26095 [3, 4]]) 26096 26097 """ 26098 return ndarray() 26099 def require(a=None, dtype=None, requirements=None): 26100 """ 26101 Return an ndarray of the provided type that satisfies requirements. 26102 26103 This function is useful to be sure that an array with the correct flags 26104 is returned for passing to compiled code (perhaps through ctypes). 26105 26106 Parameters 26107 ---------- 26108 a : array_like 26109 The object to be converted to a type-and-requirement-satisfying array. 26110 dtype : data-type 26111 The required data-type, the default data-type is float64). 26112 requirements : str or list of str 26113 The requirements list can be any of the following 26114 26115 * 'F_CONTIGUOUS' ('F') - ensure a Fortran-contiguous array 26116 * 'C_CONTIGUOUS' ('C') - ensure a C-contiguous array 26117 * 'ALIGNED' ('A') - ensure a data-type aligned array 26118 * 'WRITEABLE' ('W') - ensure a writable array 26119 * 'OWNDATA' ('O') - ensure an array that owns its own data 26120 26121 See Also 26122 -------- 26123 asarray : Convert input to an ndarray. 26124 asanyarray : Convert to an ndarray, but pass through ndarray subclasses. 26125 ascontiguousarray : Convert input to a contiguous array. 26126 asfortranarray : Convert input to an ndarray with column-major 26127 memory order. 26128 ndarray.flags : Information about the memory layout of the array. 26129 26130 Notes 26131 ----- 26132 The returned array will be guaranteed to have the listed requirements 26133 by making a copy if needed. 26134 26135 Examples 26136 -------- 26137 >>> x = np.arange(6).reshape(2,3) 26138 >>> x.flags 26139 C_CONTIGUOUS : True 26140 F_CONTIGUOUS : False 26141 OWNDATA : False 26142 WRITEABLE : True 26143 ALIGNED : True 26144 UPDATEIFCOPY : False 26145 26146 >>> y = np.require(x, dtype=np.float32, requirements=['A', 'O', 'W', 'F']) 26147 >>> y.flags 26148 C_CONTIGUOUS : False 26149 F_CONTIGUOUS : True 26150 OWNDATA : True 26151 WRITEABLE : True 26152 ALIGNED : True 26153 UPDATEIFCOPY : False 26154 26155 """ 26156 return None 26157 def reshape(a, newshape="C", order="C"): 26158 """ 26159 Gives a new shape to an array without changing its data. 26160 26161 Parameters 26162 ---------- 26163 a : array_like 26164 Array to be reshaped. 26165 newshape : int or tuple of ints 26166 The new shape should be compatible with the original shape. If 26167 an integer, then the result will be a 1-D array of that length. 26168 One shape dimension can be -1. In this case, the value is inferred 26169 from the length of the array and remaining dimensions. 26170 order : {'C', 'F', 'A'}, optional 26171 Read the elements of `a` using this index order, and place the elements 26172 into the reshaped array using this index order. 'C' means to 26173 read / write the elements using C-like index order, with the last axis index 26174 changing fastest, back to the first axis index changing slowest. 'F' 26175 means to read / write the elements using Fortran-like index order, with 26176 the first index changing fastest, and the last index changing slowest. 26177 Note that the 'C' and 'F' options take no account of the memory layout 26178 of the underlying array, and only refer to the order of indexing. 'A' 26179 means to read / write the elements in Fortran-like index order if `a` is 26180 Fortran *contiguous* in memory, C-like order otherwise. 26181 26182 Returns 26183 ------- 26184 reshaped_array : ndarray 26185 This will be a new view object if possible; otherwise, it will 26186 be a copy. Note there is no guarantee of the *memory layout* (C- or 26187 Fortran- contiguous) of the returned array. 26188 26189 See Also 26190 -------- 26191 ndarray.reshape : Equivalent method. 26192 26193 Notes 26194 ----- 26195 It is not always possible to change the shape of an array without 26196 copying the data. If you want an error to be raise if the data is copied, 26197 you should assign the new shape to the shape attribute of the array:: 26198 26199 >>> a = np.zeros((10, 2)) 26200 # A transpose make the array non-contiguous 26201 >>> b = a.T 26202 # Taking a view makes it possible to modify the shape without modifying the 26203 # initial object. 26204 >>> c = b.view() 26205 >>> c.shape = (20) 26206 AttributeError: incompatible shape for a non-contiguous array 26207 26208 The `order` keyword gives the index ordering both for *fetching* the values 26209 from `a`, and then *placing* the values into the output array. For example, 26210 let's say you have an array: 26211 26212 >>> a = np.arange(6).reshape((3, 2)) 26213 >>> a 26214 array([[0, 1], 26215 [2, 3], 26216 [4, 5]]) 26217 26218 You can think of reshaping as first raveling the array (using the given 26219 index order), then inserting the elements from the raveled array into the 26220 new array using the same kind of index ordering as was used for the 26221 raveling. 26222 26223 >>> np.reshape(a, (2, 3)) # C-like index ordering 26224 array([[0, 1, 2], 26225 [3, 4, 5]]) 26226 >>> np.reshape(np.ravel(a), (2, 3)) # equivalent to C ravel then C reshape 26227 array([[0, 1, 2], 26228 [3, 4, 5]]) 26229 >>> np.reshape(a, (2, 3), order='F') # Fortran-like index ordering 26230 array([[0, 4, 3], 26231 [2, 1, 5]]) 26232 >>> np.reshape(np.ravel(a, order='F'), (2, 3), order='F') 26233 array([[0, 4, 3], 26234 [2, 1, 5]]) 26235 26236 Examples 26237 -------- 26238 >>> a = np.array([[1,2,3], [4,5,6]]) 26239 >>> np.reshape(a, 6) 26240 array([1, 2, 3, 4, 5, 6]) 26241 >>> np.reshape(a, 6, order='F') 26242 array([1, 4, 2, 5, 3, 6]) 26243 26244 >>> np.reshape(a, (3,-1)) # the unspecified value is inferred to be 2 26245 array([[1, 2], 26246 [3, 4], 26247 [5, 6]]) 26248 """ 26249 return ndarray() 26250 def resize(a, new_shape): 26251 """ 26252 Return a new array with the specified shape. 26253 26254 If the new array is larger than the original array, then the new 26255 array is filled with repeated copies of `a`. Note that this behavior 26256 is different from a.resize(new_shape) which fills with zeros instead 26257 of repeated copies of `a`. 26258 26259 Parameters 26260 ---------- 26261 a : array_like 26262 Array to be resized. 26263 26264 new_shape : int or tuple of int 26265 Shape of resized array. 26266 26267 Returns 26268 ------- 26269 reshaped_array : ndarray 26270 The new array is formed from the data in the old array, repeated 26271 if necessary to fill out the required number of elements. The 26272 data are repeated in the order that they are stored in memory. 26273 26274 See Also 26275 -------- 26276 ndarray.resize : resize an array in-place. 26277 26278 Examples 26279 -------- 26280 >>> a=np.array([[0,1],[2,3]]) 26281 >>> np.resize(a,(1,4)) 26282 array([[0, 1, 2, 3]]) 26283 >>> np.resize(a,(2,4)) 26284 array([[0, 1, 2, 3], 26285 [0, 1, 2, 3]]) 26286 26287 """ 26288 return ndarray() 26289 def restoredot(): 26290 """Restore `dot`, `vdot`, and `innerproduct` to the default non-BLAS 26291 implementations. 26292 26293 Typically, the user will only need to call this when troubleshooting and 26294 installation problem, reproducing the conditions of a build without an 26295 accelerated BLAS, or when being very careful about benchmarking linear 26296 algebra operations. 26297 26298 See Also 26299 -------- 26300 alterdot : `restoredot` undoes the effects of `alterdot`.""" 26301 return None 26302 def result_type(arrays_and_dtypes): 26303 """result_type(*arrays_and_dtypes) 26304 26305 Returns the type that results from applying the NumPy 26306 type promotion rules to the arguments. 26307 26308 Type promotion in NumPy works similarly to the rules in languages 26309 like C++, with some slight differences. When both scalars and 26310 arrays are used, the array's type takes precedence and the actual value 26311 of the scalar is taken into account. 26312 26313 For example, calculating 3*a, where a is an array of 32-bit floats, 26314 intuitively should result in a 32-bit float output. If the 3 is a 26315 32-bit integer, the NumPy rules indicate it can't convert losslessly 26316 into a 32-bit float, so a 64-bit float should be the result type. 26317 By examining the value of the constant, '3', we see that it fits in 26318 an 8-bit integer, which can be cast losslessly into the 32-bit float. 26319 26320 Parameters 26321 ---------- 26322 arrays_and_dtypes : list of arrays and dtypes 26323 The operands of some operation whose result type is needed. 26324 26325 Returns 26326 ------- 26327 out : dtype 26328 The result type. 26329 26330 See also 26331 -------- 26332 dtype, promote_types, min_scalar_type, can_cast 26333 26334 Notes 26335 ----- 26336 .. versionadded:: 1.6.0 26337 26338 The specific algorithm used is as follows. 26339 26340 Categories are determined by first checking which of boolean, 26341 integer (int/uint), or floating point (float/complex) the maximum 26342 kind of all the arrays and the scalars are. 26343 26344 If there are only scalars or the maximum category of the scalars 26345 is higher than the maximum category of the arrays, 26346 the data types are combined with :func:`promote_types` 26347 to produce the return value. 26348 26349 Otherwise, `min_scalar_type` is called on each array, and 26350 the resulting data types are all combined with :func:`promote_types` 26351 to produce the return value. 26352 26353 The set of int values is not a subset of the uint values for types 26354 with the same number of bits, something not reflected in 26355 :func:`min_scalar_type`, but handled as a special case in `result_type`. 26356 26357 Examples 26358 -------- 26359 >>> np.result_type(3, np.arange(7, dtype='i1')) 26360 dtype('int8') 26361 26362 >>> np.result_type('i4', 'c8') 26363 dtype('complex128') 26364 26365 >>> np.result_type(3.0, -2) 26366 dtype('float64')""" 26367 return dtype() 26368 def right_shift(x1, x2, out=None): 26369 """right_shift(x1, x2[, out]) 26370 26371 Shift the bits of an integer to the right. 26372 26373 Bits are shifted to the right by removing `x2` bits at the right of `x1`. 26374 Since the internal representation of numbers is in binary format, this 26375 operation is equivalent to dividing `x1` by ``2**x2``. 26376 26377 Parameters 26378 ---------- 26379 x1 : array_like, int 26380 Input values. 26381 x2 : array_like, int 26382 Number of bits to remove at the right of `x1`. 26383 26384 Returns 26385 ------- 26386 out : ndarray, int 26387 Return `x1` with bits shifted `x2` times to the right. 26388 26389 See Also 26390 -------- 26391 left_shift : Shift the bits of an integer to the left. 26392 binary_repr : Return the binary representation of the input number 26393 as a string. 26394 26395 Examples 26396 -------- 26397 >>> np.binary_repr(10) 26398 '1010' 26399 >>> np.right_shift(10, 1) 26400 5 26401 >>> np.binary_repr(5) 26402 '101' 26403 26404 >>> np.right_shift(10, [1,2,3]) 26405 array([5, 2, 1])""" 26406 return ndarray() 26407 def rint(x, out=None): 26408 """rint(x[, out]) 26409 26410 Round elements of the array to the nearest integer. 26411 26412 Parameters 26413 ---------- 26414 x : array_like 26415 Input array. 26416 26417 Returns 26418 ------- 26419 out : {ndarray, scalar} 26420 Output array is same shape and type as `x`. 26421 26422 See Also 26423 -------- 26424 ceil, floor, trunc 26425 26426 Examples 26427 -------- 26428 >>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) 26429 >>> np.rint(a) 26430 array([-2., -2., -0., 0., 2., 2., 2.])""" 26431 return ndarray() 26432 def roll(a, shift=None, axis=None): 26433 """ 26434 Roll array elements along a given axis. 26435 26436 Elements that roll beyond the last position are re-introduced at 26437 the first. 26438 26439 Parameters 26440 ---------- 26441 a : array_like 26442 Input array. 26443 shift : int 26444 The number of places by which elements are shifted. 26445 axis : int, optional 26446 The axis along which elements are shifted. By default, the array 26447 is flattened before shifting, after which the original 26448 shape is restored. 26449 26450 Returns 26451 ------- 26452 res : ndarray 26453 Output array, with the same shape as `a`. 26454 26455 See Also 26456 -------- 26457 rollaxis : Roll the specified axis backwards, until it lies in a 26458 given position. 26459 26460 Examples 26461 -------- 26462 >>> x = np.arange(10) 26463 >>> np.roll(x, 2) 26464 array([8, 9, 0, 1, 2, 3, 4, 5, 6, 7]) 26465 26466 >>> x2 = np.reshape(x, (2,5)) 26467 >>> x2 26468 array([[0, 1, 2, 3, 4], 26469 [5, 6, 7, 8, 9]]) 26470 >>> np.roll(x2, 1) 26471 array([[9, 0, 1, 2, 3], 26472 [4, 5, 6, 7, 8]]) 26473 >>> np.roll(x2, 1, axis=0) 26474 array([[5, 6, 7, 8, 9], 26475 [0, 1, 2, 3, 4]]) 26476 >>> np.roll(x2, 1, axis=1) 26477 array([[4, 0, 1, 2, 3], 26478 [9, 5, 6, 7, 8]]) 26479 26480 """ 26481 return ndarray() 26482 def rollaxis(a, axis=0, start=0): 26483 """ 26484 Roll the specified axis backwards, until it lies in a given position. 26485 26486 Parameters 26487 ---------- 26488 a : ndarray 26489 Input array. 26490 axis : int 26491 The axis to roll backwards. The positions of the other axes do not 26492 change relative to one another. 26493 start : int, optional 26494 The axis is rolled until it lies before this position. The default, 26495 0, results in a "complete" roll. 26496 26497 Returns 26498 ------- 26499 res : ndarray 26500 Output array. 26501 26502 See Also 26503 -------- 26504 roll : Roll the elements of an array by a number of positions along a 26505 given axis. 26506 26507 Examples 26508 -------- 26509 >>> a = np.ones((3,4,5,6)) 26510 >>> np.rollaxis(a, 3, 1).shape 26511 (3, 6, 4, 5) 26512 >>> np.rollaxis(a, 2).shape 26513 (5, 3, 4, 6) 26514 >>> np.rollaxis(a, 1, 4).shape 26515 (3, 5, 6, 4) 26516 26517 """ 26518 return ndarray() 26519 def roots(p): 26520 """ 26521 Return the roots of a polynomial with coefficients given in p. 26522 26523 The values in the rank-1 array `p` are coefficients of a polynomial. 26524 If the length of `p` is n+1 then the polynomial is described by:: 26525 26526 p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n] 26527 26528 Parameters 26529 ---------- 26530 p : array_like 26531 Rank-1 array of polynomial coefficients. 26532 26533 Returns 26534 ------- 26535 out : ndarray 26536 An array containing the complex roots of the polynomial. 26537 26538 Raises 26539 ------ 26540 ValueError 26541 When `p` cannot be converted to a rank-1 array. 26542 26543 See also 26544 -------- 26545 poly : Find the coefficients of a polynomial with a given sequence 26546 of roots. 26547 polyval : Evaluate a polynomial at a point. 26548 polyfit : Least squares polynomial fit. 26549 poly1d : A one-dimensional polynomial class. 26550 26551 Notes 26552 ----- 26553 The algorithm relies on computing the eigenvalues of the 26554 companion matrix [1]_. 26555 26556 References 26557 ---------- 26558 .. [1] R. A. Horn & C. R. Johnson, *Matrix Analysis*. Cambridge, UK: 26559 Cambridge University Press, 1999, pp. 146-7. 26560 26561 Examples 26562 -------- 26563 >>> coeff = [3.2, 2, 1] 26564 >>> np.roots(coeff) 26565 array([-0.3125+0.46351241j, -0.3125-0.46351241j]) 26566 26567 """ 26568 return ndarray() 26569 def rot90(m=1, k=1): 26570 """ 26571 Rotate an array by 90 degrees in the counter-clockwise direction. 26572 26573 The first two dimensions are rotated; therefore, the array must be at 26574 least 2-D. 26575 26576 Parameters 26577 ---------- 26578 m : array_like 26579 Array of two or more dimensions. 26580 k : integer 26581 Number of times the array is rotated by 90 degrees. 26582 26583 Returns 26584 ------- 26585 y : ndarray 26586 Rotated array. 26587 26588 See Also 26589 -------- 26590 fliplr : Flip an array horizontally. 26591 flipud : Flip an array vertically. 26592 26593 Examples 26594 -------- 26595 >>> m = np.array([[1,2],[3,4]], int) 26596 >>> m 26597 array([[1, 2], 26598 [3, 4]]) 26599 >>> np.rot90(m) 26600 array([[2, 4], 26601 [1, 3]]) 26602 >>> np.rot90(m, 2) 26603 array([[4, 3], 26604 [2, 1]]) 26605 26606 """ 26607 return ndarray() 26608 def round_(a=None, decimals=0, out=None): 26609 """ 26610 Round an array to the given number of decimals. 26611 26612 Refer to `around` for full documentation. 26613 26614 See Also 26615 -------- 26616 around : equivalent function 26617 26618 """ 26619 return None 26620 def round_(a=None, decimals=0, out=None): 26621 """ 26622 Round an array to the given number of decimals. 26623 26624 Refer to `around` for full documentation. 26625 26626 See Also 26627 -------- 26628 around : equivalent function 26629 26630 """ 26631 return None 26632 def vstack(tup): 26633 """ 26634 Stack arrays in sequence vertically (row wise). 26635 26636 Take a sequence of arrays and stack them vertically to make a single 26637 array. Rebuild arrays divided by `vsplit`. 26638 26639 Parameters 26640 ---------- 26641 tup : sequence of ndarrays 26642 Tuple containing arrays to be stacked. The arrays must have the same 26643 shape along all but the first axis. 26644 26645 Returns 26646 ------- 26647 stacked : ndarray 26648 The array formed by stacking the given arrays. 26649 26650 See Also 26651 -------- 26652 hstack : Stack arrays in sequence horizontally (column wise). 26653 dstack : Stack arrays in sequence depth wise (along third dimension). 26654 concatenate : Join a sequence of arrays together. 26655 vsplit : Split array into a list of multiple sub-arrays vertically. 26656 26657 Notes 26658 ----- 26659 Equivalent to ``np.concatenate(tup, axis=0)`` if `tup` contains arrays that 26660 are at least 2-dimensional. 26661 26662 Examples 26663 -------- 26664 >>> a = np.array([1, 2, 3]) 26665 >>> b = np.array([2, 3, 4]) 26666 >>> np.vstack((a,b)) 26667 array([[1, 2, 3], 26668 [2, 3, 4]]) 26669 26670 >>> a = np.array([[1], [2], [3]]) 26671 >>> b = np.array([[2], [3], [4]]) 26672 >>> np.vstack((a,b)) 26673 array([[1], 26674 [2], 26675 [3], 26676 [2], 26677 [3], 26678 [4]]) 26679 26680 """ 26681 return ndarray() 26682 s_ = IndexExpression() 26683 def safe_eval(source): 26684 """ 26685 Protected string evaluation. 26686 26687 Evaluate a string containing a Python literal expression without 26688 allowing the execution of arbitrary non-literal code. 26689 26690 Parameters 26691 ---------- 26692 source : str 26693 The string to evaluate. 26694 26695 Returns 26696 ------- 26697 obj : object 26698 The result of evaluating `source`. 26699 26700 Raises 26701 ------ 26702 SyntaxError 26703 If the code has invalid Python syntax, or if it contains non-literal 26704 code. 26705 26706 Examples 26707 -------- 26708 >>> np.safe_eval('1') 26709 1 26710 >>> np.safe_eval('[1, 2, 3]') 26711 [1, 2, 3] 26712 >>> np.safe_eval('{"foo": ("bar", 10.0)}') 26713 {'foo': ('bar', 10.0)} 26714 26715 >>> np.safe_eval('import os') 26716 Traceback (most recent call last): 26717 ... 26718 SyntaxError: invalid syntax 26719 26720 >>> np.safe_eval('open("/home/user/.ssh/id_dsa").read()') 26721 Traceback (most recent call last): 26722 ... 26723 SyntaxError: Unsupported source construct: compiler.ast.CallFunc 26724 26725 """ 26726 return object() 26727 def save(file, arr): 26728 """ 26729 Save an array to a binary file in NumPy ``.npy`` format. 26730 26731 Parameters 26732 ---------- 26733 file : file or str 26734 File or filename to which the data is saved. If file is a file-object, 26735 then the filename is unchanged. If file is a string, a ``.npy`` 26736 extension will be appended to the file name if it does not already 26737 have one. 26738 arr : array_like 26739 Array data to be saved. 26740 26741 See Also 26742 -------- 26743 savez : Save several arrays into a ``.npz`` archive 26744 savetxt, load 26745 26746 Notes 26747 ----- 26748 For a description of the ``.npy`` format, see `format`. 26749 26750 Examples 26751 -------- 26752 >>> from tempfile import TemporaryFile 26753 >>> outfile = TemporaryFile() 26754 26755 >>> x = np.arange(10) 26756 >>> np.save(outfile, x) 26757 26758 >>> outfile.seek(0) # Only needed here to simulate closing & reopening file 26759 >>> np.load(outfile) 26760 array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) 26761 26762 """ 26763 return None 26764 def savetxt(fname, X="# ", fmt="%.18e", delimiter=" ", newline=" ", header="", footer="", comments="# "): 26765 """ 26766 Save an array to a text file. 26767 26768 Parameters 26769 ---------- 26770 fname : filename or file handle 26771 If the filename ends in ``.gz``, the file is automatically saved in 26772 compressed gzip format. `loadtxt` understands gzipped files 26773 transparently. 26774 X : array_like 26775 Data to be saved to a text file. 26776 fmt : str or sequence of strs, optional 26777 A single format (%10.5f), a sequence of formats, or a 26778 multi-format string, e.g. 'Iteration %d -- %10.5f', in which 26779 case `delimiter` is ignored. For complex `X`, the legal options 26780 for `fmt` are: 26781 a) a single specifier, `fmt='%.4e'`, resulting in numbers formatted 26782 like `' (%s+%sj)' % (fmt, fmt)` 26783 b) a full string specifying every real and imaginary part, e.g. 26784 `' %.4e %+.4j %.4e %+.4j %.4e %+.4j'` for 3 columns 26785 c) a list of specifiers, one per column - in this case, the real 26786 and imaginary part must have separate specifiers, 26787 e.g. `['%.3e + %.3ej', '(%.15e%+.15ej)']` for 2 columns 26788 delimiter : str, optional 26789 Character separating columns. 26790 newline : str, optional 26791 .. versionadded:: 1.5.0 26792 header : str, optional 26793 String that will be written at the beginning of the file. 26794 .. versionadded:: 1.7.0 26795 footer : str, optional 26796 String that will be written at the end of the file. 26797 .. versionadded:: 1.7.0 26798 comments : str, optional 26799 String that will be prepended to the ``header`` and ``footer`` strings, 26800 to mark them as comments. Default: '# ', as expected by e.g. 26801 ``numpy.loadtxt``. 26802 .. versionadded:: 1.7.0 26803 26804 Character separating lines. 26805 26806 See Also 26807 -------- 26808 save : Save an array to a binary file in NumPy ``.npy`` format 26809 savez : Save several arrays into a ``.npz`` compressed archive 26810 26811 Notes 26812 ----- 26813 Further explanation of the `fmt` parameter 26814 (``%[flag]width[.precision]specifier``): 26815 26816 flags: 26817 ``-`` : left justify 26818 26819 ``+`` : Forces to preceed result with + or -. 26820 26821 ``0`` : Left pad the number with zeros instead of space (see width). 26822 26823 width: 26824 Minimum number of characters to be printed. The value is not truncated 26825 if it has more characters. 26826 26827 precision: 26828 - For integer specifiers (eg. ``d,i,o,x``), the minimum number of 26829 digits. 26830 - For ``e, E`` and ``f`` specifiers, the number of digits to print 26831 after the decimal point. 26832 - For ``g`` and ``G``, the maximum number of significant digits. 26833 - For ``s``, the maximum number of characters. 26834 26835 specifiers: 26836 ``c`` : character 26837 26838 ``d`` or ``i`` : signed decimal integer 26839 26840 ``e`` or ``E`` : scientific notation with ``e`` or ``E``. 26841 26842 ``f`` : decimal floating point 26843 26844 ``g,G`` : use the shorter of ``e,E`` or ``f`` 26845 26846 ``o`` : signed octal 26847 26848 ``s`` : string of characters 26849 26850 ``u`` : unsigned decimal integer 26851 26852 ``x,X`` : unsigned hexadecimal integer 26853 26854 This explanation of ``fmt`` is not complete, for an exhaustive 26855 specification see [1]_. 26856 26857 References 26858 ---------- 26859 .. [1] `Format Specification Mini-Language 26860 <http://docs.python.org/library/string.html# 26861 format-specification-mini-language>`_, Python Documentation. 26862 26863 Examples 26864 -------- 26865 >>> x = y = z = np.arange(0.0,5.0,1.0) 26866 >>> np.savetxt('test.out', x, delimiter=',') # X is an array 26867 >>> np.savetxt('test.out', (x,y,z)) # x,y,z equal sized 1D arrays 26868 >>> np.savetxt('test.out', x, fmt='%1.4e') # use exponential notation 26869 26870 """ 26871 return None 26872 def savez(file, args, kwds): 26873 """ 26874 Save several arrays into a single file in uncompressed ``.npz`` format. 26875 26876 If arguments are passed in with no keywords, the corresponding variable 26877 names, in the .npz file, are 'arr_0', 'arr_1', etc. If keyword arguments 26878 are given, the corresponding variable names, in the ``.npz`` file will 26879 match the keyword names. 26880 26881 Parameters 26882 ---------- 26883 file : str or file 26884 Either the file name (string) or an open file (file-like object) 26885 where the data will be saved. If file is a string, the ``.npz`` 26886 extension will be appended to the file name if it is not already there. 26887 args : Arguments, optional 26888 Arrays to save to the file. Since it is not possible for Python to 26889 know the names of the arrays outside `savez`, the arrays will be saved 26890 with names "arr_0", "arr_1", and so on. These arguments can be any 26891 expression. 26892 kwds : Keyword arguments, optional 26893 Arrays to save to the file. Arrays will be saved in the file with the 26894 keyword names. 26895 26896 Returns 26897 ------- 26898 None 26899 26900 See Also 26901 -------- 26902 save : Save a single array to a binary file in NumPy format. 26903 savetxt : Save an array to a file as plain text. 26904 savez_compressed : Save several arrays into a compressed .npz file format 26905 26906 Notes 26907 ----- 26908 The ``.npz`` file format is a zipped archive of files named after the 26909 variables they contain. The archive is not compressed and each file 26910 in the archive contains one variable in ``.npy`` format. For a 26911 description of the ``.npy`` format, see `format`. 26912 26913 When opening the saved ``.npz`` file with `load` a `NpzFile` object is 26914 returned. This is a dictionary-like object which can be queried for 26915 its list of arrays (with the ``.files`` attribute), and for the arrays 26916 themselves. 26917 26918 Examples 26919 -------- 26920 >>> from tempfile import TemporaryFile 26921 >>> outfile = TemporaryFile() 26922 >>> x = np.arange(10) 26923 >>> y = np.sin(x) 26924 26925 Using `savez` with \*args, the arrays are saved with default names. 26926 26927 >>> np.savez(outfile, x, y) 26928 >>> outfile.seek(0) # Only needed here to simulate closing & reopening file 26929 >>> npzfile = np.load(outfile) 26930 >>> npzfile.files 26931 ['arr_1', 'arr_0'] 26932 >>> npzfile['arr_0'] 26933 array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) 26934 26935 Using `savez` with \**kwds, the arrays are saved with the keyword names. 26936 26937 >>> outfile = TemporaryFile() 26938 >>> np.savez(outfile, x=x, y=y) 26939 >>> outfile.seek(0) 26940 >>> npzfile = np.load(outfile) 26941 >>> npzfile.files 26942 ['y', 'x'] 26943 >>> npzfile['x'] 26944 array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) 26945 26946 """ 26947 return None 26948 def savez_compressed(file, args, kwds): 26949 """ 26950 Save several arrays into a single file in compressed ``.npz`` format. 26951 26952 If keyword arguments are given, then filenames are taken from the keywords. 26953 If arguments are passed in with no keywords, then stored file names are 26954 arr_0, arr_1, etc. 26955 26956 Parameters 26957 ---------- 26958 file : str 26959 File name of .npz file. 26960 args : Arguments 26961 Function arguments. 26962 kwds : Keyword arguments 26963 Keywords. 26964 26965 See Also 26966 -------- 26967 numpy.savez : Save several arrays into an uncompressed .npz file format 26968 26969 """ 26970 return None 26971 def sctype2char(sctype): 26972 """ 26973 Return the string representation of a scalar dtype. 26974 26975 Parameters 26976 ---------- 26977 sctype : scalar dtype or object 26978 If a scalar dtype, the corresponding string character is 26979 returned. If an object, `sctype2char` tries to infer its scalar type 26980 and then return the corresponding string character. 26981 26982 Returns 26983 ------- 26984 typechar : str 26985 The string character corresponding to the scalar type. 26986 26987 Raises 26988 ------ 26989 ValueError 26990 If `sctype` is an object for which the type can not be inferred. 26991 26992 See Also 26993 -------- 26994 obj2sctype, issctype, issubsctype, mintypecode 26995 26996 Examples 26997 -------- 26998 >>> for sctype in [np.int32, np.float, np.complex, np.string_, np.ndarray]: 26999 ... print np.sctype2char(sctype) 27000 l 27001 d 27002 D 27003 S 27004 O 27005 27006 >>> x = np.array([1., 2-1.j]) 27007 >>> np.sctype2char(x) 27008 'D' 27009 >>> np.sctype2char(list) 27010 'O' 27011 27012 """ 27013 return str() 27014 sctypeDict = dict() 27015 sctypeNA = dict() 27016 sctypes = dict() 27017 def searchsorted(a, v=None, side="left", sorter=None): 27018 """ 27019 Find indices where elements should be inserted to maintain order. 27020 27021 Find the indices into a sorted array `a` such that, if the 27022 corresponding elements in `v` were inserted before the indices, the 27023 order of `a` would be preserved. 27024 27025 Parameters 27026 ---------- 27027 a : 1-D array_like 27028 Input array. If `sorter` is None, then it must be sorted in 27029 ascending order, otherwise `sorter` must be an array of indices 27030 that sort it. 27031 v : array_like 27032 Values to insert into `a`. 27033 side : {'left', 'right'}, optional 27034 If 'left', the index of the first suitable location found is given. 27035 If 'right', return the last such index. If there is no suitable 27036 index, return either 0 or N (where N is the length of `a`). 27037 sorter : 1-D array_like, optional 27038 .. versionadded:: 1.7.0 27039 Optional array of integer indices that sort array a into ascending 27040 order. They are typically the result of argsort. 27041 27042 Returns 27043 ------- 27044 indices : array of ints 27045 Array of insertion points with the same shape as `v`. 27046 27047 See Also 27048 -------- 27049 sort : Return a sorted copy of an array. 27050 histogram : Produce histogram from 1-D data. 27051 27052 Notes 27053 ----- 27054 Binary search is used to find the required insertion points. 27055 27056 As of Numpy 1.4.0 `searchsorted` works with real/complex arrays containing 27057 `nan` values. The enhanced sort order is documented in `sort`. 27058 27059 Examples 27060 -------- 27061 >>> np.searchsorted([1,2,3,4,5], 3) 27062 2 27063 >>> np.searchsorted([1,2,3,4,5], 3, side='right') 27064 3 27065 >>> np.searchsorted([1,2,3,4,5], [-10, 10, 2, 3]) 27066 array([0, 5, 1, 2]) 27067 27068 """ 27069 return array() 27070 def select(condlist, choicelist=0, default=0): 27071 """ 27072 Return an array drawn from elements in choicelist, depending on conditions. 27073 27074 Parameters 27075 ---------- 27076 condlist : list of bool ndarrays 27077 The list of conditions which determine from which array in `choicelist` 27078 the output elements are taken. When multiple conditions are satisfied, 27079 the first one encountered in `condlist` is used. 27080 choicelist : list of ndarrays 27081 The list of arrays from which the output elements are taken. It has 27082 to be of the same length as `condlist`. 27083 default : scalar, optional 27084 The element inserted in `output` when all conditions evaluate to False. 27085 27086 Returns 27087 ------- 27088 output : ndarray 27089 The output at position m is the m-th element of the array in 27090 `choicelist` where the m-th element of the corresponding array in 27091 `condlist` is True. 27092 27093 See Also 27094 -------- 27095 where : Return elements from one of two arrays depending on condition. 27096 take, choose, compress, diag, diagonal 27097 27098 Examples 27099 -------- 27100 >>> x = np.arange(10) 27101 >>> condlist = [x<3, x>5] 27102 >>> choicelist = [x, x**2] 27103 >>> np.select(condlist, choicelist) 27104 array([ 0, 1, 2, 0, 0, 0, 36, 49, 64, 81]) 27105 27106 """ 27107 return ndarray() 27108 def set_numeric_ops(op1=func1, op2=func2, more_args=None): 27109 """set_numeric_ops(op1=func1, op2=func2, ...) 27110 27111 Set numerical operators for array objects. 27112 27113 Parameters 27114 ---------- 27115 op1, op2, ... : callable 27116 Each ``op = func`` pair describes an operator to be replaced. 27117 For example, ``add = lambda x, y: np.add(x, y) % 5`` would replace 27118 addition by modulus 5 addition. 27119 27120 Returns 27121 ------- 27122 saved_ops : list of callables 27123 A list of all operators, stored before making replacements. 27124 27125 Notes 27126 ----- 27127 .. WARNING:: 27128 Use with care! Incorrect usage may lead to memory errors. 27129 27130 A function replacing an operator cannot make use of that operator. 27131 For example, when replacing add, you may not use ``+``. Instead, 27132 directly call ufuncs. 27133 27134 Examples 27135 -------- 27136 >>> def add_mod5(x, y): 27137 ... return np.add(x, y) % 5 27138 ... 27139 >>> old_funcs = np.set_numeric_ops(add=add_mod5) 27140 27141 >>> x = np.arange(12).reshape((3, 4)) 27142 >>> x + x 27143 array([[0, 2, 4, 1], 27144 [3, 0, 2, 4], 27145 [1, 3, 0, 2]]) 27146 27147 >>> ignore = np.set_numeric_ops(**old_funcs) # restore operators""" 27148 return list() 27149 def set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, suppress=None, nanstr=None, infstr=None, formatter=None): 27150 """ 27151 Set printing options. 27152 27153 These options determine the way floating point numbers, arrays and 27154 other NumPy objects are displayed. 27155 27156 Parameters 27157 ---------- 27158 precision : int, optional 27159 Number of digits of precision for floating point output (default 8). 27160 threshold : int, optional 27161 Total number of array elements which trigger summarization 27162 rather than full repr (default 1000). 27163 edgeitems : int, optional 27164 Number of array items in summary at beginning and end of 27165 each dimension (default 3). 27166 linewidth : int, optional 27167 The number of characters per line for the purpose of inserting 27168 line breaks (default 75). 27169 suppress : bool, optional 27170 Whether or not suppress printing of small floating point values 27171 using scientific notation (default False). 27172 nanstr : str, optional 27173 String representation of floating point not-a-number (default nan). 27174 infstr : str, optional 27175 String representation of floating point infinity (default inf). 27176 formatter : dict of callables, optional 27177 If not None, the keys should indicate the type(s) that the respective 27178 formatting function applies to. Callables should return a string. 27179 Types that are not specified (by their corresponding keys) are handled 27180 by the default formatters. Individual types for which a formatter 27181 can be set are:: 27182 27183 - 'bool' 27184 - 'int' 27185 - 'timedelta' : a `numpy.timedelta64` 27186 - 'datetime' : a `numpy.datetime64` 27187 - 'float' 27188 - 'longfloat' : 128-bit floats 27189 - 'complexfloat' 27190 - 'longcomplexfloat' : composed of two 128-bit floats 27191 - 'numpy_str' : types `numpy.string_` and `numpy.unicode_` 27192 - 'str' : all other strings 27193 27194 Other keys that can be used to set a group of types at once are:: 27195 27196 - 'all' : sets all types 27197 - 'int_kind' : sets 'int' 27198 - 'float_kind' : sets 'float' and 'longfloat' 27199 - 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat' 27200 - 'str_kind' : sets 'str' and 'numpystr' 27201 27202 See Also 27203 -------- 27204 get_printoptions, set_string_function, array2string 27205 27206 Notes 27207 ----- 27208 `formatter` is always reset with a call to `set_printoptions`. 27209 27210 Examples 27211 -------- 27212 Floating point precision can be set: 27213 27214 >>> np.set_printoptions(precision=4) 27215 >>> print np.array([1.123456789]) 27216 [ 1.1235] 27217 27218 Long arrays can be summarised: 27219 27220 >>> np.set_printoptions(threshold=5) 27221 >>> print np.arange(10) 27222 [0 1 2 ..., 7 8 9] 27223 27224 Small results can be suppressed: 27225 27226 >>> eps = np.finfo(float).eps 27227 >>> x = np.arange(4.) 27228 >>> x**2 - (x + eps)**2 27229 array([ -4.9304e-32, -4.4409e-16, 0.0000e+00, 0.0000e+00]) 27230 >>> np.set_printoptions(suppress=True) 27231 >>> x**2 - (x + eps)**2 27232 array([-0., -0., 0., 0.]) 27233 27234 A custom formatter can be used to display array elements as desired: 27235 27236 >>> np.set_printoptions(formatter={'all':lambda x: 'int: '+str(-x)}) 27237 >>> x = np.arange(3) 27238 >>> x 27239 array([int: 0, int: -1, int: -2]) 27240 >>> np.set_printoptions() # formatter gets reset 27241 >>> x 27242 array([0, 1, 2]) 27243 27244 To put back the default options, you can use: 27245 27246 >>> np.set_printoptions(edgeitems=3,infstr='inf', 27247 ... linewidth=75, nanstr='nan', precision=8, 27248 ... suppress=False, threshold=1000, formatter=None) 27249 """ 27250 return None 27251 def set_string_function(f=True, repr=True): 27252 """ 27253 Set a Python function to be used when pretty printing arrays. 27254 27255 Parameters 27256 ---------- 27257 f : function or None 27258 Function to be used to pretty print arrays. The function should expect 27259 a single array argument and return a string of the representation of 27260 the array. If None, the function is reset to the default NumPy function 27261 to print arrays. 27262 repr : bool, optional 27263 If True (default), the function for pretty printing (``__repr__``) 27264 is set, if False the function that returns the default string 27265 representation (``__str__``) is set. 27266 27267 See Also 27268 -------- 27269 set_printoptions, get_printoptions 27270 27271 Examples 27272 -------- 27273 >>> def pprint(arr): 27274 ... return 'HA! - What are you going to do now?' 27275 ... 27276 >>> np.set_string_function(pprint) 27277 >>> a = np.arange(10) 27278 >>> a 27279 HA! - What are you going to do now? 27280 >>> print a 27281 [0 1 2 3 4 5 6 7 8 9] 27282 27283 We can reset the function to the default: 27284 27285 >>> np.set_string_function(None) 27286 >>> a 27287 array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) 27288 27289 `repr` affects either pretty printing or normal string representation. 27290 Note that ``__repr__`` is still affected by setting ``__str__`` 27291 because the width of each array element in the returned string becomes 27292 equal to the length of the result of ``__str__()``. 27293 27294 >>> x = np.arange(4) 27295 >>> np.set_string_function(lambda x:'random', repr=False) 27296 >>> x.__str__() 27297 'random' 27298 >>> x.__repr__() 27299 'array([ 0, 1, 2, 3])' 27300 27301 """ 27302 return None 27303 def setbufsize(): 27304 """ 27305 Set the size of the buffer used in ufuncs. 27306 27307 Parameters 27308 ---------- 27309 size : int 27310 Size of buffer. 27311 27312 """ 27313 return None 27314 def setdiff1d(ar1, ar2=False, assume_unique=False): 27315 """ 27316 Find the set difference of two arrays. 27317 27318 Return the sorted, unique values in `ar1` that are not in `ar2`. 27319 27320 Parameters 27321 ---------- 27322 ar1 : array_like 27323 Input array. 27324 ar2 : array_like 27325 Input comparison array. 27326 assume_unique : bool 27327 If True, the input arrays are both assumed to be unique, which 27328 can speed up the calculation. Default is False. 27329 27330 Returns 27331 ------- 27332 setdiff1d : ndarray 27333 Sorted 1D array of values in `ar1` that are not in `ar2`. 27334 27335 See Also 27336 -------- 27337 numpy.lib.arraysetops : Module with a number of other functions for 27338 performing set operations on arrays. 27339 27340 Examples 27341 -------- 27342 >>> a = np.array([1, 2, 3, 2, 4, 1]) 27343 >>> b = np.array([3, 4, 5, 6]) 27344 >>> np.setdiff1d(a, b) 27345 array([1, 2]) 27346 27347 """ 27348 return ndarray() 27349 def seterr(all=None, divide=None, over=None, under=None, invalid=None): 27350 """ 27351 Set how floating-point errors are handled. 27352 27353 Note that operations on integer scalar types (such as `int16`) are 27354 handled like floating point, and are affected by these settings. 27355 27356 Parameters 27357 ---------- 27358 all : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional 27359 Set treatment for all types of floating-point errors at once: 27360 27361 - ignore: Take no action when the exception occurs. 27362 - warn: Print a `RuntimeWarning` (via the Python `warnings` module). 27363 - raise: Raise a `FloatingPointError`. 27364 - call: Call a function specified using the `seterrcall` function. 27365 - print: Print a warning directly to ``stdout``. 27366 - log: Record error in a Log object specified by `seterrcall`. 27367 27368 The default is not to change the current behavior. 27369 divide : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional 27370 Treatment for division by zero. 27371 over : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional 27372 Treatment for floating-point overflow. 27373 under : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional 27374 Treatment for floating-point underflow. 27375 invalid : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional 27376 Treatment for invalid floating-point operation. 27377 27378 Returns 27379 ------- 27380 old_settings : dict 27381 Dictionary containing the old settings. 27382 27383 See also 27384 -------- 27385 seterrcall : Set a callback function for the 'call' mode. 27386 geterr, geterrcall, errstate 27387 27388 Notes 27389 ----- 27390 The floating-point exceptions are defined in the IEEE 754 standard [1]: 27391 27392 - Division by zero: infinite result obtained from finite numbers. 27393 - Overflow: result too large to be expressed. 27394 - Underflow: result so close to zero that some precision 27395 was lost. 27396 - Invalid operation: result is not an expressible number, typically 27397 indicates that a NaN was produced. 27398 27399 .. [1] http://en.wikipedia.org/wiki/IEEE_754 27400 27401 Examples 27402 -------- 27403 >>> old_settings = np.seterr(all='ignore') #seterr to known value 27404 >>> np.seterr(over='raise') 27405 {'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore', 27406 'under': 'ignore'} 27407 >>> np.seterr(all='ignore') # reset to default 27408 {'over': 'raise', 'divide': 'ignore', 'invalid': 'ignore', 'under': 'ignore'} 27409 27410 >>> np.int16(32000) * np.int16(3) 27411 30464 27412 >>> old_settings = np.seterr(all='warn', over='raise') 27413 >>> np.int16(32000) * np.int16(3) 27414 Traceback (most recent call last): 27415 File "<stdin>", line 1, in <module> 27416 FloatingPointError: overflow encountered in short_scalars 27417 27418 >>> old_settings = np.seterr(all='print') 27419 >>> np.geterr() 27420 {'over': 'print', 'divide': 'print', 'invalid': 'print', 'under': 'print'} 27421 >>> np.int16(32000) * np.int16(3) 27422 Warning: overflow encountered in short_scalars 27423 30464 27424 27425 """ 27426 return dict() 27427 def seterrcall(func): 27428 """ 27429 Set the floating-point error callback function or log object. 27430 27431 There are two ways to capture floating-point error messages. The first 27432 is to set the error-handler to 'call', using `seterr`. Then, set 27433 the function to call using this function. 27434 27435 The second is to set the error-handler to 'log', using `seterr`. 27436 Floating-point errors then trigger a call to the 'write' method of 27437 the provided object. 27438 27439 Parameters 27440 ---------- 27441 func : callable f(err, flag) or object with write method 27442 Function to call upon floating-point errors ('call'-mode) or 27443 object whose 'write' method is used to log such message ('log'-mode). 27444 27445 The call function takes two arguments. The first is the 27446 type of error (one of "divide", "over", "under", or "invalid"), 27447 and the second is the status flag. The flag is a byte, whose 27448 least-significant bits indicate the status:: 27449 27450 [0 0 0 0 invalid over under invalid] 27451 27452 In other words, ``flags = divide + 2*over + 4*under + 8*invalid``. 27453 27454 If an object is provided, its write method should take one argument, 27455 a string. 27456 27457 Returns 27458 ------- 27459 h : callable, log instance or None 27460 The old error handler. 27461 27462 See Also 27463 -------- 27464 seterr, geterr, geterrcall 27465 27466 Examples 27467 -------- 27468 Callback upon error: 27469 27470 >>> def err_handler(type, flag): 27471 ... print "Floating point error (%s), with flag %s" % (type, flag) 27472 ... 27473 27474 >>> saved_handler = np.seterrcall(err_handler) 27475 >>> save_err = np.seterr(all='call') 27476 27477 >>> np.array([1, 2, 3]) / 0.0 27478 Floating point error (divide by zero), with flag 1 27479 array([ Inf, Inf, Inf]) 27480 27481 >>> np.seterrcall(saved_handler) 27482 <function err_handler at 0x...> 27483 >>> np.seterr(**save_err) 27484 {'over': 'call', 'divide': 'call', 'invalid': 'call', 'under': 'call'} 27485 27486 Log error message: 27487 27488 >>> class Log(object): 27489 ... def write(self, msg): 27490 ... print "LOG: %s" % msg 27491 ... 27492 27493 >>> log = Log() 27494 >>> saved_handler = np.seterrcall(log) 27495 >>> save_err = np.seterr(all='log') 27496 27497 >>> np.array([1, 2, 3]) / 0.0 27498 LOG: Warning: divide by zero encountered in divide 27499 <BLANKLINE> 27500 array([ Inf, Inf, Inf]) 27501 27502 >>> np.seterrcall(saved_handler) 27503 <__main__.Log object at 0x...> 27504 >>> np.seterr(**save_err) 27505 {'over': 'log', 'divide': 'log', 'invalid': 'log', 'under': 'log'} 27506 27507 """ 27508 return callable() if False else None() 27509 def seterrobj(errobj): 27510 """seterrobj(errobj) 27511 27512 Set the object that defines floating-point error handling. 27513 27514 The error object contains all information that defines the error handling 27515 behavior in Numpy. `seterrobj` is used internally by the other 27516 functions that set error handling behavior (`seterr`, `seterrcall`). 27517 27518 Parameters 27519 ---------- 27520 errobj : list 27521 The error object, a list containing three elements: 27522 [internal numpy buffer size, error mask, error callback function]. 27523 27524 The error mask is a single integer that holds the treatment information 27525 on all four floating point errors. The information for each error type 27526 is contained in three bits of the integer. If we print it in base 8, we 27527 can see what treatment is set for "invalid", "under", "over", and 27528 "divide" (in that order). The printed string can be interpreted with 27529 27530 * 0 : 'ignore' 27531 * 1 : 'warn' 27532 * 2 : 'raise' 27533 * 3 : 'call' 27534 * 4 : 'print' 27535 * 5 : 'log' 27536 27537 See Also 27538 -------- 27539 geterrobj, seterr, geterr, seterrcall, geterrcall 27540 getbufsize, setbufsize 27541 27542 Notes 27543 ----- 27544 For complete documentation of the types of floating-point exceptions and 27545 treatment options, see `seterr`. 27546 27547 Examples 27548 -------- 27549 >>> old_errobj = np.geterrobj() # first get the defaults 27550 >>> old_errobj 27551 [10000, 0, None] 27552 27553 >>> def err_handler(type, flag): 27554 ... print "Floating point error (%s), with flag %s" % (type, flag) 27555 ... 27556 >>> new_errobj = [20000, 12, err_handler] 27557 >>> np.seterrobj(new_errobj) 27558 >>> np.base_repr(12, 8) # int for divide=4 ('print') and over=1 ('warn') 27559 '14' 27560 >>> np.geterr() 27561 {'over': 'warn', 'divide': 'print', 'invalid': 'ignore', 'under': 'ignore'} 27562 >>> np.geterrcall() is err_handler 27563 True""" 27564 return None 27565 def setxor1d(ar1, ar2=False, assume_unique=False): 27566 """ 27567 Find the set exclusive-or of two arrays. 27568 27569 Return the sorted, unique values that are in only one (not both) of the 27570 input arrays. 27571 27572 Parameters 27573 ---------- 27574 ar1, ar2 : array_like 27575 Input arrays. 27576 assume_unique : bool 27577 If True, the input arrays are both assumed to be unique, which 27578 can speed up the calculation. Default is False. 27579 27580 Returns 27581 ------- 27582 setxor1d : ndarray 27583 Sorted 1D array of unique values that are in only one of the input 27584 arrays. 27585 27586 Examples 27587 -------- 27588 >>> a = np.array([1, 2, 3, 2, 4]) 27589 >>> b = np.array([2, 3, 5, 7, 5]) 27590 >>> np.setxor1d(a,b) 27591 array([1, 4, 5, 7]) 27592 27593 """ 27594 return ndarray() 27595 def shape(a): 27596 """ 27597 Return the shape of an array. 27598 27599 Parameters 27600 ---------- 27601 a : array_like 27602 Input array. 27603 27604 Returns 27605 ------- 27606 shape : tuple of ints 27607 The elements of the shape tuple give the lengths of the 27608 corresponding array dimensions. 27609 27610 See Also 27611 -------- 27612 alen 27613 ndarray.shape : Equivalent array method. 27614 27615 Examples 27616 -------- 27617 >>> np.shape(np.eye(3)) 27618 (3, 3) 27619 >>> np.shape([[1, 2]]) 27620 (1, 2) 27621 >>> np.shape([0]) 27622 (1,) 27623 >>> np.shape(0) 27624 () 27625 27626 >>> a = np.array([(1, 2), (3, 4)], dtype=[('x', 'i4'), ('y', 'i4')]) 27627 >>> np.shape(a) 27628 (2,) 27629 >>> a.shape 27630 (2,) 27631 27632 """ 27633 return tuple() 27634 class int16: 27635 T = getset_descriptor() 27636 __array_interface__ = getset_descriptor() 27637 __array_priority__ = getset_descriptor() 27638 __array_struct__ = getset_descriptor() 27639 __doc__ = str() 27640 base = getset_descriptor() 27641 def conj(self, _): 27642 """None""" 27643 return None 27644 data = getset_descriptor() 27645 dtype = getset_descriptor() 27646 flags = getset_descriptor() 27647 flat = getset_descriptor() 27648 imag = getset_descriptor() 27649 itemsize = getset_descriptor() 27650 nbytes = getset_descriptor() 27651 ndim = getset_descriptor() 27652 def newbyteorder(self, new_order): 27653 """newbyteorder(new_order='S') 27654 27655 Return a new `dtype` with a different byte order. 27656 27657 Changes are also made in all fields and sub-arrays of the data type. 27658 27659 The `new_order` code can be any from the following: 27660 27661 * {'<', 'L'} - little endian 27662 * {'>', 'B'} - big endian 27663 * {'=', 'N'} - native order 27664 * 'S' - swap dtype from current to opposite endian 27665 * {'|', 'I'} - ignore (no change to byte order) 27666 27667 Parameters 27668 ---------- 27669 new_order : str, optional 27670 Byte order to force; a value from the byte order specifications 27671 above. The default value ('S') results in swapping the current 27672 byte order. The code does a case-insensitive check on the first 27673 letter of `new_order` for the alternatives above. For example, 27674 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 27675 27676 27677 Returns 27678 ------- 27679 new_dtype : dtype 27680 New `dtype` object with the given change to the byte order.""" 27681 return dtype() 27682 real = getset_descriptor() 27683 shape = getset_descriptor() 27684 size = getset_descriptor() 27685 strides = getset_descriptor() 27686 def show(): 27687 """None""" 27688 return None 27689 def sign(x, out=None): 27690 """sign(x[, out]) 27691 27692 Returns an element-wise indication of the sign of a number. 27693 27694 The `sign` function returns ``-1 if x < 0, 0 if x==0, 1 if x > 0``. 27695 27696 Parameters 27697 ---------- 27698 x : array_like 27699 Input values. 27700 27701 Returns 27702 ------- 27703 y : ndarray 27704 The sign of `x`. 27705 27706 Examples 27707 -------- 27708 >>> np.sign([-5., 4.5]) 27709 array([-1., 1.]) 27710 >>> np.sign(0) 27711 0""" 27712 return ndarray() 27713 def signbit(x, out): 27714 """signbit(x[, out]) 27715 27716 Returns element-wise True where signbit is set (less than zero). 27717 27718 Parameters 27719 ---------- 27720 x : array_like 27721 The input value(s). 27722 out : ndarray, optional 27723 Array into which the output is placed. Its type is preserved 27724 and it must be of the right shape to hold the output. 27725 See `doc.ufuncs`. 27726 27727 Returns 27728 ------- 27729 result : ndarray of bool 27730 Output array, or reference to `out` if that was supplied. 27731 27732 Examples 27733 -------- 27734 >>> np.signbit(-1.2) 27735 True 27736 >>> np.signbit(np.array([1, -2.3, 2.1])) 27737 array([False, True, False], dtype=bool)""" 27738 return ndarray() 27739 class signedinteger: 27740 T = getset_descriptor() 27741 __array_interface__ = getset_descriptor() 27742 __array_priority__ = getset_descriptor() 27743 __array_struct__ = getset_descriptor() 27744 __doc__ = None 27745 base = getset_descriptor() 27746 def conj(self, _): 27747 """None""" 27748 return None 27749 data = getset_descriptor() 27750 dtype = getset_descriptor() 27751 flags = getset_descriptor() 27752 flat = getset_descriptor() 27753 imag = getset_descriptor() 27754 itemsize = getset_descriptor() 27755 nbytes = getset_descriptor() 27756 ndim = getset_descriptor() 27757 def newbyteorder(self, new_order): 27758 """newbyteorder(new_order='S') 27759 27760 Return a new `dtype` with a different byte order. 27761 27762 Changes are also made in all fields and sub-arrays of the data type. 27763 27764 The `new_order` code can be any from the following: 27765 27766 * {'<', 'L'} - little endian 27767 * {'>', 'B'} - big endian 27768 * {'=', 'N'} - native order 27769 * 'S' - swap dtype from current to opposite endian 27770 * {'|', 'I'} - ignore (no change to byte order) 27771 27772 Parameters 27773 ---------- 27774 new_order : str, optional 27775 Byte order to force; a value from the byte order specifications 27776 above. The default value ('S') results in swapping the current 27777 byte order. The code does a case-insensitive check on the first 27778 letter of `new_order` for the alternatives above. For example, 27779 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 27780 27781 27782 Returns 27783 ------- 27784 new_dtype : dtype 27785 New `dtype` object with the given change to the byte order.""" 27786 return dtype() 27787 real = getset_descriptor() 27788 shape = getset_descriptor() 27789 size = getset_descriptor() 27790 strides = getset_descriptor() 27791 def sin(x, out=None): 27792 """sin(x[, out]) 27793 27794 Trigonometric sine, element-wise. 27795 27796 Parameters 27797 ---------- 27798 x : array_like 27799 Angle, in radians (:math:`2 \pi` rad equals 360 degrees). 27800 27801 Returns 27802 ------- 27803 y : array_like 27804 The sine of each element of x. 27805 27806 See Also 27807 -------- 27808 arcsin, sinh, cos 27809 27810 Notes 27811 ----- 27812 The sine is one of the fundamental functions of trigonometry 27813 (the mathematical study of triangles). Consider a circle of radius 27814 1 centered on the origin. A ray comes in from the :math:`+x` axis, 27815 makes an angle at the origin (measured counter-clockwise from that 27816 axis), and departs from the origin. The :math:`y` coordinate of 27817 the outgoing ray's intersection with the unit circle is the sine 27818 of that angle. It ranges from -1 for :math:`x=3\pi / 2` to 27819 +1 for :math:`\pi / 2.` The function has zeroes where the angle is 27820 a multiple of :math:`\pi`. Sines of angles between :math:`\pi` and 27821 :math:`2\pi` are negative. The numerous properties of the sine and 27822 related functions are included in any standard trigonometry text. 27823 27824 Examples 27825 -------- 27826 Print sine of one angle: 27827 27828 >>> np.sin(np.pi/2.) 27829 1.0 27830 27831 Print sines of an array of angles given in degrees: 27832 27833 >>> np.sin(np.array((0., 30., 45., 60., 90.)) * np.pi / 180. ) 27834 array([ 0. , 0.5 , 0.70710678, 0.8660254 , 1. ]) 27835 27836 Plot the sine function: 27837 27838 >>> import matplotlib.pylab as plt 27839 >>> x = np.linspace(-np.pi, np.pi, 201) 27840 >>> plt.plot(x, np.sin(x)) 27841 >>> plt.xlabel('Angle [rad]') 27842 >>> plt.ylabel('sin(x)') 27843 >>> plt.axis('tight') 27844 >>> plt.show()""" 27845 return ndarray() 27846 def sinc(x): 27847 """ 27848 Return the sinc function. 27849 27850 The sinc function is :math:`\sin(\pi x)/(\pi x)`. 27851 27852 Parameters 27853 ---------- 27854 x : ndarray 27855 Array (possibly multi-dimensional) of values for which to to 27856 calculate ``sinc(x)``. 27857 27858 Returns 27859 ------- 27860 out : ndarray 27861 ``sinc(x)``, which has the same shape as the input. 27862 27863 Notes 27864 ----- 27865 ``sinc(0)`` is the limit value 1. 27866 27867 The name sinc is short for "sine cardinal" or "sinus cardinalis". 27868 27869 The sinc function is used in various signal processing applications, 27870 including in anti-aliasing, in the construction of a 27871 Lanczos resampling filter, and in interpolation. 27872 27873 For bandlimited interpolation of discrete-time signals, the ideal 27874 interpolation kernel is proportional to the sinc function. 27875 27876 References 27877 ---------- 27878 .. [1] Weisstein, Eric W. "Sinc Function." From MathWorld--A Wolfram Web 27879 Resource. http://mathworld.wolfram.com/SincFunction.html 27880 .. [2] Wikipedia, "Sinc function", 27881 http://en.wikipedia.org/wiki/Sinc_function 27882 27883 Examples 27884 -------- 27885 >>> x = np.linspace(-4, 4, 41) 27886 >>> np.sinc(x) 27887 array([ -3.89804309e-17, -4.92362781e-02, -8.40918587e-02, 27888 -8.90384387e-02, -5.84680802e-02, 3.89804309e-17, 27889 6.68206631e-02, 1.16434881e-01, 1.26137788e-01, 27890 8.50444803e-02, -3.89804309e-17, -1.03943254e-01, 27891 -1.89206682e-01, -2.16236208e-01, -1.55914881e-01, 27892 3.89804309e-17, 2.33872321e-01, 5.04551152e-01, 27893 7.56826729e-01, 9.35489284e-01, 1.00000000e+00, 27894 9.35489284e-01, 7.56826729e-01, 5.04551152e-01, 27895 2.33872321e-01, 3.89804309e-17, -1.55914881e-01, 27896 -2.16236208e-01, -1.89206682e-01, -1.03943254e-01, 27897 -3.89804309e-17, 8.50444803e-02, 1.26137788e-01, 27898 1.16434881e-01, 6.68206631e-02, 3.89804309e-17, 27899 -5.84680802e-02, -8.90384387e-02, -8.40918587e-02, 27900 -4.92362781e-02, -3.89804309e-17]) 27901 27902 >>> plt.plot(x, np.sinc(x)) 27903 [<matplotlib.lines.Line2D object at 0x...>] 27904 >>> plt.title("Sinc Function") 27905 <matplotlib.text.Text object at 0x...> 27906 >>> plt.ylabel("Amplitude") 27907 <matplotlib.text.Text object at 0x...> 27908 >>> plt.xlabel("X") 27909 <matplotlib.text.Text object at 0x...> 27910 >>> plt.show() 27911 27912 It works in 2-D as well: 27913 27914 >>> x = np.linspace(-4, 4, 401) 27915 >>> xx = np.outer(x, x) 27916 >>> plt.imshow(np.sinc(xx)) 27917 <matplotlib.image.AxesImage object at 0x...> 27918 27919 """ 27920 return ndarray() 27921 class float32: 27922 T = getset_descriptor() 27923 __array_interface__ = getset_descriptor() 27924 __array_priority__ = getset_descriptor() 27925 __array_struct__ = getset_descriptor() 27926 __doc__ = str() 27927 base = getset_descriptor() 27928 def conj(self, _): 27929 """None""" 27930 return None 27931 data = getset_descriptor() 27932 dtype = getset_descriptor() 27933 flags = getset_descriptor() 27934 flat = getset_descriptor() 27935 imag = getset_descriptor() 27936 itemsize = getset_descriptor() 27937 nbytes = getset_descriptor() 27938 ndim = getset_descriptor() 27939 def newbyteorder(self, new_order): 27940 """newbyteorder(new_order='S') 27941 27942 Return a new `dtype` with a different byte order. 27943 27944 Changes are also made in all fields and sub-arrays of the data type. 27945 27946 The `new_order` code can be any from the following: 27947 27948 * {'<', 'L'} - little endian 27949 * {'>', 'B'} - big endian 27950 * {'=', 'N'} - native order 27951 * 'S' - swap dtype from current to opposite endian 27952 * {'|', 'I'} - ignore (no change to byte order) 27953 27954 Parameters 27955 ---------- 27956 new_order : str, optional 27957 Byte order to force; a value from the byte order specifications 27958 above. The default value ('S') results in swapping the current 27959 byte order. The code does a case-insensitive check on the first 27960 letter of `new_order` for the alternatives above. For example, 27961 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 27962 27963 27964 Returns 27965 ------- 27966 new_dtype : dtype 27967 New `dtype` object with the given change to the byte order.""" 27968 return dtype() 27969 real = getset_descriptor() 27970 shape = getset_descriptor() 27971 size = getset_descriptor() 27972 strides = getset_descriptor() 27973 class complex64: 27974 T = getset_descriptor() 27975 __array_interface__ = getset_descriptor() 27976 __array_priority__ = getset_descriptor() 27977 __array_struct__ = getset_descriptor() 27978 __doc__ = str() 27979 base = getset_descriptor() 27980 def conj(self, _): 27981 """None""" 27982 return None 27983 data = getset_descriptor() 27984 dtype = getset_descriptor() 27985 flags = getset_descriptor() 27986 flat = getset_descriptor() 27987 imag = getset_descriptor() 27988 itemsize = getset_descriptor() 27989 nbytes = getset_descriptor() 27990 ndim = getset_descriptor() 27991 def newbyteorder(self, new_order): 27992 """newbyteorder(new_order='S') 27993 27994 Return a new `dtype` with a different byte order. 27995 27996 Changes are also made in all fields and sub-arrays of the data type. 27997 27998 The `new_order` code can be any from the following: 27999 28000 * {'<', 'L'} - little endian 28001 * {'>', 'B'} - big endian 28002 * {'=', 'N'} - native order 28003 * 'S' - swap dtype from current to opposite endian 28004 * {'|', 'I'} - ignore (no change to byte order) 28005 28006 Parameters 28007 ---------- 28008 new_order : str, optional 28009 Byte order to force; a value from the byte order specifications 28010 above. The default value ('S') results in swapping the current 28011 byte order. The code does a case-insensitive check on the first 28012 letter of `new_order` for the alternatives above. For example, 28013 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 28014 28015 28016 Returns 28017 ------- 28018 new_dtype : dtype 28019 New `dtype` object with the given change to the byte order.""" 28020 return dtype() 28021 real = getset_descriptor() 28022 shape = getset_descriptor() 28023 size = getset_descriptor() 28024 strides = getset_descriptor() 28025 def sinh(x, out): 28026 """sinh(x[, out]) 28027 28028 Hyperbolic sine, element-wise. 28029 28030 Equivalent to ``1/2 * (np.exp(x) - np.exp(-x))`` or 28031 ``-1j * np.sin(1j*x)``. 28032 28033 Parameters 28034 ---------- 28035 x : array_like 28036 Input array. 28037 out : ndarray, optional 28038 Output array of same shape as `x`. 28039 28040 Returns 28041 ------- 28042 y : ndarray 28043 The corresponding hyperbolic sine values. 28044 28045 Raises 28046 ------ 28047 ValueError: invalid return array shape 28048 if `out` is provided and `out.shape` != `x.shape` (See Examples) 28049 28050 Notes 28051 ----- 28052 If `out` is provided, the function writes the result into it, 28053 and returns a reference to `out`. (See Examples) 28054 28055 References 28056 ---------- 28057 M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions. 28058 New York, NY: Dover, 1972, pg. 83. 28059 28060 Examples 28061 -------- 28062 >>> np.sinh(0) 28063 0.0 28064 >>> np.sinh(np.pi*1j/2) 28065 1j 28066 >>> np.sinh(np.pi*1j) # (exact value is 0) 28067 1.2246063538223773e-016j 28068 >>> # Discrepancy due to vagaries of floating point arithmetic. 28069 28070 >>> # Example of providing the optional output parameter 28071 >>> out2 = np.sinh([0.1], out1) 28072 >>> out2 is out1 28073 True 28074 28075 >>> # Example of ValueError due to provision of shape mis-matched `out` 28076 >>> np.sinh(np.zeros((3,3)),np.zeros((2,2))) 28077 Traceback (most recent call last): 28078 File "<stdin>", line 1, in <module> 28079 ValueError: invalid return array shape""" 28080 return ndarray() 28081 def size(a=None, axis=None): 28082 """ 28083 Return the number of elements along a given axis. 28084 28085 Parameters 28086 ---------- 28087 a : array_like 28088 Input data. 28089 axis : int, optional 28090 Axis along which the elements are counted. By default, give 28091 the total number of elements. 28092 28093 Returns 28094 ------- 28095 element_count : int 28096 Number of elements along the specified axis. 28097 28098 See Also 28099 -------- 28100 shape : dimensions of array 28101 ndarray.shape : dimensions of array 28102 ndarray.size : number of elements in array 28103 28104 Examples 28105 -------- 28106 >>> a = np.array([[1,2,3],[4,5,6]]) 28107 >>> np.size(a) 28108 6 28109 >>> np.size(a,1) 28110 3 28111 >>> np.size(a,0) 28112 2 28113 28114 """ 28115 return int() 28116 def sometrue(a=False, axis=None, out=None, keepdims=False): 28117 """ 28118 Check whether some values are true. 28119 28120 Refer to `any` for full documentation. 28121 28122 See Also 28123 -------- 28124 any : equivalent function 28125 28126 """ 28127 return None 28128 def sort(a=None, axis=-1, kind="quicksort", order=None): 28129 """ 28130 Return a sorted copy of an array. 28131 28132 Parameters 28133 ---------- 28134 a : array_like 28135 Array to be sorted. 28136 axis : int or None, optional 28137 Axis along which to sort. If None, the array is flattened before 28138 sorting. The default is -1, which sorts along the last axis. 28139 kind : {'quicksort', 'mergesort', 'heapsort'}, optional 28140 Sorting algorithm. Default is 'quicksort'. 28141 order : list, optional 28142 When `a` is a structured array, this argument specifies which fields 28143 to compare first, second, and so on. This list does not need to 28144 include all of the fields. 28145 28146 Returns 28147 ------- 28148 sorted_array : ndarray 28149 Array of the same type and shape as `a`. 28150 28151 See Also 28152 -------- 28153 ndarray.sort : Method to sort an array in-place. 28154 argsort : Indirect sort. 28155 lexsort : Indirect stable sort on multiple keys. 28156 searchsorted : Find elements in a sorted array. 28157 partition : Partial sort. 28158 28159 Notes 28160 ----- 28161 The various sorting algorithms are characterized by their average speed, 28162 worst case performance, work space size, and whether they are stable. A 28163 stable sort keeps items with the same key in the same relative 28164 order. The three available algorithms have the following 28165 properties: 28166 28167 =========== ======= ============= ============ ======= 28168 kind speed worst case work space stable 28169 =========== ======= ============= ============ ======= 28170 'quicksort' 1 O(n^2) 0 no 28171 'mergesort' 2 O(n*log(n)) ~n/2 yes 28172 'heapsort' 3 O(n*log(n)) 0 no 28173 =========== ======= ============= ============ ======= 28174 28175 All the sort algorithms make temporary copies of the data when 28176 sorting along any but the last axis. Consequently, sorting along 28177 the last axis is faster and uses less space than sorting along 28178 any other axis. 28179 28180 The sort order for complex numbers is lexicographic. If both the real 28181 and imaginary parts are non-nan then the order is determined by the 28182 real parts except when they are equal, in which case the order is 28183 determined by the imaginary parts. 28184 28185 Previous to numpy 1.4.0 sorting real and complex arrays containing nan 28186 values led to undefined behaviour. In numpy versions >= 1.4.0 nan 28187 values are sorted to the end. The extended sort order is: 28188 28189 * Real: [R, nan] 28190 * Complex: [R + Rj, R + nanj, nan + Rj, nan + nanj] 28191 28192 where R is a non-nan real value. Complex values with the same nan 28193 placements are sorted according to the non-nan part if it exists. 28194 Non-nan values are sorted as before. 28195 28196 Examples 28197 -------- 28198 >>> a = np.array([[1,4],[3,1]]) 28199 >>> np.sort(a) # sort along the last axis 28200 array([[1, 4], 28201 [1, 3]]) 28202 >>> np.sort(a, axis=None) # sort the flattened array 28203 array([1, 1, 3, 4]) 28204 >>> np.sort(a, axis=0) # sort along the first axis 28205 array([[1, 1], 28206 [3, 4]]) 28207 28208 Use the `order` keyword to specify a field to use when sorting a 28209 structured array: 28210 28211 >>> dtype = [('name', 'S10'), ('height', float), ('age', int)] 28212 >>> values = [('Arthur', 1.8, 41), ('Lancelot', 1.9, 38), 28213 ... ('Galahad', 1.7, 38)] 28214 >>> a = np.array(values, dtype=dtype) # create a structured array 28215 >>> np.sort(a, order='height') # doctest: +SKIP 28216 array([('Galahad', 1.7, 38), ('Arthur', 1.8, 41), 28217 ('Lancelot', 1.8999999999999999, 38)], 28218 dtype=[('name', '|S10'), ('height', '<f8'), ('age', '<i4')]) 28219 28220 Sort by age, then height if ages are equal: 28221 28222 >>> np.sort(a, order=['age', 'height']) # doctest: +SKIP 28223 array([('Galahad', 1.7, 38), ('Lancelot', 1.8999999999999999, 38), 28224 ('Arthur', 1.8, 41)], 28225 dtype=[('name', '|S10'), ('height', '<f8'), ('age', '<i4')]) 28226 28227 """ 28228 return ndarray() 28229 def sort_complex(a): 28230 """ 28231 Sort a complex array using the real part first, then the imaginary part. 28232 28233 Parameters 28234 ---------- 28235 a : array_like 28236 Input array 28237 28238 Returns 28239 ------- 28240 out : complex ndarray 28241 Always returns a sorted complex array. 28242 28243 Examples 28244 -------- 28245 >>> np.sort_complex([5, 3, 6, 2, 1]) 28246 array([ 1.+0.j, 2.+0.j, 3.+0.j, 5.+0.j, 6.+0.j]) 28247 28248 >>> np.sort_complex([1 + 2j, 2 - 1j, 3 - 2j, 3 - 3j, 3 + 5j]) 28249 array([ 1.+2.j, 2.-1.j, 3.-3.j, 3.-2.j, 3.+5.j]) 28250 28251 """ 28252 return complex() 28253 def source(object="<open file '../../documentation_files/numpy.py', mode 'w' at 0x7ff32be959c0>", output="<open file '../../documentation_files/numpy.py', mode 'w' at 0x7ff32be959c0>"): 28254 """ 28255 Print or write to a file the source code for a Numpy object. 28256 28257 The source code is only returned for objects written in Python. Many 28258 functions and classes are defined in C and will therefore not return 28259 useful information. 28260 28261 Parameters 28262 ---------- 28263 object : numpy object 28264 Input object. This can be any object (function, class, module, ...). 28265 output : file object, optional 28266 If `output` not supplied then source code is printed to screen 28267 (sys.stdout). File object must be created with either write 'w' or 28268 append 'a' modes. 28269 28270 See Also 28271 -------- 28272 lookfor, info 28273 28274 Examples 28275 -------- 28276 >>> np.source(np.interp) #doctest: +SKIP 28277 In file: /usr/lib/python2.6/dist-packages/numpy/lib/function_base.py 28278 def interp(x, xp, fp, left=None, right=None): 28279 ___.... (full docstring printed)___ 28280 if isinstance(x, (float, int, number)): 28281 return compiled_interp([x], xp, fp, left, right).item() 28282 else: 28283 return compiled_interp(x, xp, fp, left, right) 28284 28285 The source code is only returned for objects written in Python. 28286 28287 >>> np.source(np.array) #doctest: +SKIP 28288 Not available for this object. 28289 28290 """ 28291 return None 28292 def spacing(x, out=None): 28293 """spacing(x[, out]) 28294 28295 Return the distance between x and the nearest adjacent number. 28296 28297 Parameters 28298 ---------- 28299 x1 : array_like 28300 Values to find the spacing of. 28301 28302 Returns 28303 ------- 28304 out : array_like 28305 The spacing of values of `x1`. 28306 28307 Notes 28308 ----- 28309 It can be considered as a generalization of EPS: 28310 ``spacing(np.float64(1)) == np.finfo(np.float64).eps``, and there 28311 should not be any representable number between ``x + spacing(x)`` and 28312 x for any finite x. 28313 28314 Spacing of +- inf and nan is nan. 28315 28316 Examples 28317 -------- 28318 >>> np.spacing(1) == np.finfo(np.float64).eps 28319 True""" 28320 return ndarray() 28321 def split(ary, indices_or_sections=0, axis=0): 28322 """ 28323 Split an array into multiple sub-arrays. 28324 28325 Parameters 28326 ---------- 28327 ary : ndarray 28328 Array to be divided into sub-arrays. 28329 indices_or_sections : int or 1-D array 28330 If `indices_or_sections` is an integer, N, the array will be divided 28331 into N equal arrays along `axis`. If such a split is not possible, 28332 an error is raised. 28333 28334 If `indices_or_sections` is a 1-D array of sorted integers, the entries 28335 indicate where along `axis` the array is split. For example, 28336 ``[2, 3]`` would, for ``axis=0``, result in 28337 28338 - ary[:2] 28339 - ary[2:3] 28340 - ary[3:] 28341 28342 If an index exceeds the dimension of the array along `axis`, 28343 an empty sub-array is returned correspondingly. 28344 axis : int, optional 28345 The axis along which to split, default is 0. 28346 28347 Returns 28348 ------- 28349 sub-arrays : list of ndarrays 28350 A list of sub-arrays. 28351 28352 Raises 28353 ------ 28354 ValueError 28355 If `indices_or_sections` is given as an integer, but 28356 a split does not result in equal division. 28357 28358 See Also 28359 -------- 28360 array_split : Split an array into multiple sub-arrays of equal or 28361 near-equal size. Does not raise an exception if 28362 an equal division cannot be made. 28363 hsplit : Split array into multiple sub-arrays horizontally (column-wise). 28364 vsplit : Split array into multiple sub-arrays vertically (row wise). 28365 dsplit : Split array into multiple sub-arrays along the 3rd axis (depth). 28366 concatenate : Join arrays together. 28367 hstack : Stack arrays in sequence horizontally (column wise). 28368 vstack : Stack arrays in sequence vertically (row wise). 28369 dstack : Stack arrays in sequence depth wise (along third dimension). 28370 28371 Examples 28372 -------- 28373 >>> x = np.arange(9.0) 28374 >>> np.split(x, 3) 28375 [array([ 0., 1., 2.]), array([ 3., 4., 5.]), array([ 6., 7., 8.])] 28376 28377 >>> x = np.arange(8.0) 28378 >>> np.split(x, [3, 5, 6, 10]) 28379 [array([ 0., 1., 2.]), 28380 array([ 3., 4.]), 28381 array([ 5.]), 28382 array([ 6., 7.]), 28383 array([], dtype=float64)] 28384 28385 """ 28386 return list() 28387 def sqrt(x, out): 28388 """sqrt(x[, out]) 28389 28390 Return the positive square-root of an array, element-wise. 28391 28392 Parameters 28393 ---------- 28394 x : array_like 28395 The values whose square-roots are required. 28396 out : ndarray, optional 28397 Alternate array object in which to put the result; if provided, it 28398 must have the same shape as `x` 28399 28400 Returns 28401 ------- 28402 y : ndarray 28403 An array of the same shape as `x`, containing the positive 28404 square-root of each element in `x`. If any element in `x` is 28405 complex, a complex array is returned (and the square-roots of 28406 negative reals are calculated). If all of the elements in `x` 28407 are real, so is `y`, with negative elements returning ``nan``. 28408 If `out` was provided, `y` is a reference to it. 28409 28410 See Also 28411 -------- 28412 lib.scimath.sqrt 28413 A version which returns complex numbers when given negative reals. 28414 28415 Notes 28416 ----- 28417 *sqrt* has--consistent with common convention--as its branch cut the 28418 real "interval" [`-inf`, 0), and is continuous from above on it. 28419 (A branch cut is a curve in the complex plane across which a given 28420 complex function fails to be continuous.) 28421 28422 Examples 28423 -------- 28424 >>> np.sqrt([1,4,9]) 28425 array([ 1., 2., 3.]) 28426 28427 >>> np.sqrt([4, -1, -3+4J]) 28428 array([ 2.+0.j, 0.+1.j, 1.+2.j]) 28429 28430 >>> np.sqrt([4, -1, numpy.inf]) 28431 array([ 2., NaN, Inf])""" 28432 return ndarray() 28433 def square(x, out=None): 28434 """square(x[, out]) 28435 28436 Return the element-wise square of the input. 28437 28438 Parameters 28439 ---------- 28440 x : array_like 28441 Input data. 28442 28443 Returns 28444 ------- 28445 out : ndarray 28446 Element-wise `x*x`, of the same shape and dtype as `x`. 28447 Returns scalar if `x` is a scalar. 28448 28449 See Also 28450 -------- 28451 numpy.linalg.matrix_power 28452 sqrt 28453 power 28454 28455 Examples 28456 -------- 28457 >>> np.square([-1j, 1]) 28458 array([-1.-0.j, 1.+0.j])""" 28459 return ndarray() 28460 def squeeze(a=None, axis=None): 28461 """ 28462 Remove single-dimensional entries from the shape of an array. 28463 28464 Parameters 28465 ---------- 28466 a : array_like 28467 Input data. 28468 axis : None or int or tuple of ints, optional 28469 .. versionadded:: 1.7.0 28470 28471 Selects a subset of the single-dimensional entries in the 28472 shape. If an axis is selected with shape entry greater than 28473 one, an error is raised. 28474 28475 Returns 28476 ------- 28477 squeezed : ndarray 28478 The input array, but with with all or a subset of the 28479 dimensions of length 1 removed. This is always `a` itself 28480 or a view into `a`. 28481 28482 Examples 28483 -------- 28484 >>> x = np.array([[[0], [1], [2]]]) 28485 >>> x.shape 28486 (1, 3, 1) 28487 >>> np.squeeze(x).shape 28488 (3,) 28489 >>> np.squeeze(x, axis=(2,)).shape 28490 (1, 3) 28491 28492 """ 28493 return ndarray() 28494 def std(a=False, axis=None, dtype=None, out=None, ddof=0, keepdims=False): 28495 """ 28496 Compute the standard deviation along the specified axis. 28497 28498 Returns the standard deviation, a measure of the spread of a distribution, 28499 of the array elements. The standard deviation is computed for the 28500 flattened array by default, otherwise over the specified axis. 28501 28502 Parameters 28503 ---------- 28504 a : array_like 28505 Calculate the standard deviation of these values. 28506 axis : int, optional 28507 Axis along which the standard deviation is computed. The default is 28508 to compute the standard deviation of the flattened array. 28509 dtype : dtype, optional 28510 Type to use in computing the standard deviation. For arrays of 28511 integer type the default is float64, for arrays of float types it is 28512 the same as the array type. 28513 out : ndarray, optional 28514 Alternative output array in which to place the result. It must have 28515 the same shape as the expected output but the type (of the calculated 28516 values) will be cast if necessary. 28517 ddof : int, optional 28518 Means Delta Degrees of Freedom. The divisor used in calculations 28519 is ``N - ddof``, where ``N`` represents the number of elements. 28520 By default `ddof` is zero. 28521 keepdims : bool, optional 28522 If this is set to True, the axes which are reduced are left 28523 in the result as dimensions with size one. With this option, 28524 the result will broadcast correctly against the original `arr`. 28525 28526 Returns 28527 ------- 28528 standard_deviation : ndarray, see dtype parameter above. 28529 If `out` is None, return a new array containing the standard deviation, 28530 otherwise return a reference to the output array. 28531 28532 See Also 28533 -------- 28534 var, mean, nanmean, nanstd, nanvar 28535 numpy.doc.ufuncs : Section "Output arguments" 28536 28537 Notes 28538 ----- 28539 The standard deviation is the square root of the average of the squared 28540 deviations from the mean, i.e., ``std = sqrt(mean(abs(x - x.mean())**2))``. 28541 28542 The average squared deviation is normally calculated as 28543 ``x.sum() / N``, where ``N = len(x)``. If, however, `ddof` is specified, 28544 the divisor ``N - ddof`` is used instead. In standard statistical 28545 practice, ``ddof=1`` provides an unbiased estimator of the variance 28546 of the infinite population. ``ddof=0`` provides a maximum likelihood 28547 estimate of the variance for normally distributed variables. The 28548 standard deviation computed in this function is the square root of 28549 the estimated variance, so even with ``ddof=1``, it will not be an 28550 unbiased estimate of the standard deviation per se. 28551 28552 Note that, for complex numbers, `std` takes the absolute 28553 value before squaring, so that the result is always real and nonnegative. 28554 28555 For floating-point input, the *std* is computed using the same 28556 precision the input has. Depending on the input data, this can cause 28557 the results to be inaccurate, especially for float32 (see example below). 28558 Specifying a higher-accuracy accumulator using the `dtype` keyword can 28559 alleviate this issue. 28560 28561 Examples 28562 -------- 28563 >>> a = np.array([[1, 2], [3, 4]]) 28564 >>> np.std(a) 28565 1.1180339887498949 28566 >>> np.std(a, axis=0) 28567 array([ 1., 1.]) 28568 >>> np.std(a, axis=1) 28569 array([ 0.5, 0.5]) 28570 28571 In single precision, std() can be inaccurate: 28572 28573 >>> a = np.zeros((2,512*512), dtype=np.float32) 28574 >>> a[0,:] = 1.0 28575 >>> a[1,:] = 0.1 28576 >>> np.std(a) 28577 0.45172946707416706 28578 28579 Computing the standard deviation in float64 is more accurate: 28580 28581 >>> np.std(a, dtype=np.float64) 28582 0.44999999925552653 28583 28584 """ 28585 return ndarray() 28586 class str: 28587 __doc__ = str() 28588 def _formatter_field_name_split(self, _): 28589 """None""" 28590 return None 28591 def _formatter_parser(self, _): 28592 """None""" 28593 return None 28594 def capitalize(self, _): 28595 """S.capitalize() -> string 28596 28597 Return a copy of the string S with only its first character 28598 capitalized.""" 28599 return None 28600 def center(self, width, fillchar): 28601 """S.center(width[, fillchar]) -> string 28602 28603 Return S centered in a string of length width. Padding is 28604 done using the specified fill character (default is a space)""" 28605 return None 28606 def count(self, sub, start, end): 28607 """S.count(sub[, start[, end]]) -> int 28608 28609 Return the number of non-overlapping occurrences of substring sub in 28610 string S[start:end]. Optional arguments start and end are interpreted 28611 as in slice notation.""" 28612 return None 28613 def decode(self, encoding, errors): 28614 """S.decode([encoding[,errors]]) -> object 28615 28616 Decodes S using the codec registered for encoding. encoding defaults 28617 to the default encoding. errors may be given to set a different error 28618 handling scheme. Default is 'strict' meaning that encoding errors raise 28619 a UnicodeDecodeError. Other possible values are 'ignore' and 'replace' 28620 as well as any other name registered with codecs.register_error that is 28621 able to handle UnicodeDecodeErrors.""" 28622 return None 28623 def encode(self, encoding, errors): 28624 """S.encode([encoding[,errors]]) -> object 28625 28626 Encodes S using the codec registered for encoding. encoding defaults 28627 to the default encoding. errors may be given to set a different error 28628 handling scheme. Default is 'strict' meaning that encoding errors raise 28629 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 28630 'xmlcharrefreplace' as well as any other name registered with 28631 codecs.register_error that is able to handle UnicodeEncodeErrors.""" 28632 return None 28633 def endswith(self, suffix, start, end): 28634 """S.endswith(suffix[, start[, end]]) -> bool 28635 28636 Return True if S ends with the specified suffix, False otherwise. 28637 With optional start, test S beginning at that position. 28638 With optional end, stop comparing S at that position. 28639 suffix can also be a tuple of strings to try.""" 28640 return None 28641 def expandtabs(self, tabsize): 28642 """S.expandtabs([tabsize]) -> string 28643 28644 Return a copy of S where all tab characters are expanded using spaces. 28645 If tabsize is not given, a tab size of 8 characters is assumed.""" 28646 return None 28647 def find(self, sub, start, end): 28648 """S.find(sub [,start [,end]]) -> int 28649 28650 Return the lowest index in S where substring sub is found, 28651 such that sub is contained within S[start:end]. Optional 28652 arguments start and end are interpreted as in slice notation. 28653 28654 Return -1 on failure.""" 28655 return None 28656 def format(self, args, kwargs): 28657 """S.format(*args, **kwargs) -> string 28658 28659 Return a formatted version of S, using substitutions from args and kwargs. 28660 The substitutions are identified by braces ('{' and '}').""" 28661 return None 28662 def index(self, sub, start, end): 28663 """S.index(sub [,start [,end]]) -> int 28664 28665 Like S.find() but raise ValueError when the substring is not found.""" 28666 return None 28667 def isalnum(self, _): 28668 """S.isalnum() -> bool 28669 28670 Return True if all characters in S are alphanumeric 28671 and there is at least one character in S, False otherwise.""" 28672 return None 28673 def isalpha(self, _): 28674 """S.isalpha() -> bool 28675 28676 Return True if all characters in S are alphabetic 28677 and there is at least one character in S, False otherwise.""" 28678 return None 28679 def isdigit(self, _): 28680 """S.isdigit() -> bool 28681 28682 Return True if all characters in S are digits 28683 and there is at least one character in S, False otherwise.""" 28684 return None 28685 def islower(self, _): 28686 """S.islower() -> bool 28687 28688 Return True if all cased characters in S are lowercase and there is 28689 at least one cased character in S, False otherwise.""" 28690 return None 28691 def isspace(self, _): 28692 """S.isspace() -> bool 28693 28694 Return True if all characters in S are whitespace 28695 and there is at least one character in S, False otherwise.""" 28696 return None 28697 def istitle(self, _): 28698 """S.istitle() -> bool 28699 28700 Return True if S is a titlecased string and there is at least one 28701 character in S, i.e. uppercase characters may only follow uncased 28702 characters and lowercase characters only cased ones. Return False 28703 otherwise.""" 28704 return None 28705 def isupper(self, _): 28706 """S.isupper() -> bool 28707 28708 Return True if all cased characters in S are uppercase and there is 28709 at least one cased character in S, False otherwise.""" 28710 return None 28711 def join(self, iterable): 28712 """S.join(iterable) -> string 28713 28714 Return a string which is the concatenation of the strings in the 28715 iterable. The separator between elements is S.""" 28716 return None 28717 def ljust(self, width, fillchar): 28718 """S.ljust(width[, fillchar]) -> string 28719 28720 Return S left-justified in a string of length width. Padding is 28721 done using the specified fill character (default is a space).""" 28722 return None 28723 def lower(self, _): 28724 """S.lower() -> string 28725 28726 Return a copy of the string S converted to lowercase.""" 28727 return None 28728 def lstrip(self, chars): 28729 """S.lstrip([chars]) -> string or unicode 28730 28731 Return a copy of the string S with leading whitespace removed. 28732 If chars is given and not None, remove characters in chars instead. 28733 If chars is unicode, S will be converted to unicode before stripping""" 28734 return None 28735 def partition(self, sep): 28736 """S.partition(sep) -> (head, sep, tail) 28737 28738 Search for the separator sep in S, and return the part before it, 28739 the separator itself, and the part after it. If the separator is not 28740 found, return S and two empty strings.""" 28741 return None 28742 def replace(self, old, new, count): 28743 """S.replace(old, new[, count]) -> string 28744 28745 Return a copy of string S with all occurrences of substring 28746 old replaced by new. If the optional argument count is 28747 given, only the first count occurrences are replaced.""" 28748 return None 28749 def rfind(self, sub, start, end): 28750 """S.rfind(sub [,start [,end]]) -> int 28751 28752 Return the highest index in S where substring sub is found, 28753 such that sub is contained within S[start:end]. Optional 28754 arguments start and end are interpreted as in slice notation. 28755 28756 Return -1 on failure.""" 28757 return None 28758 def rindex(self, sub, start, end): 28759 """S.rindex(sub [,start [,end]]) -> int 28760 28761 Like S.rfind() but raise ValueError when the substring is not found.""" 28762 return None 28763 def rjust(self, width, fillchar): 28764 """S.rjust(width[, fillchar]) -> string 28765 28766 Return S right-justified in a string of length width. Padding is 28767 done using the specified fill character (default is a space)""" 28768 return None 28769 def rpartition(self, sep): 28770 """S.rpartition(sep) -> (head, sep, tail) 28771 28772 Search for the separator sep in S, starting at the end of S, and return 28773 the part before it, the separator itself, and the part after it. If the 28774 separator is not found, return two empty strings and S.""" 28775 return None 28776 def rsplit(self, sep, maxsplit): 28777 """S.rsplit([sep [,maxsplit]]) -> list of strings 28778 28779 Return a list of the words in the string S, using sep as the 28780 delimiter string, starting at the end of the string and working 28781 to the front. If maxsplit is given, at most maxsplit splits are 28782 done. If sep is not specified or is None, any whitespace string 28783 is a separator.""" 28784 return None 28785 def rstrip(self, chars): 28786 """S.rstrip([chars]) -> string or unicode 28787 28788 Return a copy of the string S with trailing whitespace removed. 28789 If chars is given and not None, remove characters in chars instead. 28790 If chars is unicode, S will be converted to unicode before stripping""" 28791 return None 28792 def split(self, sep, maxsplit): 28793 """S.split([sep [,maxsplit]]) -> list of strings 28794 28795 Return a list of the words in the string S, using sep as the 28796 delimiter string. If maxsplit is given, at most maxsplit 28797 splits are done. If sep is not specified or is None, any 28798 whitespace string is a separator and empty strings are removed 28799 from the result.""" 28800 return None 28801 def splitlines(self, keepends=False): 28802 """S.splitlines(keepends=False) -> list of strings 28803 28804 Return a list of the lines in S, breaking at line boundaries. 28805 Line breaks are not included in the resulting list unless keepends 28806 is given and true.""" 28807 return None 28808 def startswith(self, prefix, start, end): 28809 """S.startswith(prefix[, start[, end]]) -> bool 28810 28811 Return True if S starts with the specified prefix, False otherwise. 28812 With optional start, test S beginning at that position. 28813 With optional end, stop comparing S at that position. 28814 prefix can also be a tuple of strings to try.""" 28815 return None 28816 def strip(self, chars): 28817 """S.strip([chars]) -> string or unicode 28818 28819 Return a copy of the string S with leading and trailing 28820 whitespace removed. 28821 If chars is given and not None, remove characters in chars instead. 28822 If chars is unicode, S will be converted to unicode before stripping""" 28823 return None 28824 def swapcase(self, _): 28825 """S.swapcase() -> string 28826 28827 Return a copy of the string S with uppercase characters 28828 converted to lowercase and vice versa.""" 28829 return None 28830 def title(self, _): 28831 """S.title() -> string 28832 28833 Return a titlecased version of S, i.e. words start with uppercase 28834 characters, all remaining cased characters have lowercase.""" 28835 return None 28836 def translate(self, table, deletechars): 28837 """S.translate(table [,deletechars]) -> string 28838 28839 Return a copy of the string S, where all characters occurring 28840 in the optional argument deletechars are removed, and the 28841 remaining characters have been mapped through the given 28842 translation table, which must be a string of length 256 or None. 28843 If the table argument is None, no translation is applied and 28844 the operation simply removes the characters in deletechars.""" 28845 return None 28846 def upper(self, _): 28847 """S.upper() -> string 28848 28849 Return a copy of the string S converted to uppercase.""" 28850 return None 28851 def zfill(self, width): 28852 """S.zfill(width) -> string 28853 28854 Pad a numeric string S with zeros on the left, to fill a field 28855 of the specified width. The string S is never truncated.""" 28856 return None 28857 class string_: 28858 T = getset_descriptor() 28859 __array_interface__ = getset_descriptor() 28860 __array_priority__ = getset_descriptor() 28861 __array_struct__ = getset_descriptor() 28862 __doc__ = None 28863 def _formatter_field_name_split(self, _): 28864 """None""" 28865 return None 28866 def _formatter_parser(self, _): 28867 """None""" 28868 return None 28869 base = getset_descriptor() 28870 def capitalize(self, _): 28871 """S.capitalize() -> string 28872 28873 Return a copy of the string S with only its first character 28874 capitalized.""" 28875 return None 28876 def center(self, width, fillchar): 28877 """S.center(width[, fillchar]) -> string 28878 28879 Return S centered in a string of length width. Padding is 28880 done using the specified fill character (default is a space)""" 28881 return None 28882 def conj(self, _): 28883 """None""" 28884 return None 28885 def count(self, sub, start, end): 28886 """S.count(sub[, start[, end]]) -> int 28887 28888 Return the number of non-overlapping occurrences of substring sub in 28889 string S[start:end]. Optional arguments start and end are interpreted 28890 as in slice notation.""" 28891 return None 28892 data = getset_descriptor() 28893 def decode(self, encoding, errors): 28894 """S.decode([encoding[,errors]]) -> object 28895 28896 Decodes S using the codec registered for encoding. encoding defaults 28897 to the default encoding. errors may be given to set a different error 28898 handling scheme. Default is 'strict' meaning that encoding errors raise 28899 a UnicodeDecodeError. Other possible values are 'ignore' and 'replace' 28900 as well as any other name registered with codecs.register_error that is 28901 able to handle UnicodeDecodeErrors.""" 28902 return None 28903 dtype = getset_descriptor() 28904 def encode(self, encoding, errors): 28905 """S.encode([encoding[,errors]]) -> object 28906 28907 Encodes S using the codec registered for encoding. encoding defaults 28908 to the default encoding. errors may be given to set a different error 28909 handling scheme. Default is 'strict' meaning that encoding errors raise 28910 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 28911 'xmlcharrefreplace' as well as any other name registered with 28912 codecs.register_error that is able to handle UnicodeEncodeErrors.""" 28913 return None 28914 def endswith(self, suffix, start, end): 28915 """S.endswith(suffix[, start[, end]]) -> bool 28916 28917 Return True if S ends with the specified suffix, False otherwise. 28918 With optional start, test S beginning at that position. 28919 With optional end, stop comparing S at that position. 28920 suffix can also be a tuple of strings to try.""" 28921 return None 28922 def expandtabs(self, tabsize): 28923 """S.expandtabs([tabsize]) -> string 28924 28925 Return a copy of S where all tab characters are expanded using spaces. 28926 If tabsize is not given, a tab size of 8 characters is assumed.""" 28927 return None 28928 def find(self, sub, start, end): 28929 """S.find(sub [,start [,end]]) -> int 28930 28931 Return the lowest index in S where substring sub is found, 28932 such that sub is contained within S[start:end]. Optional 28933 arguments start and end are interpreted as in slice notation. 28934 28935 Return -1 on failure.""" 28936 return None 28937 flags = getset_descriptor() 28938 flat = getset_descriptor() 28939 def format(self, args, kwargs): 28940 """S.format(*args, **kwargs) -> string 28941 28942 Return a formatted version of S, using substitutions from args and kwargs. 28943 The substitutions are identified by braces ('{' and '}').""" 28944 return None 28945 imag = getset_descriptor() 28946 def index(self, sub, start, end): 28947 """S.index(sub [,start [,end]]) -> int 28948 28949 Like S.find() but raise ValueError when the substring is not found.""" 28950 return None 28951 def isalnum(self, _): 28952 """S.isalnum() -> bool 28953 28954 Return True if all characters in S are alphanumeric 28955 and there is at least one character in S, False otherwise.""" 28956 return None 28957 def isalpha(self, _): 28958 """S.isalpha() -> bool 28959 28960 Return True if all characters in S are alphabetic 28961 and there is at least one character in S, False otherwise.""" 28962 return None 28963 def isdigit(self, _): 28964 """S.isdigit() -> bool 28965 28966 Return True if all characters in S are digits 28967 and there is at least one character in S, False otherwise.""" 28968 return None 28969 def islower(self, _): 28970 """S.islower() -> bool 28971 28972 Return True if all cased characters in S are lowercase and there is 28973 at least one cased character in S, False otherwise.""" 28974 return None 28975 def isspace(self, _): 28976 """S.isspace() -> bool 28977 28978 Return True if all characters in S are whitespace 28979 and there is at least one character in S, False otherwise.""" 28980 return None 28981 def istitle(self, _): 28982 """S.istitle() -> bool 28983 28984 Return True if S is a titlecased string and there is at least one 28985 character in S, i.e. uppercase characters may only follow uncased 28986 characters and lowercase characters only cased ones. Return False 28987 otherwise.""" 28988 return None 28989 def isupper(self, _): 28990 """S.isupper() -> bool 28991 28992 Return True if all cased characters in S are uppercase and there is 28993 at least one cased character in S, False otherwise.""" 28994 return None 28995 itemsize = getset_descriptor() 28996 def join(self, iterable): 28997 """S.join(iterable) -> string 28998 28999 Return a string which is the concatenation of the strings in the 29000 iterable. The separator between elements is S.""" 29001 return None 29002 def ljust(self, width, fillchar): 29003 """S.ljust(width[, fillchar]) -> string 29004 29005 Return S left-justified in a string of length width. Padding is 29006 done using the specified fill character (default is a space).""" 29007 return None 29008 def lower(self, _): 29009 """S.lower() -> string 29010 29011 Return a copy of the string S converted to lowercase.""" 29012 return None 29013 def lstrip(self, chars): 29014 """S.lstrip([chars]) -> string or unicode 29015 29016 Return a copy of the string S with leading whitespace removed. 29017 If chars is given and not None, remove characters in chars instead. 29018 If chars is unicode, S will be converted to unicode before stripping""" 29019 return None 29020 nbytes = getset_descriptor() 29021 ndim = getset_descriptor() 29022 def newbyteorder(self, new_order): 29023 """newbyteorder(new_order='S') 29024 29025 Return a new `dtype` with a different byte order. 29026 29027 Changes are also made in all fields and sub-arrays of the data type. 29028 29029 The `new_order` code can be any from the following: 29030 29031 * {'<', 'L'} - little endian 29032 * {'>', 'B'} - big endian 29033 * {'=', 'N'} - native order 29034 * 'S' - swap dtype from current to opposite endian 29035 * {'|', 'I'} - ignore (no change to byte order) 29036 29037 Parameters 29038 ---------- 29039 new_order : str, optional 29040 Byte order to force; a value from the byte order specifications 29041 above. The default value ('S') results in swapping the current 29042 byte order. The code does a case-insensitive check on the first 29043 letter of `new_order` for the alternatives above. For example, 29044 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 29045 29046 29047 Returns 29048 ------- 29049 new_dtype : dtype 29050 New `dtype` object with the given change to the byte order.""" 29051 return dtype() 29052 def partition(self, sep): 29053 """S.partition(sep) -> (head, sep, tail) 29054 29055 Search for the separator sep in S, and return the part before it, 29056 the separator itself, and the part after it. If the separator is not 29057 found, return S and two empty strings.""" 29058 return None 29059 real = getset_descriptor() 29060 def replace(self, old, new, count): 29061 """S.replace(old, new[, count]) -> string 29062 29063 Return a copy of string S with all occurrences of substring 29064 old replaced by new. If the optional argument count is 29065 given, only the first count occurrences are replaced.""" 29066 return None 29067 def rfind(self, sub, start, end): 29068 """S.rfind(sub [,start [,end]]) -> int 29069 29070 Return the highest index in S where substring sub is found, 29071 such that sub is contained within S[start:end]. Optional 29072 arguments start and end are interpreted as in slice notation. 29073 29074 Return -1 on failure.""" 29075 return None 29076 def rindex(self, sub, start, end): 29077 """S.rindex(sub [,start [,end]]) -> int 29078 29079 Like S.rfind() but raise ValueError when the substring is not found.""" 29080 return None 29081 def rjust(self, width, fillchar): 29082 """S.rjust(width[, fillchar]) -> string 29083 29084 Return S right-justified in a string of length width. Padding is 29085 done using the specified fill character (default is a space)""" 29086 return None 29087 def rpartition(self, sep): 29088 """S.rpartition(sep) -> (head, sep, tail) 29089 29090 Search for the separator sep in S, starting at the end of S, and return 29091 the part before it, the separator itself, and the part after it. If the 29092 separator is not found, return two empty strings and S.""" 29093 return None 29094 def rsplit(self, sep, maxsplit): 29095 """S.rsplit([sep [,maxsplit]]) -> list of strings 29096 29097 Return a list of the words in the string S, using sep as the 29098 delimiter string, starting at the end of the string and working 29099 to the front. If maxsplit is given, at most maxsplit splits are 29100 done. If sep is not specified or is None, any whitespace string 29101 is a separator.""" 29102 return None 29103 def rstrip(self, chars): 29104 """S.rstrip([chars]) -> string or unicode 29105 29106 Return a copy of the string S with trailing whitespace removed. 29107 If chars is given and not None, remove characters in chars instead. 29108 If chars is unicode, S will be converted to unicode before stripping""" 29109 return None 29110 shape = getset_descriptor() 29111 size = getset_descriptor() 29112 def split(self, sep, maxsplit): 29113 """S.split([sep [,maxsplit]]) -> list of strings 29114 29115 Return a list of the words in the string S, using sep as the 29116 delimiter string. If maxsplit is given, at most maxsplit 29117 splits are done. If sep is not specified or is None, any 29118 whitespace string is a separator and empty strings are removed 29119 from the result.""" 29120 return None 29121 def splitlines(self, keepends=False): 29122 """S.splitlines(keepends=False) -> list of strings 29123 29124 Return a list of the lines in S, breaking at line boundaries. 29125 Line breaks are not included in the resulting list unless keepends 29126 is given and true.""" 29127 return None 29128 def startswith(self, prefix, start, end): 29129 """S.startswith(prefix[, start[, end]]) -> bool 29130 29131 Return True if S starts with the specified prefix, False otherwise. 29132 With optional start, test S beginning at that position. 29133 With optional end, stop comparing S at that position. 29134 prefix can also be a tuple of strings to try.""" 29135 return None 29136 strides = getset_descriptor() 29137 def strip(self, chars): 29138 """S.strip([chars]) -> string or unicode 29139 29140 Return a copy of the string S with leading and trailing 29141 whitespace removed. 29142 If chars is given and not None, remove characters in chars instead. 29143 If chars is unicode, S will be converted to unicode before stripping""" 29144 return None 29145 def swapcase(self, _): 29146 """S.swapcase() -> string 29147 29148 Return a copy of the string S with uppercase characters 29149 converted to lowercase and vice versa.""" 29150 return None 29151 def title(self, _): 29152 """S.title() -> string 29153 29154 Return a titlecased version of S, i.e. words start with uppercase 29155 characters, all remaining cased characters have lowercase.""" 29156 return None 29157 def translate(self, table, deletechars): 29158 """S.translate(table [,deletechars]) -> string 29159 29160 Return a copy of the string S, where all characters occurring 29161 in the optional argument deletechars are removed, and the 29162 remaining characters have been mapped through the given 29163 translation table, which must be a string of length 256 or None. 29164 If the table argument is None, no translation is applied and 29165 the operation simply removes the characters in deletechars.""" 29166 return None 29167 def upper(self, _): 29168 """S.upper() -> string 29169 29170 Return a copy of the string S converted to uppercase.""" 29171 return None 29172 def zfill(self, width): 29173 """S.zfill(width) -> string 29174 29175 Pad a numeric string S with zeros on the left, to fill a field 29176 of the specified width. The string S is never truncated.""" 29177 return None 29178 class string_: 29179 T = getset_descriptor() 29180 __array_interface__ = getset_descriptor() 29181 __array_priority__ = getset_descriptor() 29182 __array_struct__ = getset_descriptor() 29183 __doc__ = None 29184 def _formatter_field_name_split(self, _): 29185 """None""" 29186 return None 29187 def _formatter_parser(self, _): 29188 """None""" 29189 return None 29190 base = getset_descriptor() 29191 def capitalize(self, _): 29192 """S.capitalize() -> string 29193 29194 Return a copy of the string S with only its first character 29195 capitalized.""" 29196 return None 29197 def center(self, width, fillchar): 29198 """S.center(width[, fillchar]) -> string 29199 29200 Return S centered in a string of length width. Padding is 29201 done using the specified fill character (default is a space)""" 29202 return None 29203 def conj(self, _): 29204 """None""" 29205 return None 29206 def count(self, sub, start, end): 29207 """S.count(sub[, start[, end]]) -> int 29208 29209 Return the number of non-overlapping occurrences of substring sub in 29210 string S[start:end]. Optional arguments start and end are interpreted 29211 as in slice notation.""" 29212 return None 29213 data = getset_descriptor() 29214 def decode(self, encoding, errors): 29215 """S.decode([encoding[,errors]]) -> object 29216 29217 Decodes S using the codec registered for encoding. encoding defaults 29218 to the default encoding. errors may be given to set a different error 29219 handling scheme. Default is 'strict' meaning that encoding errors raise 29220 a UnicodeDecodeError. Other possible values are 'ignore' and 'replace' 29221 as well as any other name registered with codecs.register_error that is 29222 able to handle UnicodeDecodeErrors.""" 29223 return None 29224 dtype = getset_descriptor() 29225 def encode(self, encoding, errors): 29226 """S.encode([encoding[,errors]]) -> object 29227 29228 Encodes S using the codec registered for encoding. encoding defaults 29229 to the default encoding. errors may be given to set a different error 29230 handling scheme. Default is 'strict' meaning that encoding errors raise 29231 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 29232 'xmlcharrefreplace' as well as any other name registered with 29233 codecs.register_error that is able to handle UnicodeEncodeErrors.""" 29234 return None 29235 def endswith(self, suffix, start, end): 29236 """S.endswith(suffix[, start[, end]]) -> bool 29237 29238 Return True if S ends with the specified suffix, False otherwise. 29239 With optional start, test S beginning at that position. 29240 With optional end, stop comparing S at that position. 29241 suffix can also be a tuple of strings to try.""" 29242 return None 29243 def expandtabs(self, tabsize): 29244 """S.expandtabs([tabsize]) -> string 29245 29246 Return a copy of S where all tab characters are expanded using spaces. 29247 If tabsize is not given, a tab size of 8 characters is assumed.""" 29248 return None 29249 def find(self, sub, start, end): 29250 """S.find(sub [,start [,end]]) -> int 29251 29252 Return the lowest index in S where substring sub is found, 29253 such that sub is contained within S[start:end]. Optional 29254 arguments start and end are interpreted as in slice notation. 29255 29256 Return -1 on failure.""" 29257 return None 29258 flags = getset_descriptor() 29259 flat = getset_descriptor() 29260 def format(self, args, kwargs): 29261 """S.format(*args, **kwargs) -> string 29262 29263 Return a formatted version of S, using substitutions from args and kwargs. 29264 The substitutions are identified by braces ('{' and '}').""" 29265 return None 29266 imag = getset_descriptor() 29267 def index(self, sub, start, end): 29268 """S.index(sub [,start [,end]]) -> int 29269 29270 Like S.find() but raise ValueError when the substring is not found.""" 29271 return None 29272 def isalnum(self, _): 29273 """S.isalnum() -> bool 29274 29275 Return True if all characters in S are alphanumeric 29276 and there is at least one character in S, False otherwise.""" 29277 return None 29278 def isalpha(self, _): 29279 """S.isalpha() -> bool 29280 29281 Return True if all characters in S are alphabetic 29282 and there is at least one character in S, False otherwise.""" 29283 return None 29284 def isdigit(self, _): 29285 """S.isdigit() -> bool 29286 29287 Return True if all characters in S are digits 29288 and there is at least one character in S, False otherwise.""" 29289 return None 29290 def islower(self, _): 29291 """S.islower() -> bool 29292 29293 Return True if all cased characters in S are lowercase and there is 29294 at least one cased character in S, False otherwise.""" 29295 return None 29296 def isspace(self, _): 29297 """S.isspace() -> bool 29298 29299 Return True if all characters in S are whitespace 29300 and there is at least one character in S, False otherwise.""" 29301 return None 29302 def istitle(self, _): 29303 """S.istitle() -> bool 29304 29305 Return True if S is a titlecased string and there is at least one 29306 character in S, i.e. uppercase characters may only follow uncased 29307 characters and lowercase characters only cased ones. Return False 29308 otherwise.""" 29309 return None 29310 def isupper(self, _): 29311 """S.isupper() -> bool 29312 29313 Return True if all cased characters in S are uppercase and there is 29314 at least one cased character in S, False otherwise.""" 29315 return None 29316 itemsize = getset_descriptor() 29317 def join(self, iterable): 29318 """S.join(iterable) -> string 29319 29320 Return a string which is the concatenation of the strings in the 29321 iterable. The separator between elements is S.""" 29322 return None 29323 def ljust(self, width, fillchar): 29324 """S.ljust(width[, fillchar]) -> string 29325 29326 Return S left-justified in a string of length width. Padding is 29327 done using the specified fill character (default is a space).""" 29328 return None 29329 def lower(self, _): 29330 """S.lower() -> string 29331 29332 Return a copy of the string S converted to lowercase.""" 29333 return None 29334 def lstrip(self, chars): 29335 """S.lstrip([chars]) -> string or unicode 29336 29337 Return a copy of the string S with leading whitespace removed. 29338 If chars is given and not None, remove characters in chars instead. 29339 If chars is unicode, S will be converted to unicode before stripping""" 29340 return None 29341 nbytes = getset_descriptor() 29342 ndim = getset_descriptor() 29343 def newbyteorder(self, new_order): 29344 """newbyteorder(new_order='S') 29345 29346 Return a new `dtype` with a different byte order. 29347 29348 Changes are also made in all fields and sub-arrays of the data type. 29349 29350 The `new_order` code can be any from the following: 29351 29352 * {'<', 'L'} - little endian 29353 * {'>', 'B'} - big endian 29354 * {'=', 'N'} - native order 29355 * 'S' - swap dtype from current to opposite endian 29356 * {'|', 'I'} - ignore (no change to byte order) 29357 29358 Parameters 29359 ---------- 29360 new_order : str, optional 29361 Byte order to force; a value from the byte order specifications 29362 above. The default value ('S') results in swapping the current 29363 byte order. The code does a case-insensitive check on the first 29364 letter of `new_order` for the alternatives above. For example, 29365 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 29366 29367 29368 Returns 29369 ------- 29370 new_dtype : dtype 29371 New `dtype` object with the given change to the byte order.""" 29372 return dtype() 29373 def partition(self, sep): 29374 """S.partition(sep) -> (head, sep, tail) 29375 29376 Search for the separator sep in S, and return the part before it, 29377 the separator itself, and the part after it. If the separator is not 29378 found, return S and two empty strings.""" 29379 return None 29380 real = getset_descriptor() 29381 def replace(self, old, new, count): 29382 """S.replace(old, new[, count]) -> string 29383 29384 Return a copy of string S with all occurrences of substring 29385 old replaced by new. If the optional argument count is 29386 given, only the first count occurrences are replaced.""" 29387 return None 29388 def rfind(self, sub, start, end): 29389 """S.rfind(sub [,start [,end]]) -> int 29390 29391 Return the highest index in S where substring sub is found, 29392 such that sub is contained within S[start:end]. Optional 29393 arguments start and end are interpreted as in slice notation. 29394 29395 Return -1 on failure.""" 29396 return None 29397 def rindex(self, sub, start, end): 29398 """S.rindex(sub [,start [,end]]) -> int 29399 29400 Like S.rfind() but raise ValueError when the substring is not found.""" 29401 return None 29402 def rjust(self, width, fillchar): 29403 """S.rjust(width[, fillchar]) -> string 29404 29405 Return S right-justified in a string of length width. Padding is 29406 done using the specified fill character (default is a space)""" 29407 return None 29408 def rpartition(self, sep): 29409 """S.rpartition(sep) -> (head, sep, tail) 29410 29411 Search for the separator sep in S, starting at the end of S, and return 29412 the part before it, the separator itself, and the part after it. If the 29413 separator is not found, return two empty strings and S.""" 29414 return None 29415 def rsplit(self, sep, maxsplit): 29416 """S.rsplit([sep [,maxsplit]]) -> list of strings 29417 29418 Return a list of the words in the string S, using sep as the 29419 delimiter string, starting at the end of the string and working 29420 to the front. If maxsplit is given, at most maxsplit splits are 29421 done. If sep is not specified or is None, any whitespace string 29422 is a separator.""" 29423 return None 29424 def rstrip(self, chars): 29425 """S.rstrip([chars]) -> string or unicode 29426 29427 Return a copy of the string S with trailing whitespace removed. 29428 If chars is given and not None, remove characters in chars instead. 29429 If chars is unicode, S will be converted to unicode before stripping""" 29430 return None 29431 shape = getset_descriptor() 29432 size = getset_descriptor() 29433 def split(self, sep, maxsplit): 29434 """S.split([sep [,maxsplit]]) -> list of strings 29435 29436 Return a list of the words in the string S, using sep as the 29437 delimiter string. If maxsplit is given, at most maxsplit 29438 splits are done. If sep is not specified or is None, any 29439 whitespace string is a separator and empty strings are removed 29440 from the result.""" 29441 return None 29442 def splitlines(self, keepends=False): 29443 """S.splitlines(keepends=False) -> list of strings 29444 29445 Return a list of the lines in S, breaking at line boundaries. 29446 Line breaks are not included in the resulting list unless keepends 29447 is given and true.""" 29448 return None 29449 def startswith(self, prefix, start, end): 29450 """S.startswith(prefix[, start[, end]]) -> bool 29451 29452 Return True if S starts with the specified prefix, False otherwise. 29453 With optional start, test S beginning at that position. 29454 With optional end, stop comparing S at that position. 29455 prefix can also be a tuple of strings to try.""" 29456 return None 29457 strides = getset_descriptor() 29458 def strip(self, chars): 29459 """S.strip([chars]) -> string or unicode 29460 29461 Return a copy of the string S with leading and trailing 29462 whitespace removed. 29463 If chars is given and not None, remove characters in chars instead. 29464 If chars is unicode, S will be converted to unicode before stripping""" 29465 return None 29466 def swapcase(self, _): 29467 """S.swapcase() -> string 29468 29469 Return a copy of the string S with uppercase characters 29470 converted to lowercase and vice versa.""" 29471 return None 29472 def title(self, _): 29473 """S.title() -> string 29474 29475 Return a titlecased version of S, i.e. words start with uppercase 29476 characters, all remaining cased characters have lowercase.""" 29477 return None 29478 def translate(self, table, deletechars): 29479 """S.translate(table [,deletechars]) -> string 29480 29481 Return a copy of the string S, where all characters occurring 29482 in the optional argument deletechars are removed, and the 29483 remaining characters have been mapped through the given 29484 translation table, which must be a string of length 256 or None. 29485 If the table argument is None, no translation is applied and 29486 the operation simply removes the characters in deletechars.""" 29487 return None 29488 def upper(self, _): 29489 """S.upper() -> string 29490 29491 Return a copy of the string S converted to uppercase.""" 29492 return None 29493 def zfill(self, width): 29494 """S.zfill(width) -> string 29495 29496 Pad a numeric string S with zeros on the left, to fill a field 29497 of the specified width. The string S is never truncated.""" 29498 return None 29499 class string_: 29500 T = getset_descriptor() 29501 __array_interface__ = getset_descriptor() 29502 __array_priority__ = getset_descriptor() 29503 __array_struct__ = getset_descriptor() 29504 __doc__ = None 29505 def _formatter_field_name_split(self, _): 29506 """None""" 29507 return None 29508 def _formatter_parser(self, _): 29509 """None""" 29510 return None 29511 base = getset_descriptor() 29512 def capitalize(self, _): 29513 """S.capitalize() -> string 29514 29515 Return a copy of the string S with only its first character 29516 capitalized.""" 29517 return None 29518 def center(self, width, fillchar): 29519 """S.center(width[, fillchar]) -> string 29520 29521 Return S centered in a string of length width. Padding is 29522 done using the specified fill character (default is a space)""" 29523 return None 29524 def conj(self, _): 29525 """None""" 29526 return None 29527 def count(self, sub, start, end): 29528 """S.count(sub[, start[, end]]) -> int 29529 29530 Return the number of non-overlapping occurrences of substring sub in 29531 string S[start:end]. Optional arguments start and end are interpreted 29532 as in slice notation.""" 29533 return None 29534 data = getset_descriptor() 29535 def decode(self, encoding, errors): 29536 """S.decode([encoding[,errors]]) -> object 29537 29538 Decodes S using the codec registered for encoding. encoding defaults 29539 to the default encoding. errors may be given to set a different error 29540 handling scheme. Default is 'strict' meaning that encoding errors raise 29541 a UnicodeDecodeError. Other possible values are 'ignore' and 'replace' 29542 as well as any other name registered with codecs.register_error that is 29543 able to handle UnicodeDecodeErrors.""" 29544 return None 29545 dtype = getset_descriptor() 29546 def encode(self, encoding, errors): 29547 """S.encode([encoding[,errors]]) -> object 29548 29549 Encodes S using the codec registered for encoding. encoding defaults 29550 to the default encoding. errors may be given to set a different error 29551 handling scheme. Default is 'strict' meaning that encoding errors raise 29552 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 29553 'xmlcharrefreplace' as well as any other name registered with 29554 codecs.register_error that is able to handle UnicodeEncodeErrors.""" 29555 return None 29556 def endswith(self, suffix, start, end): 29557 """S.endswith(suffix[, start[, end]]) -> bool 29558 29559 Return True if S ends with the specified suffix, False otherwise. 29560 With optional start, test S beginning at that position. 29561 With optional end, stop comparing S at that position. 29562 suffix can also be a tuple of strings to try.""" 29563 return None 29564 def expandtabs(self, tabsize): 29565 """S.expandtabs([tabsize]) -> string 29566 29567 Return a copy of S where all tab characters are expanded using spaces. 29568 If tabsize is not given, a tab size of 8 characters is assumed.""" 29569 return None 29570 def find(self, sub, start, end): 29571 """S.find(sub [,start [,end]]) -> int 29572 29573 Return the lowest index in S where substring sub is found, 29574 such that sub is contained within S[start:end]. Optional 29575 arguments start and end are interpreted as in slice notation. 29576 29577 Return -1 on failure.""" 29578 return None 29579 flags = getset_descriptor() 29580 flat = getset_descriptor() 29581 def format(self, args, kwargs): 29582 """S.format(*args, **kwargs) -> string 29583 29584 Return a formatted version of S, using substitutions from args and kwargs. 29585 The substitutions are identified by braces ('{' and '}').""" 29586 return None 29587 imag = getset_descriptor() 29588 def index(self, sub, start, end): 29589 """S.index(sub [,start [,end]]) -> int 29590 29591 Like S.find() but raise ValueError when the substring is not found.""" 29592 return None 29593 def isalnum(self, _): 29594 """S.isalnum() -> bool 29595 29596 Return True if all characters in S are alphanumeric 29597 and there is at least one character in S, False otherwise.""" 29598 return None 29599 def isalpha(self, _): 29600 """S.isalpha() -> bool 29601 29602 Return True if all characters in S are alphabetic 29603 and there is at least one character in S, False otherwise.""" 29604 return None 29605 def isdigit(self, _): 29606 """S.isdigit() -> bool 29607 29608 Return True if all characters in S are digits 29609 and there is at least one character in S, False otherwise.""" 29610 return None 29611 def islower(self, _): 29612 """S.islower() -> bool 29613 29614 Return True if all cased characters in S are lowercase and there is 29615 at least one cased character in S, False otherwise.""" 29616 return None 29617 def isspace(self, _): 29618 """S.isspace() -> bool 29619 29620 Return True if all characters in S are whitespace 29621 and there is at least one character in S, False otherwise.""" 29622 return None 29623 def istitle(self, _): 29624 """S.istitle() -> bool 29625 29626 Return True if S is a titlecased string and there is at least one 29627 character in S, i.e. uppercase characters may only follow uncased 29628 characters and lowercase characters only cased ones. Return False 29629 otherwise.""" 29630 return None 29631 def isupper(self, _): 29632 """S.isupper() -> bool 29633 29634 Return True if all cased characters in S are uppercase and there is 29635 at least one cased character in S, False otherwise.""" 29636 return None 29637 itemsize = getset_descriptor() 29638 def join(self, iterable): 29639 """S.join(iterable) -> string 29640 29641 Return a string which is the concatenation of the strings in the 29642 iterable. The separator between elements is S.""" 29643 return None 29644 def ljust(self, width, fillchar): 29645 """S.ljust(width[, fillchar]) -> string 29646 29647 Return S left-justified in a string of length width. Padding is 29648 done using the specified fill character (default is a space).""" 29649 return None 29650 def lower(self, _): 29651 """S.lower() -> string 29652 29653 Return a copy of the string S converted to lowercase.""" 29654 return None 29655 def lstrip(self, chars): 29656 """S.lstrip([chars]) -> string or unicode 29657 29658 Return a copy of the string S with leading whitespace removed. 29659 If chars is given and not None, remove characters in chars instead. 29660 If chars is unicode, S will be converted to unicode before stripping""" 29661 return None 29662 nbytes = getset_descriptor() 29663 ndim = getset_descriptor() 29664 def newbyteorder(self, new_order): 29665 """newbyteorder(new_order='S') 29666 29667 Return a new `dtype` with a different byte order. 29668 29669 Changes are also made in all fields and sub-arrays of the data type. 29670 29671 The `new_order` code can be any from the following: 29672 29673 * {'<', 'L'} - little endian 29674 * {'>', 'B'} - big endian 29675 * {'=', 'N'} - native order 29676 * 'S' - swap dtype from current to opposite endian 29677 * {'|', 'I'} - ignore (no change to byte order) 29678 29679 Parameters 29680 ---------- 29681 new_order : str, optional 29682 Byte order to force; a value from the byte order specifications 29683 above. The default value ('S') results in swapping the current 29684 byte order. The code does a case-insensitive check on the first 29685 letter of `new_order` for the alternatives above. For example, 29686 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 29687 29688 29689 Returns 29690 ------- 29691 new_dtype : dtype 29692 New `dtype` object with the given change to the byte order.""" 29693 return dtype() 29694 def partition(self, sep): 29695 """S.partition(sep) -> (head, sep, tail) 29696 29697 Search for the separator sep in S, and return the part before it, 29698 the separator itself, and the part after it. If the separator is not 29699 found, return S and two empty strings.""" 29700 return None 29701 real = getset_descriptor() 29702 def replace(self, old, new, count): 29703 """S.replace(old, new[, count]) -> string 29704 29705 Return a copy of string S with all occurrences of substring 29706 old replaced by new. If the optional argument count is 29707 given, only the first count occurrences are replaced.""" 29708 return None 29709 def rfind(self, sub, start, end): 29710 """S.rfind(sub [,start [,end]]) -> int 29711 29712 Return the highest index in S where substring sub is found, 29713 such that sub is contained within S[start:end]. Optional 29714 arguments start and end are interpreted as in slice notation. 29715 29716 Return -1 on failure.""" 29717 return None 29718 def rindex(self, sub, start, end): 29719 """S.rindex(sub [,start [,end]]) -> int 29720 29721 Like S.rfind() but raise ValueError when the substring is not found.""" 29722 return None 29723 def rjust(self, width, fillchar): 29724 """S.rjust(width[, fillchar]) -> string 29725 29726 Return S right-justified in a string of length width. Padding is 29727 done using the specified fill character (default is a space)""" 29728 return None 29729 def rpartition(self, sep): 29730 """S.rpartition(sep) -> (head, sep, tail) 29731 29732 Search for the separator sep in S, starting at the end of S, and return 29733 the part before it, the separator itself, and the part after it. If the 29734 separator is not found, return two empty strings and S.""" 29735 return None 29736 def rsplit(self, sep, maxsplit): 29737 """S.rsplit([sep [,maxsplit]]) -> list of strings 29738 29739 Return a list of the words in the string S, using sep as the 29740 delimiter string, starting at the end of the string and working 29741 to the front. If maxsplit is given, at most maxsplit splits are 29742 done. If sep is not specified or is None, any whitespace string 29743 is a separator.""" 29744 return None 29745 def rstrip(self, chars): 29746 """S.rstrip([chars]) -> string or unicode 29747 29748 Return a copy of the string S with trailing whitespace removed. 29749 If chars is given and not None, remove characters in chars instead. 29750 If chars is unicode, S will be converted to unicode before stripping""" 29751 return None 29752 shape = getset_descriptor() 29753 size = getset_descriptor() 29754 def split(self, sep, maxsplit): 29755 """S.split([sep [,maxsplit]]) -> list of strings 29756 29757 Return a list of the words in the string S, using sep as the 29758 delimiter string. If maxsplit is given, at most maxsplit 29759 splits are done. If sep is not specified or is None, any 29760 whitespace string is a separator and empty strings are removed 29761 from the result.""" 29762 return None 29763 def splitlines(self, keepends=False): 29764 """S.splitlines(keepends=False) -> list of strings 29765 29766 Return a list of the lines in S, breaking at line boundaries. 29767 Line breaks are not included in the resulting list unless keepends 29768 is given and true.""" 29769 return None 29770 def startswith(self, prefix, start, end): 29771 """S.startswith(prefix[, start[, end]]) -> bool 29772 29773 Return True if S starts with the specified prefix, False otherwise. 29774 With optional start, test S beginning at that position. 29775 With optional end, stop comparing S at that position. 29776 prefix can also be a tuple of strings to try.""" 29777 return None 29778 strides = getset_descriptor() 29779 def strip(self, chars): 29780 """S.strip([chars]) -> string or unicode 29781 29782 Return a copy of the string S with leading and trailing 29783 whitespace removed. 29784 If chars is given and not None, remove characters in chars instead. 29785 If chars is unicode, S will be converted to unicode before stripping""" 29786 return None 29787 def swapcase(self, _): 29788 """S.swapcase() -> string 29789 29790 Return a copy of the string S with uppercase characters 29791 converted to lowercase and vice versa.""" 29792 return None 29793 def title(self, _): 29794 """S.title() -> string 29795 29796 Return a titlecased version of S, i.e. words start with uppercase 29797 characters, all remaining cased characters have lowercase.""" 29798 return None 29799 def translate(self, table, deletechars): 29800 """S.translate(table [,deletechars]) -> string 29801 29802 Return a copy of the string S, where all characters occurring 29803 in the optional argument deletechars are removed, and the 29804 remaining characters have been mapped through the given 29805 translation table, which must be a string of length 256 or None. 29806 If the table argument is None, no translation is applied and 29807 the operation simply removes the characters in deletechars.""" 29808 return None 29809 def upper(self, _): 29810 """S.upper() -> string 29811 29812 Return a copy of the string S converted to uppercase.""" 29813 return None 29814 def zfill(self, width): 29815 """S.zfill(width) -> string 29816 29817 Pad a numeric string S with zeros on the left, to fill a field 29818 of the specified width. The string S is never truncated.""" 29819 return None 29820 def subtract(x1, x2, out=None): 29821 """subtract(x1, x2[, out]) 29822 29823 Subtract arguments, element-wise. 29824 29825 Parameters 29826 ---------- 29827 x1, x2 : array_like 29828 The arrays to be subtracted from each other. 29829 29830 Returns 29831 ------- 29832 y : ndarray 29833 The difference of `x1` and `x2`, element-wise. Returns a scalar if 29834 both `x1` and `x2` are scalars. 29835 29836 Notes 29837 ----- 29838 Equivalent to ``x1 - x2`` in terms of array broadcasting. 29839 29840 Examples 29841 -------- 29842 >>> np.subtract(1.0, 4.0) 29843 -3.0 29844 29845 >>> x1 = np.arange(9.0).reshape((3, 3)) 29846 >>> x2 = np.arange(3.0) 29847 >>> np.subtract(x1, x2) 29848 array([[ 0., 0., 0.], 29849 [ 3., 3., 3.], 29850 [ 6., 6., 6.]])""" 29851 return ndarray() 29852 def sum(a=False, axis=None, dtype=None, out=None, keepdims=False): 29853 """ 29854 Sum of array elements over a given axis. 29855 29856 Parameters 29857 ---------- 29858 a : array_like 29859 Elements to sum. 29860 axis : None or int or tuple of ints, optional 29861 Axis or axes along which a sum is performed. 29862 The default (`axis` = `None`) is perform a sum over all 29863 the dimensions of the input array. `axis` may be negative, in 29864 which case it counts from the last to the first axis. 29865 29866 .. versionadded:: 1.7.0 29867 29868 If this is a tuple of ints, a sum is performed on multiple 29869 axes, instead of a single axis or all the axes as before. 29870 dtype : dtype, optional 29871 The type of the returned array and of the accumulator in which 29872 the elements are summed. By default, the dtype of `a` is used. 29873 An exception is when `a` has an integer type with less precision 29874 than the default platform integer. In that case, the default 29875 platform integer is used instead. 29876 out : ndarray, optional 29877 Array into which the output is placed. By default, a new array is 29878 created. If `out` is given, it must be of the appropriate shape 29879 (the shape of `a` with `axis` removed, i.e., 29880 ``numpy.delete(a.shape, axis)``). Its type is preserved. See 29881 `doc.ufuncs` (Section "Output arguments") for more details. 29882 keepdims : bool, optional 29883 If this is set to True, the axes which are reduced are left 29884 in the result as dimensions with size one. With this option, 29885 the result will broadcast correctly against the original `arr`. 29886 29887 Returns 29888 ------- 29889 sum_along_axis : ndarray 29890 An array with the same shape as `a`, with the specified 29891 axis removed. If `a` is a 0-d array, or if `axis` is None, a scalar 29892 is returned. If an output array is specified, a reference to 29893 `out` is returned. 29894 29895 See Also 29896 -------- 29897 ndarray.sum : Equivalent method. 29898 29899 cumsum : Cumulative sum of array elements. 29900 29901 trapz : Integration of array values using the composite trapezoidal rule. 29902 29903 mean, average 29904 29905 Notes 29906 ----- 29907 Arithmetic is modular when using integer types, and no error is 29908 raised on overflow. 29909 29910 Examples 29911 -------- 29912 >>> np.sum([0.5, 1.5]) 29913 2.0 29914 >>> np.sum([0.5, 0.7, 0.2, 1.5], dtype=np.int32) 29915 1 29916 >>> np.sum([[0, 1], [0, 5]]) 29917 6 29918 >>> np.sum([[0, 1], [0, 5]], axis=0) 29919 array([0, 6]) 29920 >>> np.sum([[0, 1], [0, 5]], axis=1) 29921 array([1, 5]) 29922 29923 If the accumulator is too small, overflow occurs: 29924 29925 >>> np.ones(128, dtype=np.int8).sum(dtype=np.int8) 29926 -128 29927 29928 """ 29929 return ndarray() 29930 def swapaxes(a, axis1, axis2): 29931 """ 29932 Interchange two axes of an array. 29933 29934 Parameters 29935 ---------- 29936 a : array_like 29937 Input array. 29938 axis1 : int 29939 First axis. 29940 axis2 : int 29941 Second axis. 29942 29943 Returns 29944 ------- 29945 a_swapped : ndarray 29946 If `a` is an ndarray, then a view of `a` is returned; otherwise 29947 a new array is created. 29948 29949 Examples 29950 -------- 29951 >>> x = np.array([[1,2,3]]) 29952 >>> np.swapaxes(x,0,1) 29953 array([[1], 29954 [2], 29955 [3]]) 29956 29957 >>> x = np.array([[[0,1],[2,3]],[[4,5],[6,7]]]) 29958 >>> x 29959 array([[[0, 1], 29960 [2, 3]], 29961 [[4, 5], 29962 [6, 7]]]) 29963 29964 >>> np.swapaxes(x,0,2) 29965 array([[[0, 4], 29966 [2, 6]], 29967 [[1, 5], 29968 [3, 7]]]) 29969 29970 """ 29971 return ndarray() 29972 def take(a, indices="raise", axis=None, out=None, mode="raise"): 29973 """ 29974 Take elements from an array along an axis. 29975 29976 This function does the same thing as "fancy" indexing (indexing arrays 29977 using arrays); however, it can be easier to use if you need elements 29978 along a given axis. 29979 29980 Parameters 29981 ---------- 29982 a : array_like 29983 The source array. 29984 indices : array_like 29985 The indices of the values to extract. 29986 29987 .. versionadded:: 1.8.0 29988 29989 Also allow scalars for indices. 29990 axis : int, optional 29991 The axis over which to select values. By default, the flattened 29992 input array is used. 29993 out : ndarray, optional 29994 If provided, the result will be placed in this array. It should 29995 be of the appropriate shape and dtype. 29996 mode : {'raise', 'wrap', 'clip'}, optional 29997 Specifies how out-of-bounds indices will behave. 29998 29999 * 'raise' -- raise an error (default) 30000 * 'wrap' -- wrap around 30001 * 'clip' -- clip to the range 30002 30003 'clip' mode means that all indices that are too large are replaced 30004 by the index that addresses the last element along that axis. Note 30005 that this disables indexing with negative numbers. 30006 30007 Returns 30008 ------- 30009 subarray : ndarray 30010 The returned array has the same type as `a`. 30011 30012 See Also 30013 -------- 30014 ndarray.take : equivalent method 30015 30016 Examples 30017 -------- 30018 >>> a = [4, 3, 5, 7, 6, 8] 30019 >>> indices = [0, 1, 4] 30020 >>> np.take(a, indices) 30021 array([4, 3, 6]) 30022 30023 In this example if `a` is an ndarray, "fancy" indexing can be used. 30024 30025 >>> a = np.array(a) 30026 >>> a[indices] 30027 array([4, 3, 6]) 30028 30029 If `indices` is not one dimensional, the output also has these dimensions. 30030 30031 >>> np.take(a, [[0, 1], [2, 3]]) 30032 array([[4, 3], 30033 [5, 7]]) 30034 """ 30035 return ndarray() 30036 def tan(x, out): 30037 """tan(x[, out]) 30038 30039 Compute tangent element-wise. 30040 30041 Equivalent to ``np.sin(x)/np.cos(x)`` element-wise. 30042 30043 Parameters 30044 ---------- 30045 x : array_like 30046 Input array. 30047 out : ndarray, optional 30048 Output array of same shape as `x`. 30049 30050 Returns 30051 ------- 30052 y : ndarray 30053 The corresponding tangent values. 30054 30055 Raises 30056 ------ 30057 ValueError: invalid return array shape 30058 if `out` is provided and `out.shape` != `x.shape` (See Examples) 30059 30060 Notes 30061 ----- 30062 If `out` is provided, the function writes the result into it, 30063 and returns a reference to `out`. (See Examples) 30064 30065 References 30066 ---------- 30067 M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions. 30068 New York, NY: Dover, 1972. 30069 30070 Examples 30071 -------- 30072 >>> from math import pi 30073 >>> np.tan(np.array([-pi,pi/2,pi])) 30074 array([ 1.22460635e-16, 1.63317787e+16, -1.22460635e-16]) 30075 >>> 30076 >>> # Example of providing the optional output parameter illustrating 30077 >>> # that what is returned is a reference to said parameter 30078 >>> out2 = np.cos([0.1], out1) 30079 >>> out2 is out1 30080 True 30081 >>> 30082 >>> # Example of ValueError due to provision of shape mis-matched `out` 30083 >>> np.cos(np.zeros((3,3)),np.zeros((2,2))) 30084 Traceback (most recent call last): 30085 File "<stdin>", line 1, in <module> 30086 ValueError: invalid return array shape""" 30087 return ndarray() 30088 def tanh(x, out): 30089 """tanh(x[, out]) 30090 30091 Compute hyperbolic tangent element-wise. 30092 30093 Equivalent to ``np.sinh(x)/np.cosh(x)`` or 30094 ``-1j * np.tan(1j*x)``. 30095 30096 Parameters 30097 ---------- 30098 x : array_like 30099 Input array. 30100 out : ndarray, optional 30101 Output array of same shape as `x`. 30102 30103 Returns 30104 ------- 30105 y : ndarray 30106 The corresponding hyperbolic tangent values. 30107 30108 Raises 30109 ------ 30110 ValueError: invalid return array shape 30111 if `out` is provided and `out.shape` != `x.shape` (See Examples) 30112 30113 Notes 30114 ----- 30115 If `out` is provided, the function writes the result into it, 30116 and returns a reference to `out`. (See Examples) 30117 30118 References 30119 ---------- 30120 .. [1] M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions. 30121 New York, NY: Dover, 1972, pg. 83. 30122 http://www.math.sfu.ca/~cbm/aands/ 30123 30124 .. [2] Wikipedia, "Hyperbolic function", 30125 http://en.wikipedia.org/wiki/Hyperbolic_function 30126 30127 Examples 30128 -------- 30129 >>> np.tanh((0, np.pi*1j, np.pi*1j/2)) 30130 array([ 0. +0.00000000e+00j, 0. -1.22460635e-16j, 0. +1.63317787e+16j]) 30131 30132 >>> # Example of providing the optional output parameter illustrating 30133 >>> # that what is returned is a reference to said parameter 30134 >>> out2 = np.tanh([0.1], out1) 30135 >>> out2 is out1 30136 True 30137 30138 >>> # Example of ValueError due to provision of shape mis-matched `out` 30139 >>> np.tanh(np.zeros((3,3)),np.zeros((2,2))) 30140 Traceback (most recent call last): 30141 File "<stdin>", line 1, in <module> 30142 ValueError: invalid return array shape""" 30143 return ndarray() 30144 def tensordot(a, b=2, axes=2): 30145 """ 30146 Compute tensor dot product along specified axes for arrays >= 1-D. 30147 30148 Given two tensors (arrays of dimension greater than or equal to one), 30149 `a` and `b`, and an array_like object containing two array_like 30150 objects, ``(a_axes, b_axes)``, sum the products of `a`'s and `b`'s 30151 elements (components) over the axes specified by ``a_axes`` and 30152 ``b_axes``. The third argument can be a single non-negative 30153 integer_like scalar, ``N``; if it is such, then the last ``N`` 30154 dimensions of `a` and the first ``N`` dimensions of `b` are summed 30155 over. 30156 30157 Parameters 30158 ---------- 30159 a, b : array_like, len(shape) >= 1 30160 Tensors to "dot". 30161 axes : variable type 30162 * integer_like scalar 30163 Number of axes to sum over (applies to both arrays); or 30164 * (2,) array_like, both elements array_like of the same length 30165 List of axes to be summed over, first sequence applying to `a`, 30166 second to `b`. 30167 30168 See Also 30169 -------- 30170 dot, einsum 30171 30172 Notes 30173 ----- 30174 When there is more than one axis to sum over - and they are not the last 30175 (first) axes of `a` (`b`) - the argument `axes` should consist of 30176 two sequences of the same length, with the first axis to sum over given 30177 first in both sequences, the second axis second, and so forth. 30178 30179 Examples 30180 -------- 30181 A "traditional" example: 30182 30183 >>> a = np.arange(60.).reshape(3,4,5) 30184 >>> b = np.arange(24.).reshape(4,3,2) 30185 >>> c = np.tensordot(a,b, axes=([1,0],[0,1])) 30186 >>> c.shape 30187 (5, 2) 30188 >>> c 30189 array([[ 4400., 4730.], 30190 [ 4532., 4874.], 30191 [ 4664., 5018.], 30192 [ 4796., 5162.], 30193 [ 4928., 5306.]]) 30194 >>> # A slower but equivalent way of computing the same... 30195 >>> d = np.zeros((5,2)) 30196 >>> for i in range(5): 30197 ... for j in range(2): 30198 ... for k in range(3): 30199 ... for n in range(4): 30200 ... d[i,j] += a[k,n,i] * b[n,k,j] 30201 >>> c == d 30202 array([[ True, True], 30203 [ True, True], 30204 [ True, True], 30205 [ True, True], 30206 [ True, True]], dtype=bool) 30207 30208 An extended example taking advantage of the overloading of + and \*: 30209 30210 >>> a = np.array(range(1, 9)) 30211 >>> a.shape = (2, 2, 2) 30212 >>> A = np.array(('a', 'b', 'c', 'd'), dtype=object) 30213 >>> A.shape = (2, 2) 30214 >>> a; A 30215 array([[[1, 2], 30216 [3, 4]], 30217 [[5, 6], 30218 [7, 8]]]) 30219 array([[a, b], 30220 [c, d]], dtype=object) 30221 30222 >>> np.tensordot(a, A) # third argument default is 2 30223 array([abbcccdddd, aaaaabbbbbbcccccccdddddddd], dtype=object) 30224 30225 >>> np.tensordot(a, A, 1) 30226 array([[[acc, bdd], 30227 [aaacccc, bbbdddd]], 30228 [[aaaaacccccc, bbbbbdddddd], 30229 [aaaaaaacccccccc, bbbbbbbdddddddd]]], dtype=object) 30230 30231 >>> np.tensordot(a, A, 0) # "Left for reader" (result too long to incl.) 30232 array([[[[[a, b], 30233 [c, d]], 30234 ... 30235 30236 >>> np.tensordot(a, A, (0, 1)) 30237 array([[[abbbbb, cddddd], 30238 [aabbbbbb, ccdddddd]], 30239 [[aaabbbbbbb, cccddddddd], 30240 [aaaabbbbbbbb, ccccdddddddd]]], dtype=object) 30241 30242 >>> np.tensordot(a, A, (2, 1)) 30243 array([[[abb, cdd], 30244 [aaabbbb, cccdddd]], 30245 [[aaaaabbbbbb, cccccdddddd], 30246 [aaaaaaabbbbbbbb, cccccccdddddddd]]], dtype=object) 30247 30248 >>> np.tensordot(a, A, ((0, 1), (0, 1))) 30249 array([abbbcccccddddddd, aabbbbccccccdddddddd], dtype=object) 30250 30251 >>> np.tensordot(a, A, ((2, 1), (1, 0))) 30252 array([acccbbdddd, aaaaacccccccbbbbbbdddddddd], dtype=object) 30253 30254 """ 30255 return None 30256 def test(self=None, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None): 30257 """ 30258 Run tests for module using nose. 30259 30260 Parameters 30261 ---------- 30262 label : {'fast', 'full', '', attribute identifier}, optional 30263 Identifies the tests to run. This can be a string to pass to 30264 the nosetests executable with the '-A' option, or one of several 30265 special values. Special values are: 30266 * 'fast' - the default - which corresponds to the ``nosetests -A`` 30267 option of 'not slow'. 30268 * 'full' - fast (as above) and slow tests as in the 30269 'no -A' option to nosetests - this is the same as ''. 30270 * None or '' - run all tests. 30271 attribute_identifier - string passed directly to nosetests as '-A'. 30272 verbose : int, optional 30273 Verbosity value for test outputs, in the range 1-10. Default is 1. 30274 extra_argv : list, optional 30275 List with any extra arguments to pass to nosetests. 30276 doctests : bool, optional 30277 If True, run doctests in module. Default is False. 30278 coverage : bool, optional 30279 If True, report coverage of NumPy code. Default is False. 30280 (This requires the `coverage module: 30281 <http://nedbatchelder.com/code/modules/coverage.html>`_). 30282 raise_warnings : str or sequence of warnings, optional 30283 This specifies which warnings to configure as 'raise' instead 30284 of 'warn' during the test execution. Valid strings are: 30285 30286 - "develop" : equals ``(DeprecationWarning, RuntimeWarning)`` 30287 - "release" : equals ``()``, don't raise on any warnings. 30288 30289 Returns 30290 ------- 30291 result : object 30292 Returns the result of running the tests as a 30293 ``nose.result.TextTestResult`` object. 30294 30295 Notes 30296 ----- 30297 Each NumPy module exposes `test` in its namespace to run all tests for it. 30298 For example, to run all tests for numpy.lib: 30299 30300 >>> np.lib.test() #doctest: +SKIP 30301 30302 Examples 30303 -------- 30304 >>> result = np.lib.test() #doctest: +SKIP 30305 Running unit tests for numpy.lib 30306 ... 30307 Ran 976 tests in 3.933s 30308 30309 OK 30310 30311 >>> result.errors #doctest: +SKIP 30312 [] 30313 >>> result.knownfail #doctest: +SKIP 30314 [] 30315 """ 30316 return object() 30317 def tile(A, reps): 30318 """ 30319 Construct an array by repeating A the number of times given by reps. 30320 30321 If `reps` has length ``d``, the result will have dimension of 30322 ``max(d, A.ndim)``. 30323 30324 If ``A.ndim < d``, `A` is promoted to be d-dimensional by prepending new 30325 axes. So a shape (3,) array is promoted to (1, 3) for 2-D replication, 30326 or shape (1, 1, 3) for 3-D replication. If this is not the desired 30327 behavior, promote `A` to d-dimensions manually before calling this 30328 function. 30329 30330 If ``A.ndim > d``, `reps` is promoted to `A`.ndim by pre-pending 1's to it. 30331 Thus for an `A` of shape (2, 3, 4, 5), a `reps` of (2, 2) is treated as 30332 (1, 1, 2, 2). 30333 30334 Parameters 30335 ---------- 30336 A : array_like 30337 The input array. 30338 reps : array_like 30339 The number of repetitions of `A` along each axis. 30340 30341 Returns 30342 ------- 30343 c : ndarray 30344 The tiled output array. 30345 30346 See Also 30347 -------- 30348 repeat : Repeat elements of an array. 30349 30350 Examples 30351 -------- 30352 >>> a = np.array([0, 1, 2]) 30353 >>> np.tile(a, 2) 30354 array([0, 1, 2, 0, 1, 2]) 30355 >>> np.tile(a, (2, 2)) 30356 array([[0, 1, 2, 0, 1, 2], 30357 [0, 1, 2, 0, 1, 2]]) 30358 >>> np.tile(a, (2, 1, 2)) 30359 array([[[0, 1, 2, 0, 1, 2]], 30360 [[0, 1, 2, 0, 1, 2]]]) 30361 30362 >>> b = np.array([[1, 2], [3, 4]]) 30363 >>> np.tile(b, 2) 30364 array([[1, 2, 1, 2], 30365 [3, 4, 3, 4]]) 30366 >>> np.tile(b, (2, 1)) 30367 array([[1, 2], 30368 [3, 4], 30369 [1, 2], 30370 [3, 4]]) 30371 30372 """ 30373 return ndarray() 30374 class timedelta64: 30375 T = getset_descriptor() 30376 __array_interface__ = getset_descriptor() 30377 __array_priority__ = getset_descriptor() 30378 __array_struct__ = getset_descriptor() 30379 __doc__ = None 30380 base = getset_descriptor() 30381 def conj(self, _): 30382 """None""" 30383 return None 30384 data = getset_descriptor() 30385 dtype = getset_descriptor() 30386 flags = getset_descriptor() 30387 flat = getset_descriptor() 30388 imag = getset_descriptor() 30389 itemsize = getset_descriptor() 30390 nbytes = getset_descriptor() 30391 ndim = getset_descriptor() 30392 def newbyteorder(self, new_order): 30393 """newbyteorder(new_order='S') 30394 30395 Return a new `dtype` with a different byte order. 30396 30397 Changes are also made in all fields and sub-arrays of the data type. 30398 30399 The `new_order` code can be any from the following: 30400 30401 * {'<', 'L'} - little endian 30402 * {'>', 'B'} - big endian 30403 * {'=', 'N'} - native order 30404 * 'S' - swap dtype from current to opposite endian 30405 * {'|', 'I'} - ignore (no change to byte order) 30406 30407 Parameters 30408 ---------- 30409 new_order : str, optional 30410 Byte order to force; a value from the byte order specifications 30411 above. The default value ('S') results in swapping the current 30412 byte order. The code does a case-insensitive check on the first 30413 letter of `new_order` for the alternatives above. For example, 30414 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 30415 30416 30417 Returns 30418 ------- 30419 new_dtype : dtype 30420 New `dtype` object with the given change to the byte order.""" 30421 return dtype() 30422 real = getset_descriptor() 30423 shape = getset_descriptor() 30424 size = getset_descriptor() 30425 strides = getset_descriptor() 30426 def trace(a=None, offset=0, axis1=0, axis2=1, dtype=None, out=None): 30427 """ 30428 Return the sum along diagonals of the array. 30429 30430 If `a` is 2-D, the sum along its diagonal with the given offset 30431 is returned, i.e., the sum of elements ``a[i,i+offset]`` for all i. 30432 30433 If `a` has more than two dimensions, then the axes specified by axis1 and 30434 axis2 are used to determine the 2-D sub-arrays whose traces are returned. 30435 The shape of the resulting array is the same as that of `a` with `axis1` 30436 and `axis2` removed. 30437 30438 Parameters 30439 ---------- 30440 a : array_like 30441 Input array, from which the diagonals are taken. 30442 offset : int, optional 30443 Offset of the diagonal from the main diagonal. Can be both positive 30444 and negative. Defaults to 0. 30445 axis1, axis2 : int, optional 30446 Axes to be used as the first and second axis of the 2-D sub-arrays 30447 from which the diagonals should be taken. Defaults are the first two 30448 axes of `a`. 30449 dtype : dtype, optional 30450 Determines the data-type of the returned array and of the accumulator 30451 where the elements are summed. If dtype has the value None and `a` is 30452 of integer type of precision less than the default integer 30453 precision, then the default integer precision is used. Otherwise, 30454 the precision is the same as that of `a`. 30455 out : ndarray, optional 30456 Array into which the output is placed. Its type is preserved and 30457 it must be of the right shape to hold the output. 30458 30459 Returns 30460 ------- 30461 sum_along_diagonals : ndarray 30462 If `a` is 2-D, the sum along the diagonal is returned. If `a` has 30463 larger dimensions, then an array of sums along diagonals is returned. 30464 30465 See Also 30466 -------- 30467 diag, diagonal, diagflat 30468 30469 Examples 30470 -------- 30471 >>> np.trace(np.eye(3)) 30472 3.0 30473 >>> a = np.arange(8).reshape((2,2,2)) 30474 >>> np.trace(a) 30475 array([6, 8]) 30476 30477 >>> a = np.arange(24).reshape((2,2,2,3)) 30478 >>> np.trace(a).shape 30479 (2, 3) 30480 30481 """ 30482 return ndarray() 30483 def transpose(a=None, axes=None): 30484 """ 30485 Permute the dimensions of an array. 30486 30487 Parameters 30488 ---------- 30489 a : array_like 30490 Input array. 30491 axes : list of ints, optional 30492 By default, reverse the dimensions, otherwise permute the axes 30493 according to the values given. 30494 30495 Returns 30496 ------- 30497 p : ndarray 30498 `a` with its axes permuted. A view is returned whenever 30499 possible. 30500 30501 See Also 30502 -------- 30503 rollaxis 30504 30505 Examples 30506 -------- 30507 >>> x = np.arange(4).reshape((2,2)) 30508 >>> x 30509 array([[0, 1], 30510 [2, 3]]) 30511 30512 >>> np.transpose(x) 30513 array([[0, 2], 30514 [1, 3]]) 30515 30516 >>> x = np.ones((1, 2, 3)) 30517 >>> np.transpose(x, (1, 0, 2)).shape 30518 (2, 1, 3) 30519 30520 """ 30521 return ndarray() 30522 def trapz(y=-1, x=None, dx=1.0, axis=-1): 30523 """ 30524 Integrate along the given axis using the composite trapezoidal rule. 30525 30526 Integrate `y` (`x`) along given axis. 30527 30528 Parameters 30529 ---------- 30530 y : array_like 30531 Input array to integrate. 30532 x : array_like, optional 30533 If `x` is None, then spacing between all `y` elements is `dx`. 30534 dx : scalar, optional 30535 If `x` is None, spacing given by `dx` is assumed. Default is 1. 30536 axis : int, optional 30537 Specify the axis. 30538 30539 Returns 30540 ------- 30541 trapz : float 30542 Definite integral as approximated by trapezoidal rule. 30543 30544 See Also 30545 -------- 30546 sum, cumsum 30547 30548 Notes 30549 ----- 30550 Image [2]_ illustrates trapezoidal rule -- y-axis locations of points will 30551 be taken from `y` array, by default x-axis distances between points will be 30552 1.0, alternatively they can be provided with `x` array or with `dx` scalar. 30553 Return value will be equal to combined area under the red lines. 30554 30555 30556 References 30557 ---------- 30558 .. [1] Wikipedia page: http://en.wikipedia.org/wiki/Trapezoidal_rule 30559 30560 .. [2] Illustration image: 30561 http://en.wikipedia.org/wiki/File:Composite_trapezoidal_rule_illustration.png 30562 30563 Examples 30564 -------- 30565 >>> np.trapz([1,2,3]) 30566 4.0 30567 >>> np.trapz([1,2,3], x=[4,6,8]) 30568 8.0 30569 >>> np.trapz([1,2,3], dx=2) 30570 8.0 30571 >>> a = np.arange(6).reshape(2, 3) 30572 >>> a 30573 array([[0, 1, 2], 30574 [3, 4, 5]]) 30575 >>> np.trapz(a, axis=0) 30576 array([ 1.5, 2.5, 3.5]) 30577 >>> np.trapz(a, axis=1) 30578 array([ 2., 8.]) 30579 30580 """ 30581 return float() 30582 def tri(N=typefloat(), M=None, k=0, dtype=typefloat()): 30583 """ 30584 An array with ones at and below the given diagonal and zeros elsewhere. 30585 30586 Parameters 30587 ---------- 30588 N : int 30589 Number of rows in the array. 30590 M : int, optional 30591 Number of columns in the array. 30592 By default, `M` is taken equal to `N`. 30593 k : int, optional 30594 The sub-diagonal at and below which the array is filled. 30595 `k` = 0 is the main diagonal, while `k` < 0 is below it, 30596 and `k` > 0 is above. The default is 0. 30597 dtype : dtype, optional 30598 Data type of the returned array. The default is float. 30599 30600 Returns 30601 ------- 30602 tri : ndarray of shape (N, M) 30603 Array with its lower triangle filled with ones and zero elsewhere; 30604 in other words ``T[i,j] == 1`` for ``i <= j + k``, 0 otherwise. 30605 30606 Examples 30607 -------- 30608 >>> np.tri(3, 5, 2, dtype=int) 30609 array([[1, 1, 1, 0, 0], 30610 [1, 1, 1, 1, 0], 30611 [1, 1, 1, 1, 1]]) 30612 30613 >>> np.tri(3, 5, -1) 30614 array([[ 0., 0., 0., 0., 0.], 30615 [ 1., 0., 0., 0., 0.], 30616 [ 1., 1., 0., 0., 0.]]) 30617 30618 """ 30619 return ndarray() 30620 def tril(m=0, k=0): 30621 """ 30622 Lower triangle of an array. 30623 30624 Return a copy of an array with elements above the `k`-th diagonal zeroed. 30625 30626 Parameters 30627 ---------- 30628 m : array_like, shape (M, N) 30629 Input array. 30630 k : int, optional 30631 Diagonal above which to zero elements. `k = 0` (the default) is the 30632 main diagonal, `k < 0` is below it and `k > 0` is above. 30633 30634 Returns 30635 ------- 30636 tril : ndarray, shape (M, N) 30637 Lower triangle of `m`, of same shape and data-type as `m`. 30638 30639 See Also 30640 -------- 30641 triu : same thing, only for the upper triangle 30642 30643 Examples 30644 -------- 30645 >>> np.tril([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1) 30646 array([[ 0, 0, 0], 30647 [ 4, 0, 0], 30648 [ 7, 8, 0], 30649 [10, 11, 12]]) 30650 30651 """ 30652 return ndarray() 30653 def tril_indices(n=0, k=0): 30654 """ 30655 Return the indices for the lower-triangle of an (n, n) array. 30656 30657 Parameters 30658 ---------- 30659 n : int 30660 The row dimension of the square arrays for which the returned 30661 indices will be valid. 30662 k : int, optional 30663 Diagonal offset (see `tril` for details). 30664 30665 Returns 30666 ------- 30667 inds : tuple of arrays 30668 The indices for the triangle. The returned tuple contains two arrays, 30669 each with the indices along one dimension of the array. 30670 30671 See also 30672 -------- 30673 triu_indices : similar function, for upper-triangular. 30674 mask_indices : generic function accepting an arbitrary mask function. 30675 tril, triu 30676 30677 Notes 30678 ----- 30679 .. versionadded:: 1.4.0 30680 30681 Examples 30682 -------- 30683 Compute two different sets of indices to access 4x4 arrays, one for the 30684 lower triangular part starting at the main diagonal, and one starting two 30685 diagonals further right: 30686 30687 >>> il1 = np.tril_indices(4) 30688 >>> il2 = np.tril_indices(4, 2) 30689 30690 Here is how they can be used with a sample array: 30691 30692 >>> a = np.arange(16).reshape(4, 4) 30693 >>> a 30694 array([[ 0, 1, 2, 3], 30695 [ 4, 5, 6, 7], 30696 [ 8, 9, 10, 11], 30697 [12, 13, 14, 15]]) 30698 30699 Both for indexing: 30700 30701 >>> a[il1] 30702 array([ 0, 4, 5, 8, 9, 10, 12, 13, 14, 15]) 30703 30704 And for assigning values: 30705 30706 >>> a[il1] = -1 30707 >>> a 30708 array([[-1, 1, 2, 3], 30709 [-1, -1, 6, 7], 30710 [-1, -1, -1, 11], 30711 [-1, -1, -1, -1]]) 30712 30713 These cover almost the whole array (two diagonals right of the main one): 30714 30715 >>> a[il2] = -10 30716 >>> a 30717 array([[-10, -10, -10, 3], 30718 [-10, -10, -10, -10], 30719 [-10, -10, -10, -10], 30720 [-10, -10, -10, -10]]) 30721 30722 """ 30723 return tuple() 30724 def tril_indices__from(arr=0, k=0): 30725 """ 30726 Return the indices for the lower-triangle of arr. 30727 30728 See `tril_indices` for full details. 30729 30730 Parameters 30731 ---------- 30732 arr : array_like 30733 The indices will be valid for square arrays whose dimensions are 30734 the same as arr. 30735 k : int, optional 30736 Diagonal offset (see `tril` for details). 30737 30738 See Also 30739 -------- 30740 tril_indices, tril 30741 30742 Notes 30743 ----- 30744 .. versionadded:: 1.4.0 30745 30746 """ 30747 return None 30748 def trim_zeros(filt="fb", trim="fb"): 30749 """ 30750 Trim the leading and/or trailing zeros from a 1-D array or sequence. 30751 30752 Parameters 30753 ---------- 30754 filt : 1-D array or sequence 30755 Input array. 30756 trim : str, optional 30757 A string with 'f' representing trim from front and 'b' to trim from 30758 back. Default is 'fb', trim zeros from both front and back of the 30759 array. 30760 30761 Returns 30762 ------- 30763 trimmed : 1-D array or sequence 30764 The result of trimming the input. The input data type is preserved. 30765 30766 Examples 30767 -------- 30768 >>> a = np.array((0, 0, 0, 1, 2, 3, 0, 2, 1, 0)) 30769 >>> np.trim_zeros(a) 30770 array([1, 2, 3, 0, 2, 1]) 30771 30772 >>> np.trim_zeros(a, 'b') 30773 array([0, 0, 0, 1, 2, 3, 0, 2, 1]) 30774 30775 The input data type is preserved, list/tuple in means list/tuple out. 30776 30777 >>> np.trim_zeros([0, 1, 2, 0]) 30778 [1, 2] 30779 30780 """ 30781 return _1_D() if False else sequence() 30782 def triu(m=0, k=0): 30783 """ 30784 Upper triangle of an array. 30785 30786 Return a copy of a matrix with the elements below the `k`-th diagonal 30787 zeroed. 30788 30789 Please refer to the documentation for `tril` for further details. 30790 30791 See Also 30792 -------- 30793 tril : lower triangle of an array 30794 30795 Examples 30796 -------- 30797 >>> np.triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1) 30798 array([[ 1, 2, 3], 30799 [ 4, 5, 6], 30800 [ 0, 8, 9], 30801 [ 0, 0, 12]]) 30802 30803 """ 30804 return None 30805 def triu_indices(n=0, k=0): 30806 """ 30807 Return the indices for the upper-triangle of an (n, n) array. 30808 30809 Parameters 30810 ---------- 30811 n : int 30812 The size of the arrays for which the returned indices will 30813 be valid. 30814 k : int, optional 30815 Diagonal offset (see `triu` for details). 30816 30817 Returns 30818 ------- 30819 inds : tuple, shape(2) of ndarrays, shape(`n`) 30820 The indices for the triangle. The returned tuple contains two arrays, 30821 each with the indices along one dimension of the array. Can be used 30822 to slice a ndarray of shape(`n`, `n`). 30823 30824 See also 30825 -------- 30826 tril_indices : similar function, for lower-triangular. 30827 mask_indices : generic function accepting an arbitrary mask function. 30828 triu, tril 30829 30830 Notes 30831 ----- 30832 .. versionadded:: 1.4.0 30833 30834 Examples 30835 -------- 30836 Compute two different sets of indices to access 4x4 arrays, one for the 30837 upper triangular part starting at the main diagonal, and one starting two 30838 diagonals further right: 30839 30840 >>> iu1 = np.triu_indices(4) 30841 >>> iu2 = np.triu_indices(4, 2) 30842 30843 Here is how they can be used with a sample array: 30844 30845 >>> a = np.arange(16).reshape(4, 4) 30846 >>> a 30847 array([[ 0, 1, 2, 3], 30848 [ 4, 5, 6, 7], 30849 [ 8, 9, 10, 11], 30850 [12, 13, 14, 15]]) 30851 30852 Both for indexing: 30853 30854 >>> a[iu1] 30855 array([ 0, 1, 2, 3, 5, 6, 7, 10, 11, 15]) 30856 30857 And for assigning values: 30858 30859 >>> a[iu1] = -1 30860 >>> a 30861 array([[-1, -1, -1, -1], 30862 [ 4, -1, -1, -1], 30863 [ 8, 9, -1, -1], 30864 [12, 13, 14, -1]]) 30865 30866 These cover only a small part of the whole array (two diagonals right 30867 of the main one): 30868 30869 >>> a[iu2] = -10 30870 >>> a 30871 array([[ -1, -1, -10, -10], 30872 [ 4, -1, -1, -10], 30873 [ 8, 9, -1, -1], 30874 [ 12, 13, 14, -1]]) 30875 30876 """ 30877 return tuple() 30878 def triu_indices__from(arr=0, k=0): 30879 """ 30880 Return the indices for the upper-triangle of a (N, N) array. 30881 30882 See `triu_indices` for full details. 30883 30884 Parameters 30885 ---------- 30886 arr : ndarray, shape(N, N) 30887 The indices will be valid for square arrays. 30888 k : int, optional 30889 Diagonal offset (see `triu` for details). 30890 30891 Returns 30892 ------- 30893 triu_indices_from : tuple, shape(2) of ndarray, shape(N) 30894 Indices for the upper-triangle of `arr`. 30895 30896 See Also 30897 -------- 30898 triu_indices, triu 30899 30900 Notes 30901 ----- 30902 .. versionadded:: 1.4.0 30903 30904 """ 30905 return tuple() 30906 def true_divide(x1, x2, out=None): 30907 """true_divide(x1, x2[, out]) 30908 30909 Returns a true division of the inputs, element-wise. 30910 30911 Instead of the Python traditional 'floor division', this returns a true 30912 division. True division adjusts the output type to present the best 30913 answer, regardless of input types. 30914 30915 Parameters 30916 ---------- 30917 x1 : array_like 30918 Dividend array. 30919 x2 : array_like 30920 Divisor array. 30921 30922 Returns 30923 ------- 30924 out : ndarray 30925 Result is scalar if both inputs are scalar, ndarray otherwise. 30926 30927 Notes 30928 ----- 30929 The floor division operator ``//`` was added in Python 2.2 making ``//`` 30930 and ``/`` equivalent operators. The default floor division operation of 30931 ``/`` can be replaced by true division with 30932 ``from __future__ import division``. 30933 30934 In Python 3.0, ``//`` is the floor division operator and ``/`` the 30935 true division operator. The ``true_divide(x1, x2)`` function is 30936 equivalent to true division in Python. 30937 30938 Examples 30939 -------- 30940 >>> x = np.arange(5) 30941 >>> np.true_divide(x, 4) 30942 array([ 0. , 0.25, 0.5 , 0.75, 1. ]) 30943 30944 >>> x/4 30945 array([0, 0, 0, 0, 1]) 30946 >>> x//4 30947 array([0, 0, 0, 0, 1]) 30948 30949 >>> from __future__ import division 30950 >>> x/4 30951 array([ 0. , 0.25, 0.5 , 0.75, 1. ]) 30952 >>> x//4 30953 array([0, 0, 0, 0, 1])""" 30954 return ndarray() 30955 def trunc(x, out=None): 30956 """trunc(x[, out]) 30957 30958 Return the truncated value of the input, element-wise. 30959 30960 The truncated value of the scalar `x` is the nearest integer `i` which 30961 is closer to zero than `x` is. In short, the fractional part of the 30962 signed number `x` is discarded. 30963 30964 Parameters 30965 ---------- 30966 x : array_like 30967 Input data. 30968 30969 Returns 30970 ------- 30971 y : {ndarray, scalar} 30972 The truncated value of each element in `x`. 30973 30974 See Also 30975 -------- 30976 ceil, floor, rint 30977 30978 Notes 30979 ----- 30980 .. versionadded:: 1.3.0 30981 30982 Examples 30983 -------- 30984 >>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) 30985 >>> np.trunc(a) 30986 array([-1., -1., -0., 0., 1., 1., 2.])""" 30987 return ndarray() 30988 typeDict = dict() 30989 typeNA = dict() 30990 typecodes = dict() 30991 def typename(char): 30992 """ 30993 Return a description for the given data type code. 30994 30995 Parameters 30996 ---------- 30997 char : str 30998 Data type code. 30999 31000 Returns 31001 ------- 31002 out : str 31003 Description of the input data type code. 31004 31005 See Also 31006 -------- 31007 dtype, typecodes 31008 31009 Examples 31010 -------- 31011 >>> typechars = ['S1', '?', 'B', 'D', 'G', 'F', 'I', 'H', 'L', 'O', 'Q', 31012 ... 'S', 'U', 'V', 'b', 'd', 'g', 'f', 'i', 'h', 'l', 'q'] 31013 >>> for typechar in typechars: 31014 ... print typechar, ' : ', np.typename(typechar) 31015 ... 31016 S1 : character 31017 ? : bool 31018 B : unsigned char 31019 D : complex double precision 31020 G : complex long double precision 31021 F : complex single precision 31022 I : unsigned integer 31023 H : unsigned short 31024 L : unsigned long integer 31025 O : object 31026 Q : unsigned long long integer 31027 S : string 31028 U : unicode 31029 V : void 31030 b : signed char 31031 d : double precision 31032 g : long precision 31033 f : single precision 31034 i : integer 31035 h : short 31036 l : long integer 31037 q : long long integer 31038 31039 """ 31040 return str() 31041 class uint8: 31042 T = getset_descriptor() 31043 __array_interface__ = getset_descriptor() 31044 __array_priority__ = getset_descriptor() 31045 __array_struct__ = getset_descriptor() 31046 __doc__ = None 31047 base = getset_descriptor() 31048 def conj(self, _): 31049 """None""" 31050 return None 31051 data = getset_descriptor() 31052 dtype = getset_descriptor() 31053 flags = getset_descriptor() 31054 flat = getset_descriptor() 31055 imag = getset_descriptor() 31056 itemsize = getset_descriptor() 31057 nbytes = getset_descriptor() 31058 ndim = getset_descriptor() 31059 def newbyteorder(self, new_order): 31060 """newbyteorder(new_order='S') 31061 31062 Return a new `dtype` with a different byte order. 31063 31064 Changes are also made in all fields and sub-arrays of the data type. 31065 31066 The `new_order` code can be any from the following: 31067 31068 * {'<', 'L'} - little endian 31069 * {'>', 'B'} - big endian 31070 * {'=', 'N'} - native order 31071 * 'S' - swap dtype from current to opposite endian 31072 * {'|', 'I'} - ignore (no change to byte order) 31073 31074 Parameters 31075 ---------- 31076 new_order : str, optional 31077 Byte order to force; a value from the byte order specifications 31078 above. The default value ('S') results in swapping the current 31079 byte order. The code does a case-insensitive check on the first 31080 letter of `new_order` for the alternatives above. For example, 31081 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 31082 31083 31084 Returns 31085 ------- 31086 new_dtype : dtype 31087 New `dtype` object with the given change to the byte order.""" 31088 return dtype() 31089 real = getset_descriptor() 31090 shape = getset_descriptor() 31091 size = getset_descriptor() 31092 strides = getset_descriptor() 31093 class ufunc: 31094 __doc__ = str() 31095 __name__ = str() 31096 def accumulate(self, array, axis, dtype, out): 31097 """accumulate(array, axis=0, dtype=None, out=None) 31098 31099 Accumulate the result of applying the operator to all elements. 31100 31101 For a one-dimensional array, accumulate produces results equivalent to:: 31102 31103 r = np.empty(len(A)) 31104 t = op.identity # op = the ufunc being applied to A's elements 31105 for i in range(len(A)): 31106 t = op(t, A[i]) 31107 r[i] = t 31108 return r 31109 31110 For example, add.accumulate() is equivalent to np.cumsum(). 31111 31112 For a multi-dimensional array, accumulate is applied along only one 31113 axis (axis zero by default; see Examples below) so repeated use is 31114 necessary if one wants to accumulate over multiple axes. 31115 31116 Parameters 31117 ---------- 31118 array : array_like 31119 The array to act on. 31120 axis : int, optional 31121 The axis along which to apply the accumulation; default is zero. 31122 dtype : data-type code, optional 31123 The data-type used to represent the intermediate results. Defaults 31124 to the data-type of the output array if such is provided, or the 31125 the data-type of the input array if no output array is provided. 31126 out : ndarray, optional 31127 A location into which the result is stored. If not provided a 31128 freshly-allocated array is returned. 31129 31130 Returns 31131 ------- 31132 r : ndarray 31133 The accumulated values. If `out` was supplied, `r` is a reference to 31134 `out`. 31135 31136 Examples 31137 -------- 31138 1-D array examples: 31139 31140 >>> np.add.accumulate([2, 3, 5]) 31141 array([ 2, 5, 10]) 31142 >>> np.multiply.accumulate([2, 3, 5]) 31143 array([ 2, 6, 30]) 31144 31145 2-D array examples: 31146 31147 >>> I = np.eye(2) 31148 >>> I 31149 array([[ 1., 0.], 31150 [ 0., 1.]]) 31151 31152 Accumulate along axis 0 (rows), down columns: 31153 31154 >>> np.add.accumulate(I, 0) 31155 array([[ 1., 0.], 31156 [ 1., 1.]]) 31157 >>> np.add.accumulate(I) # no axis specified = axis zero 31158 array([[ 1., 0.], 31159 [ 1., 1.]]) 31160 31161 Accumulate along axis 1 (columns), through rows: 31162 31163 >>> np.add.accumulate(I, 1) 31164 array([[ 1., 1.], 31165 [ 0., 1.]])""" 31166 return ndarray() 31167 def at(self, a, indices, b): 31168 """at(a, indices, b=None) 31169 31170 Performs unbuffered in place operation on operand 'a' for elements 31171 specified by 'indices'. For addition ufunc, this method is equivalent to 31172 `a[indices] += b`, except that results are accumulated for elements that 31173 are indexed more than once. For example, `a[[0,0]] += 1` will only 31174 increment the first element once because of buffering, whereas 31175 `add.at(a, [0,0], 1)` will increment the first element twice. 31176 31177 Parameters 31178 ---------- 31179 a : array_like 31180 The array to perform in place operation on. 31181 indices : array_like or tuple 31182 Array like index object or slice object for indexing into first 31183 operand. If first operand has multiple dimensions, indices can be a 31184 tuple of array like index objects or slice objects. 31185 b : array_like 31186 Second operand for ufuncs requiring two operands. Operand must be 31187 broadcastable over first operand after indexing or slicing. 31188 31189 Examples 31190 -------- 31191 Set items 0 and 1 to their negative values: 31192 31193 >>> a = np.array([1, 2, 3, 4]) 31194 >>> np.negative.at(a, [0, 1]) 31195 >>> print(a) 31196 array([-1, -2, 3, 4]) 31197 31198 :: 31199 31200 Increment items 0 and 1, and increment item 2 twice: 31201 31202 >>> a = np.array([1, 2, 3, 4]) 31203 >>> np.add.at(a, [0, 1, 2, 2], 1) 31204 >>> print(a) 31205 array([2, 3, 5, 4]) 31206 31207 :: 31208 31209 Add items 0 and 1 in first array to second array, 31210 and store results in first array: 31211 31212 >>> a = np.array([1, 2, 3, 4]) 31213 >>> b = np.array([1, 2]) 31214 >>> np.add.at(a, [0, 1], b) 31215 >>> print(a) 31216 array([2, 4, 3, 4])""" 31217 return None 31218 identity = getset_descriptor() 31219 nargs = getset_descriptor() 31220 nin = getset_descriptor() 31221 nout = getset_descriptor() 31222 ntypes = getset_descriptor() 31223 def outer(self, A, B): 31224 """outer(A, B) 31225 31226 Apply the ufunc `op` to all pairs (a, b) with a in `A` and b in `B`. 31227 31228 Let ``M = A.ndim``, ``N = B.ndim``. Then the result, `C`, of 31229 ``op.outer(A, B)`` is an array of dimension M + N such that: 31230 31231 .. math:: C[i_0, ..., i_{M-1}, j_0, ..., j_{N-1}] = 31232 op(A[i_0, ..., i_{M-1}], B[j_0, ..., j_{N-1}]) 31233 31234 For `A` and `B` one-dimensional, this is equivalent to:: 31235 31236 r = empty(len(A),len(B)) 31237 for i in range(len(A)): 31238 for j in range(len(B)): 31239 r[i,j] = op(A[i], B[j]) # op = ufunc in question 31240 31241 Parameters 31242 ---------- 31243 A : array_like 31244 First array 31245 B : array_like 31246 Second array 31247 31248 Returns 31249 ------- 31250 r : ndarray 31251 Output array 31252 31253 See Also 31254 -------- 31255 numpy.outer 31256 31257 Examples 31258 -------- 31259 >>> np.multiply.outer([1, 2, 3], [4, 5, 6]) 31260 array([[ 4, 5, 6], 31261 [ 8, 10, 12], 31262 [12, 15, 18]]) 31263 31264 A multi-dimensional example: 31265 31266 >>> A = np.array([[1, 2, 3], [4, 5, 6]]) 31267 >>> A.shape 31268 (2, 3) 31269 >>> B = np.array([[1, 2, 3, 4]]) 31270 >>> B.shape 31271 (1, 4) 31272 >>> C = np.multiply.outer(A, B) 31273 >>> C.shape; C 31274 (2, 3, 1, 4) 31275 array([[[[ 1, 2, 3, 4]], 31276 [[ 2, 4, 6, 8]], 31277 [[ 3, 6, 9, 12]]], 31278 [[[ 4, 8, 12, 16]], 31279 [[ 5, 10, 15, 20]], 31280 [[ 6, 12, 18, 24]]]])""" 31281 return ndarray() 31282 def reduce(self, a, axis, dtype, out, keepdims): 31283 """reduce(a, axis=0, dtype=None, out=None, keepdims=False) 31284 31285 Reduces `a`'s dimension by one, by applying ufunc along one axis. 31286 31287 Let :math:`a.shape = (N_0, ..., N_i, ..., N_{M-1})`. Then 31288 :math:`ufunc.reduce(a, axis=i)[k_0, ..,k_{i-1}, k_{i+1}, .., k_{M-1}]` = 31289 the result of iterating `j` over :math:`range(N_i)`, cumulatively applying 31290 ufunc to each :math:`a[k_0, ..,k_{i-1}, j, k_{i+1}, .., k_{M-1}]`. 31291 For a one-dimensional array, reduce produces results equivalent to: 31292 :: 31293 31294 r = op.identity # op = ufunc 31295 for i in range(len(A)): 31296 r = op(r, A[i]) 31297 return r 31298 31299 For example, add.reduce() is equivalent to sum(). 31300 31301 Parameters 31302 ---------- 31303 a : array_like 31304 The array to act on. 31305 axis : None or int or tuple of ints, optional 31306 Axis or axes along which a reduction is performed. 31307 The default (`axis` = 0) is perform a reduction over the first 31308 dimension of the input array. `axis` may be negative, in 31309 which case it counts from the last to the first axis. 31310 31311 .. versionadded:: 1.7.0 31312 31313 If this is `None`, a reduction is performed over all the axes. 31314 If this is a tuple of ints, a reduction is performed on multiple 31315 axes, instead of a single axis or all the axes as before. 31316 31317 For operations which are either not commutative or not associative, 31318 doing a reduction over multiple axes is not well-defined. The 31319 ufuncs do not currently raise an exception in this case, but will 31320 likely do so in the future. 31321 dtype : data-type code, optional 31322 The type used to represent the intermediate results. Defaults 31323 to the data-type of the output array if this is provided, or 31324 the data-type of the input array if no output array is provided. 31325 out : ndarray, optional 31326 A location into which the result is stored. If not provided, a 31327 freshly-allocated array is returned. 31328 keepdims : bool, optional 31329 If this is set to True, the axes which are reduced are left 31330 in the result as dimensions with size one. With this option, 31331 the result will broadcast correctly against the original `arr`. 31332 31333 Returns 31334 ------- 31335 r : ndarray 31336 The reduced array. If `out` was supplied, `r` is a reference to it. 31337 31338 Examples 31339 -------- 31340 >>> np.multiply.reduce([2,3,5]) 31341 30 31342 31343 A multi-dimensional array example: 31344 31345 >>> X = np.arange(8).reshape((2,2,2)) 31346 >>> X 31347 array([[[0, 1], 31348 [2, 3]], 31349 [[4, 5], 31350 [6, 7]]]) 31351 >>> np.add.reduce(X, 0) 31352 array([[ 4, 6], 31353 [ 8, 10]]) 31354 >>> np.add.reduce(X) # confirm: default axis value is 0 31355 array([[ 4, 6], 31356 [ 8, 10]]) 31357 >>> np.add.reduce(X, 1) 31358 array([[ 2, 4], 31359 [10, 12]]) 31360 >>> np.add.reduce(X, 2) 31361 array([[ 1, 5], 31362 [ 9, 13]])""" 31363 return ndarray() 31364 def reduceat(self, a, indices, axis, dtype, out): 31365 """reduceat(a, indices, axis=0, dtype=None, out=None) 31366 31367 Performs a (local) reduce with specified slices over a single axis. 31368 31369 For i in ``range(len(indices))``, `reduceat` computes 31370 ``ufunc.reduce(a[indices[i]:indices[i+1]])``, which becomes the i-th 31371 generalized "row" parallel to `axis` in the final result (i.e., in a 31372 2-D array, for example, if `axis = 0`, it becomes the i-th row, but if 31373 `axis = 1`, it becomes the i-th column). There are two exceptions to this: 31374 31375 * when ``i = len(indices) - 1`` (so for the last index), 31376 ``indices[i+1] = a.shape[axis]``. 31377 * if ``indices[i] >= indices[i + 1]``, the i-th generalized "row" is 31378 simply ``a[indices[i]]``. 31379 31380 The shape of the output depends on the size of `indices`, and may be 31381 larger than `a` (this happens if ``len(indices) > a.shape[axis]``). 31382 31383 Parameters 31384 ---------- 31385 a : array_like 31386 The array to act on. 31387 indices : array_like 31388 Paired indices, comma separated (not colon), specifying slices to 31389 reduce. 31390 axis : int, optional 31391 The axis along which to apply the reduceat. 31392 dtype : data-type code, optional 31393 The type used to represent the intermediate results. Defaults 31394 to the data type of the output array if this is provided, or 31395 the data type of the input array if no output array is provided. 31396 out : ndarray, optional 31397 A location into which the result is stored. If not provided a 31398 freshly-allocated array is returned. 31399 31400 Returns 31401 ------- 31402 r : ndarray 31403 The reduced values. If `out` was supplied, `r` is a reference to 31404 `out`. 31405 31406 Notes 31407 ----- 31408 A descriptive example: 31409 31410 If `a` is 1-D, the function `ufunc.accumulate(a)` is the same as 31411 ``ufunc.reduceat(a, indices)[::2]`` where `indices` is 31412 ``range(len(array) - 1)`` with a zero placed 31413 in every other element: 31414 ``indices = zeros(2 * len(a) - 1)``, ``indices[1::2] = range(1, len(a))``. 31415 31416 Don't be fooled by this attribute's name: `reduceat(a)` is not 31417 necessarily smaller than `a`. 31418 31419 Examples 31420 -------- 31421 To take the running sum of four successive values: 31422 31423 >>> np.add.reduceat(np.arange(8),[0,4, 1,5, 2,6, 3,7])[::2] 31424 array([ 6, 10, 14, 18]) 31425 31426 A 2-D example: 31427 31428 >>> x = np.linspace(0, 15, 16).reshape(4,4) 31429 >>> x 31430 array([[ 0., 1., 2., 3.], 31431 [ 4., 5., 6., 7.], 31432 [ 8., 9., 10., 11.], 31433 [ 12., 13., 14., 15.]]) 31434 31435 :: 31436 31437 # reduce such that the result has the following five rows: 31438 # [row1 + row2 + row3] 31439 # [row4] 31440 # [row2] 31441 # [row3] 31442 # [row1 + row2 + row3 + row4] 31443 31444 >>> np.add.reduceat(x, [0, 3, 1, 2, 0]) 31445 array([[ 12., 15., 18., 21.], 31446 [ 12., 13., 14., 15.], 31447 [ 4., 5., 6., 7.], 31448 [ 8., 9., 10., 11.], 31449 [ 24., 28., 32., 36.]]) 31450 31451 :: 31452 31453 # reduce such that result has the following two columns: 31454 # [col1 * col2 * col3, col4] 31455 31456 >>> np.multiply.reduceat(x, [0, 3], 1) 31457 array([[ 0., 3.], 31458 [ 120., 7.], 31459 [ 720., 11.], 31460 [ 2184., 15.]])""" 31461 return ndarray() 31462 signature = getset_descriptor() 31463 types = getset_descriptor() 31464 class uint64: 31465 T = getset_descriptor() 31466 __array_interface__ = getset_descriptor() 31467 __array_priority__ = getset_descriptor() 31468 __array_struct__ = getset_descriptor() 31469 __doc__ = None 31470 base = getset_descriptor() 31471 def conj(self, _): 31472 """None""" 31473 return None 31474 data = getset_descriptor() 31475 dtype = getset_descriptor() 31476 flags = getset_descriptor() 31477 flat = getset_descriptor() 31478 imag = getset_descriptor() 31479 itemsize = getset_descriptor() 31480 nbytes = getset_descriptor() 31481 ndim = getset_descriptor() 31482 def newbyteorder(self, new_order): 31483 """newbyteorder(new_order='S') 31484 31485 Return a new `dtype` with a different byte order. 31486 31487 Changes are also made in all fields and sub-arrays of the data type. 31488 31489 The `new_order` code can be any from the following: 31490 31491 * {'<', 'L'} - little endian 31492 * {'>', 'B'} - big endian 31493 * {'=', 'N'} - native order 31494 * 'S' - swap dtype from current to opposite endian 31495 * {'|', 'I'} - ignore (no change to byte order) 31496 31497 Parameters 31498 ---------- 31499 new_order : str, optional 31500 Byte order to force; a value from the byte order specifications 31501 above. The default value ('S') results in swapping the current 31502 byte order. The code does a case-insensitive check on the first 31503 letter of `new_order` for the alternatives above. For example, 31504 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 31505 31506 31507 Returns 31508 ------- 31509 new_dtype : dtype 31510 New `dtype` object with the given change to the byte order.""" 31511 return dtype() 31512 real = getset_descriptor() 31513 shape = getset_descriptor() 31514 size = getset_descriptor() 31515 strides = getset_descriptor() 31516 class uint64: 31517 T = getset_descriptor() 31518 __array_interface__ = getset_descriptor() 31519 __array_priority__ = getset_descriptor() 31520 __array_struct__ = getset_descriptor() 31521 __doc__ = None 31522 base = getset_descriptor() 31523 def conj(self, _): 31524 """None""" 31525 return None 31526 data = getset_descriptor() 31527 dtype = getset_descriptor() 31528 flags = getset_descriptor() 31529 flat = getset_descriptor() 31530 imag = getset_descriptor() 31531 itemsize = getset_descriptor() 31532 nbytes = getset_descriptor() 31533 ndim = getset_descriptor() 31534 def newbyteorder(self, new_order): 31535 """newbyteorder(new_order='S') 31536 31537 Return a new `dtype` with a different byte order. 31538 31539 Changes are also made in all fields and sub-arrays of the data type. 31540 31541 The `new_order` code can be any from the following: 31542 31543 * {'<', 'L'} - little endian 31544 * {'>', 'B'} - big endian 31545 * {'=', 'N'} - native order 31546 * 'S' - swap dtype from current to opposite endian 31547 * {'|', 'I'} - ignore (no change to byte order) 31548 31549 Parameters 31550 ---------- 31551 new_order : str, optional 31552 Byte order to force; a value from the byte order specifications 31553 above. The default value ('S') results in swapping the current 31554 byte order. The code does a case-insensitive check on the first 31555 letter of `new_order` for the alternatives above. For example, 31556 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 31557 31558 31559 Returns 31560 ------- 31561 new_dtype : dtype 31562 New `dtype` object with the given change to the byte order.""" 31563 return dtype() 31564 real = getset_descriptor() 31565 shape = getset_descriptor() 31566 size = getset_descriptor() 31567 strides = getset_descriptor() 31568 class uint16: 31569 T = getset_descriptor() 31570 __array_interface__ = getset_descriptor() 31571 __array_priority__ = getset_descriptor() 31572 __array_struct__ = getset_descriptor() 31573 __doc__ = None 31574 base = getset_descriptor() 31575 def conj(self, _): 31576 """None""" 31577 return None 31578 data = getset_descriptor() 31579 dtype = getset_descriptor() 31580 flags = getset_descriptor() 31581 flat = getset_descriptor() 31582 imag = getset_descriptor() 31583 itemsize = getset_descriptor() 31584 nbytes = getset_descriptor() 31585 ndim = getset_descriptor() 31586 def newbyteorder(self, new_order): 31587 """newbyteorder(new_order='S') 31588 31589 Return a new `dtype` with a different byte order. 31590 31591 Changes are also made in all fields and sub-arrays of the data type. 31592 31593 The `new_order` code can be any from the following: 31594 31595 * {'<', 'L'} - little endian 31596 * {'>', 'B'} - big endian 31597 * {'=', 'N'} - native order 31598 * 'S' - swap dtype from current to opposite endian 31599 * {'|', 'I'} - ignore (no change to byte order) 31600 31601 Parameters 31602 ---------- 31603 new_order : str, optional 31604 Byte order to force; a value from the byte order specifications 31605 above. The default value ('S') results in swapping the current 31606 byte order. The code does a case-insensitive check on the first 31607 letter of `new_order` for the alternatives above. For example, 31608 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 31609 31610 31611 Returns 31612 ------- 31613 new_dtype : dtype 31614 New `dtype` object with the given change to the byte order.""" 31615 return dtype() 31616 real = getset_descriptor() 31617 shape = getset_descriptor() 31618 size = getset_descriptor() 31619 strides = getset_descriptor() 31620 class uint32: 31621 T = getset_descriptor() 31622 __array_interface__ = getset_descriptor() 31623 __array_priority__ = getset_descriptor() 31624 __array_struct__ = getset_descriptor() 31625 __doc__ = None 31626 base = getset_descriptor() 31627 def conj(self, _): 31628 """None""" 31629 return None 31630 data = getset_descriptor() 31631 dtype = getset_descriptor() 31632 flags = getset_descriptor() 31633 flat = getset_descriptor() 31634 imag = getset_descriptor() 31635 itemsize = getset_descriptor() 31636 nbytes = getset_descriptor() 31637 ndim = getset_descriptor() 31638 def newbyteorder(self, new_order): 31639 """newbyteorder(new_order='S') 31640 31641 Return a new `dtype` with a different byte order. 31642 31643 Changes are also made in all fields and sub-arrays of the data type. 31644 31645 The `new_order` code can be any from the following: 31646 31647 * {'<', 'L'} - little endian 31648 * {'>', 'B'} - big endian 31649 * {'=', 'N'} - native order 31650 * 'S' - swap dtype from current to opposite endian 31651 * {'|', 'I'} - ignore (no change to byte order) 31652 31653 Parameters 31654 ---------- 31655 new_order : str, optional 31656 Byte order to force; a value from the byte order specifications 31657 above. The default value ('S') results in swapping the current 31658 byte order. The code does a case-insensitive check on the first 31659 letter of `new_order` for the alternatives above. For example, 31660 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 31661 31662 31663 Returns 31664 ------- 31665 new_dtype : dtype 31666 New `dtype` object with the given change to the byte order.""" 31667 return dtype() 31668 real = getset_descriptor() 31669 shape = getset_descriptor() 31670 size = getset_descriptor() 31671 strides = getset_descriptor() 31672 class uint64: 31673 T = getset_descriptor() 31674 __array_interface__ = getset_descriptor() 31675 __array_priority__ = getset_descriptor() 31676 __array_struct__ = getset_descriptor() 31677 __doc__ = None 31678 base = getset_descriptor() 31679 def conj(self, _): 31680 """None""" 31681 return None 31682 data = getset_descriptor() 31683 dtype = getset_descriptor() 31684 flags = getset_descriptor() 31685 flat = getset_descriptor() 31686 imag = getset_descriptor() 31687 itemsize = getset_descriptor() 31688 nbytes = getset_descriptor() 31689 ndim = getset_descriptor() 31690 def newbyteorder(self, new_order): 31691 """newbyteorder(new_order='S') 31692 31693 Return a new `dtype` with a different byte order. 31694 31695 Changes are also made in all fields and sub-arrays of the data type. 31696 31697 The `new_order` code can be any from the following: 31698 31699 * {'<', 'L'} - little endian 31700 * {'>', 'B'} - big endian 31701 * {'=', 'N'} - native order 31702 * 'S' - swap dtype from current to opposite endian 31703 * {'|', 'I'} - ignore (no change to byte order) 31704 31705 Parameters 31706 ---------- 31707 new_order : str, optional 31708 Byte order to force; a value from the byte order specifications 31709 above. The default value ('S') results in swapping the current 31710 byte order. The code does a case-insensitive check on the first 31711 letter of `new_order` for the alternatives above. For example, 31712 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 31713 31714 31715 Returns 31716 ------- 31717 new_dtype : dtype 31718 New `dtype` object with the given change to the byte order.""" 31719 return dtype() 31720 real = getset_descriptor() 31721 shape = getset_descriptor() 31722 size = getset_descriptor() 31723 strides = getset_descriptor() 31724 class uint8: 31725 T = getset_descriptor() 31726 __array_interface__ = getset_descriptor() 31727 __array_priority__ = getset_descriptor() 31728 __array_struct__ = getset_descriptor() 31729 __doc__ = None 31730 base = getset_descriptor() 31731 def conj(self, _): 31732 """None""" 31733 return None 31734 data = getset_descriptor() 31735 dtype = getset_descriptor() 31736 flags = getset_descriptor() 31737 flat = getset_descriptor() 31738 imag = getset_descriptor() 31739 itemsize = getset_descriptor() 31740 nbytes = getset_descriptor() 31741 ndim = getset_descriptor() 31742 def newbyteorder(self, new_order): 31743 """newbyteorder(new_order='S') 31744 31745 Return a new `dtype` with a different byte order. 31746 31747 Changes are also made in all fields and sub-arrays of the data type. 31748 31749 The `new_order` code can be any from the following: 31750 31751 * {'<', 'L'} - little endian 31752 * {'>', 'B'} - big endian 31753 * {'=', 'N'} - native order 31754 * 'S' - swap dtype from current to opposite endian 31755 * {'|', 'I'} - ignore (no change to byte order) 31756 31757 Parameters 31758 ---------- 31759 new_order : str, optional 31760 Byte order to force; a value from the byte order specifications 31761 above. The default value ('S') results in swapping the current 31762 byte order. The code does a case-insensitive check on the first 31763 letter of `new_order` for the alternatives above. For example, 31764 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 31765 31766 31767 Returns 31768 ------- 31769 new_dtype : dtype 31770 New `dtype` object with the given change to the byte order.""" 31771 return dtype() 31772 real = getset_descriptor() 31773 shape = getset_descriptor() 31774 size = getset_descriptor() 31775 strides = getset_descriptor() 31776 class uint32: 31777 T = getset_descriptor() 31778 __array_interface__ = getset_descriptor() 31779 __array_priority__ = getset_descriptor() 31780 __array_struct__ = getset_descriptor() 31781 __doc__ = None 31782 base = getset_descriptor() 31783 def conj(self, _): 31784 """None""" 31785 return None 31786 data = getset_descriptor() 31787 dtype = getset_descriptor() 31788 flags = getset_descriptor() 31789 flat = getset_descriptor() 31790 imag = getset_descriptor() 31791 itemsize = getset_descriptor() 31792 nbytes = getset_descriptor() 31793 ndim = getset_descriptor() 31794 def newbyteorder(self, new_order): 31795 """newbyteorder(new_order='S') 31796 31797 Return a new `dtype` with a different byte order. 31798 31799 Changes are also made in all fields and sub-arrays of the data type. 31800 31801 The `new_order` code can be any from the following: 31802 31803 * {'<', 'L'} - little endian 31804 * {'>', 'B'} - big endian 31805 * {'=', 'N'} - native order 31806 * 'S' - swap dtype from current to opposite endian 31807 * {'|', 'I'} - ignore (no change to byte order) 31808 31809 Parameters 31810 ---------- 31811 new_order : str, optional 31812 Byte order to force; a value from the byte order specifications 31813 above. The default value ('S') results in swapping the current 31814 byte order. The code does a case-insensitive check on the first 31815 letter of `new_order` for the alternatives above. For example, 31816 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 31817 31818 31819 Returns 31820 ------- 31821 new_dtype : dtype 31822 New `dtype` object with the given change to the byte order.""" 31823 return dtype() 31824 real = getset_descriptor() 31825 shape = getset_descriptor() 31826 size = getset_descriptor() 31827 strides = getset_descriptor() 31828 class uint64: 31829 T = getset_descriptor() 31830 __array_interface__ = getset_descriptor() 31831 __array_priority__ = getset_descriptor() 31832 __array_struct__ = getset_descriptor() 31833 __doc__ = None 31834 base = getset_descriptor() 31835 def conj(self, _): 31836 """None""" 31837 return None 31838 data = getset_descriptor() 31839 dtype = getset_descriptor() 31840 flags = getset_descriptor() 31841 flat = getset_descriptor() 31842 imag = getset_descriptor() 31843 itemsize = getset_descriptor() 31844 nbytes = getset_descriptor() 31845 ndim = getset_descriptor() 31846 def newbyteorder(self, new_order): 31847 """newbyteorder(new_order='S') 31848 31849 Return a new `dtype` with a different byte order. 31850 31851 Changes are also made in all fields and sub-arrays of the data type. 31852 31853 The `new_order` code can be any from the following: 31854 31855 * {'<', 'L'} - little endian 31856 * {'>', 'B'} - big endian 31857 * {'=', 'N'} - native order 31858 * 'S' - swap dtype from current to opposite endian 31859 * {'|', 'I'} - ignore (no change to byte order) 31860 31861 Parameters 31862 ---------- 31863 new_order : str, optional 31864 Byte order to force; a value from the byte order specifications 31865 above. The default value ('S') results in swapping the current 31866 byte order. The code does a case-insensitive check on the first 31867 letter of `new_order` for the alternatives above. For example, 31868 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 31869 31870 31871 Returns 31872 ------- 31873 new_dtype : dtype 31874 New `dtype` object with the given change to the byte order.""" 31875 return dtype() 31876 real = getset_descriptor() 31877 shape = getset_descriptor() 31878 size = getset_descriptor() 31879 strides = getset_descriptor() 31880 class uint64: 31881 T = getset_descriptor() 31882 __array_interface__ = getset_descriptor() 31883 __array_priority__ = getset_descriptor() 31884 __array_struct__ = getset_descriptor() 31885 __doc__ = None 31886 base = getset_descriptor() 31887 def conj(self, _): 31888 """None""" 31889 return None 31890 data = getset_descriptor() 31891 dtype = getset_descriptor() 31892 flags = getset_descriptor() 31893 flat = getset_descriptor() 31894 imag = getset_descriptor() 31895 itemsize = getset_descriptor() 31896 nbytes = getset_descriptor() 31897 ndim = getset_descriptor() 31898 def newbyteorder(self, new_order): 31899 """newbyteorder(new_order='S') 31900 31901 Return a new `dtype` with a different byte order. 31902 31903 Changes are also made in all fields and sub-arrays of the data type. 31904 31905 The `new_order` code can be any from the following: 31906 31907 * {'<', 'L'} - little endian 31908 * {'>', 'B'} - big endian 31909 * {'=', 'N'} - native order 31910 * 'S' - swap dtype from current to opposite endian 31911 * {'|', 'I'} - ignore (no change to byte order) 31912 31913 Parameters 31914 ---------- 31915 new_order : str, optional 31916 Byte order to force; a value from the byte order specifications 31917 above. The default value ('S') results in swapping the current 31918 byte order. The code does a case-insensitive check on the first 31919 letter of `new_order` for the alternatives above. For example, 31920 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 31921 31922 31923 Returns 31924 ------- 31925 new_dtype : dtype 31926 New `dtype` object with the given change to the byte order.""" 31927 return dtype() 31928 real = getset_descriptor() 31929 shape = getset_descriptor() 31930 size = getset_descriptor() 31931 strides = getset_descriptor() 31932 class unicode: 31933 __doc__ = str() 31934 def _formatter_field_name_split(self, _): 31935 """None""" 31936 return None 31937 def _formatter_parser(self, _): 31938 """None""" 31939 return None 31940 def capitalize(self, _): 31941 """S.capitalize() -> unicode 31942 31943 Return a capitalized version of S, i.e. make the first character 31944 have upper case and the rest lower case.""" 31945 return None 31946 def center(self, width, fillchar): 31947 """S.center(width[, fillchar]) -> unicode 31948 31949 Return S centered in a Unicode string of length width. Padding is 31950 done using the specified fill character (default is a space)""" 31951 return None 31952 def count(self, sub, start, end): 31953 """S.count(sub[, start[, end]]) -> int 31954 31955 Return the number of non-overlapping occurrences of substring sub in 31956 Unicode string S[start:end]. Optional arguments start and end are 31957 interpreted as in slice notation.""" 31958 return None 31959 def decode(self, encoding, errors): 31960 """S.decode([encoding[,errors]]) -> string or unicode 31961 31962 Decodes S using the codec registered for encoding. encoding defaults 31963 to the default encoding. errors may be given to set a different error 31964 handling scheme. Default is 'strict' meaning that encoding errors raise 31965 a UnicodeDecodeError. Other possible values are 'ignore' and 'replace' 31966 as well as any other name registered with codecs.register_error that is 31967 able to handle UnicodeDecodeErrors.""" 31968 return None 31969 def encode(self, encoding, errors): 31970 """S.encode([encoding[,errors]]) -> string or unicode 31971 31972 Encodes S using the codec registered for encoding. encoding defaults 31973 to the default encoding. errors may be given to set a different error 31974 handling scheme. Default is 'strict' meaning that encoding errors raise 31975 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 31976 'xmlcharrefreplace' as well as any other name registered with 31977 codecs.register_error that can handle UnicodeEncodeErrors.""" 31978 return None 31979 def endswith(self, suffix, start, end): 31980 """S.endswith(suffix[, start[, end]]) -> bool 31981 31982 Return True if S ends with the specified suffix, False otherwise. 31983 With optional start, test S beginning at that position. 31984 With optional end, stop comparing S at that position. 31985 suffix can also be a tuple of strings to try.""" 31986 return None 31987 def expandtabs(self, tabsize): 31988 """S.expandtabs([tabsize]) -> unicode 31989 31990 Return a copy of S where all tab characters are expanded using spaces. 31991 If tabsize is not given, a tab size of 8 characters is assumed.""" 31992 return None 31993 def find(self, sub, start, end): 31994 """S.find(sub [,start [,end]]) -> int 31995 31996 Return the lowest index in S where substring sub is found, 31997 such that sub is contained within S[start:end]. Optional 31998 arguments start and end are interpreted as in slice notation. 31999 32000 Return -1 on failure.""" 32001 return None 32002 def format(self, args, kwargs): 32003 """S.format(*args, **kwargs) -> unicode 32004 32005 Return a formatted version of S, using substitutions from args and kwargs. 32006 The substitutions are identified by braces ('{' and '}').""" 32007 return None 32008 def index(self, sub, start, end): 32009 """S.index(sub [,start [,end]]) -> int 32010 32011 Like S.find() but raise ValueError when the substring is not found.""" 32012 return None 32013 def isalnum(self, _): 32014 """S.isalnum() -> bool 32015 32016 Return True if all characters in S are alphanumeric 32017 and there is at least one character in S, False otherwise.""" 32018 return None 32019 def isalpha(self, _): 32020 """S.isalpha() -> bool 32021 32022 Return True if all characters in S are alphabetic 32023 and there is at least one character in S, False otherwise.""" 32024 return None 32025 def isdecimal(self, _): 32026 """S.isdecimal() -> bool 32027 32028 Return True if there are only decimal characters in S, 32029 False otherwise.""" 32030 return None 32031 def isdigit(self, _): 32032 """S.isdigit() -> bool 32033 32034 Return True if all characters in S are digits 32035 and there is at least one character in S, False otherwise.""" 32036 return None 32037 def islower(self, _): 32038 """S.islower() -> bool 32039 32040 Return True if all cased characters in S are lowercase and there is 32041 at least one cased character in S, False otherwise.""" 32042 return None 32043 def isnumeric(self, _): 32044 """S.isnumeric() -> bool 32045 32046 Return True if there are only numeric characters in S, 32047 False otherwise.""" 32048 return None 32049 def isspace(self, _): 32050 """S.isspace() -> bool 32051 32052 Return True if all characters in S are whitespace 32053 and there is at least one character in S, False otherwise.""" 32054 return None 32055 def istitle(self, _): 32056 """S.istitle() -> bool 32057 32058 Return True if S is a titlecased string and there is at least one 32059 character in S, i.e. upper- and titlecase characters may only 32060 follow uncased characters and lowercase characters only cased ones. 32061 Return False otherwise.""" 32062 return None 32063 def isupper(self, _): 32064 """S.isupper() -> bool 32065 32066 Return True if all cased characters in S are uppercase and there is 32067 at least one cased character in S, False otherwise.""" 32068 return None 32069 def join(self, iterable): 32070 """S.join(iterable) -> unicode 32071 32072 Return a string which is the concatenation of the strings in the 32073 iterable. The separator between elements is S.""" 32074 return None 32075 def ljust(self, width, fillchar): 32076 """S.ljust(width[, fillchar]) -> int 32077 32078 Return S left-justified in a Unicode string of length width. Padding is 32079 done using the specified fill character (default is a space).""" 32080 return None 32081 def lower(self, _): 32082 """S.lower() -> unicode 32083 32084 Return a copy of the string S converted to lowercase.""" 32085 return None 32086 def lstrip(self, chars): 32087 """S.lstrip([chars]) -> unicode 32088 32089 Return a copy of the string S with leading whitespace removed. 32090 If chars is given and not None, remove characters in chars instead. 32091 If chars is a str, it will be converted to unicode before stripping""" 32092 return None 32093 def partition(self, sep): 32094 """S.partition(sep) -> (head, sep, tail) 32095 32096 Search for the separator sep in S, and return the part before it, 32097 the separator itself, and the part after it. If the separator is not 32098 found, return S and two empty strings.""" 32099 return None 32100 def replace(self, old, new, count): 32101 """S.replace(old, new[, count]) -> unicode 32102 32103 Return a copy of S with all occurrences of substring 32104 old replaced by new. If the optional argument count is 32105 given, only the first count occurrences are replaced.""" 32106 return None 32107 def rfind(self, sub, start, end): 32108 """S.rfind(sub [,start [,end]]) -> int 32109 32110 Return the highest index in S where substring sub is found, 32111 such that sub is contained within S[start:end]. Optional 32112 arguments start and end are interpreted as in slice notation. 32113 32114 Return -1 on failure.""" 32115 return None 32116 def rindex(self, sub, start, end): 32117 """S.rindex(sub [,start [,end]]) -> int 32118 32119 Like S.rfind() but raise ValueError when the substring is not found.""" 32120 return None 32121 def rjust(self, width, fillchar): 32122 """S.rjust(width[, fillchar]) -> unicode 32123 32124 Return S right-justified in a Unicode string of length width. Padding is 32125 done using the specified fill character (default is a space).""" 32126 return None 32127 def rpartition(self, sep): 32128 """S.rpartition(sep) -> (head, sep, tail) 32129 32130 Search for the separator sep in S, starting at the end of S, and return 32131 the part before it, the separator itself, and the part after it. If the 32132 separator is not found, return two empty strings and S.""" 32133 return None 32134 def rsplit(self, sep, maxsplit): 32135 """S.rsplit([sep [,maxsplit]]) -> list of strings 32136 32137 Return a list of the words in S, using sep as the 32138 delimiter string, starting at the end of the string and 32139 working to the front. If maxsplit is given, at most maxsplit 32140 splits are done. If sep is not specified, any whitespace string 32141 is a separator.""" 32142 return None 32143 def rstrip(self, chars): 32144 """S.rstrip([chars]) -> unicode 32145 32146 Return a copy of the string S with trailing whitespace removed. 32147 If chars is given and not None, remove characters in chars instead. 32148 If chars is a str, it will be converted to unicode before stripping""" 32149 return None 32150 def split(self, sep, maxsplit): 32151 """S.split([sep [,maxsplit]]) -> list of strings 32152 32153 Return a list of the words in S, using sep as the 32154 delimiter string. If maxsplit is given, at most maxsplit 32155 splits are done. If sep is not specified or is None, any 32156 whitespace string is a separator and empty strings are 32157 removed from the result.""" 32158 return None 32159 def splitlines(self, keepends=False): 32160 """S.splitlines(keepends=False) -> list of strings 32161 32162 Return a list of the lines in S, breaking at line boundaries. 32163 Line breaks are not included in the resulting list unless keepends 32164 is given and true.""" 32165 return None 32166 def startswith(self, prefix, start, end): 32167 """S.startswith(prefix[, start[, end]]) -> bool 32168 32169 Return True if S starts with the specified prefix, False otherwise. 32170 With optional start, test S beginning at that position. 32171 With optional end, stop comparing S at that position. 32172 prefix can also be a tuple of strings to try.""" 32173 return None 32174 def strip(self, chars): 32175 """S.strip([chars]) -> unicode 32176 32177 Return a copy of the string S with leading and trailing 32178 whitespace removed. 32179 If chars is given and not None, remove characters in chars instead. 32180 If chars is a str, it will be converted to unicode before stripping""" 32181 return None 32182 def swapcase(self, _): 32183 """S.swapcase() -> unicode 32184 32185 Return a copy of S with uppercase characters converted to lowercase 32186 and vice versa.""" 32187 return None 32188 def title(self, _): 32189 """S.title() -> unicode 32190 32191 Return a titlecased version of S, i.e. words start with title case 32192 characters, all remaining cased characters have lower case.""" 32193 return None 32194 def translate(self, table): 32195 """S.translate(table) -> unicode 32196 32197 Return a copy of the string S, where all characters have been mapped 32198 through the given translation table, which must be a mapping of 32199 Unicode ordinals to Unicode ordinals, Unicode strings or None. 32200 Unmapped characters are left untouched. Characters mapped to None 32201 are deleted.""" 32202 return None 32203 def upper(self, _): 32204 """S.upper() -> unicode 32205 32206 Return a copy of S converted to uppercase.""" 32207 return None 32208 def zfill(self, width): 32209 """S.zfill(width) -> unicode 32210 32211 Pad a numeric string S with zeros on the left, to fill a field 32212 of the specified width. The string S is never truncated.""" 32213 return None 32214 class unicode_: 32215 T = getset_descriptor() 32216 __array_interface__ = getset_descriptor() 32217 __array_priority__ = getset_descriptor() 32218 __array_struct__ = getset_descriptor() 32219 __doc__ = None 32220 def _formatter_field_name_split(self, _): 32221 """None""" 32222 return None 32223 def _formatter_parser(self, _): 32224 """None""" 32225 return None 32226 base = getset_descriptor() 32227 def capitalize(self, _): 32228 """S.capitalize() -> unicode 32229 32230 Return a capitalized version of S, i.e. make the first character 32231 have upper case and the rest lower case.""" 32232 return None 32233 def center(self, width, fillchar): 32234 """S.center(width[, fillchar]) -> unicode 32235 32236 Return S centered in a Unicode string of length width. Padding is 32237 done using the specified fill character (default is a space)""" 32238 return None 32239 def conj(self, _): 32240 """None""" 32241 return None 32242 def count(self, sub, start, end): 32243 """S.count(sub[, start[, end]]) -> int 32244 32245 Return the number of non-overlapping occurrences of substring sub in 32246 Unicode string S[start:end]. Optional arguments start and end are 32247 interpreted as in slice notation.""" 32248 return None 32249 data = getset_descriptor() 32250 def decode(self, encoding, errors): 32251 """S.decode([encoding[,errors]]) -> string or unicode 32252 32253 Decodes S using the codec registered for encoding. encoding defaults 32254 to the default encoding. errors may be given to set a different error 32255 handling scheme. Default is 'strict' meaning that encoding errors raise 32256 a UnicodeDecodeError. Other possible values are 'ignore' and 'replace' 32257 as well as any other name registered with codecs.register_error that is 32258 able to handle UnicodeDecodeErrors.""" 32259 return None 32260 dtype = getset_descriptor() 32261 def encode(self, encoding, errors): 32262 """S.encode([encoding[,errors]]) -> string or unicode 32263 32264 Encodes S using the codec registered for encoding. encoding defaults 32265 to the default encoding. errors may be given to set a different error 32266 handling scheme. Default is 'strict' meaning that encoding errors raise 32267 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 32268 'xmlcharrefreplace' as well as any other name registered with 32269 codecs.register_error that can handle UnicodeEncodeErrors.""" 32270 return None 32271 def endswith(self, suffix, start, end): 32272 """S.endswith(suffix[, start[, end]]) -> bool 32273 32274 Return True if S ends with the specified suffix, False otherwise. 32275 With optional start, test S beginning at that position. 32276 With optional end, stop comparing S at that position. 32277 suffix can also be a tuple of strings to try.""" 32278 return None 32279 def expandtabs(self, tabsize): 32280 """S.expandtabs([tabsize]) -> unicode 32281 32282 Return a copy of S where all tab characters are expanded using spaces. 32283 If tabsize is not given, a tab size of 8 characters is assumed.""" 32284 return None 32285 def find(self, sub, start, end): 32286 """S.find(sub [,start [,end]]) -> int 32287 32288 Return the lowest index in S where substring sub is found, 32289 such that sub is contained within S[start:end]. Optional 32290 arguments start and end are interpreted as in slice notation. 32291 32292 Return -1 on failure.""" 32293 return None 32294 flags = getset_descriptor() 32295 flat = getset_descriptor() 32296 def format(self, args, kwargs): 32297 """S.format(*args, **kwargs) -> unicode 32298 32299 Return a formatted version of S, using substitutions from args and kwargs. 32300 The substitutions are identified by braces ('{' and '}').""" 32301 return None 32302 imag = getset_descriptor() 32303 def index(self, sub, start, end): 32304 """S.index(sub [,start [,end]]) -> int 32305 32306 Like S.find() but raise ValueError when the substring is not found.""" 32307 return None 32308 def isalnum(self, _): 32309 """S.isalnum() -> bool 32310 32311 Return True if all characters in S are alphanumeric 32312 and there is at least one character in S, False otherwise.""" 32313 return None 32314 def isalpha(self, _): 32315 """S.isalpha() -> bool 32316 32317 Return True if all characters in S are alphabetic 32318 and there is at least one character in S, False otherwise.""" 32319 return None 32320 def isdecimal(self, _): 32321 """S.isdecimal() -> bool 32322 32323 Return True if there are only decimal characters in S, 32324 False otherwise.""" 32325 return None 32326 def isdigit(self, _): 32327 """S.isdigit() -> bool 32328 32329 Return True if all characters in S are digits 32330 and there is at least one character in S, False otherwise.""" 32331 return None 32332 def islower(self, _): 32333 """S.islower() -> bool 32334 32335 Return True if all cased characters in S are lowercase and there is 32336 at least one cased character in S, False otherwise.""" 32337 return None 32338 def isnumeric(self, _): 32339 """S.isnumeric() -> bool 32340 32341 Return True if there are only numeric characters in S, 32342 False otherwise.""" 32343 return None 32344 def isspace(self, _): 32345 """S.isspace() -> bool 32346 32347 Return True if all characters in S are whitespace 32348 and there is at least one character in S, False otherwise.""" 32349 return None 32350 def istitle(self, _): 32351 """S.istitle() -> bool 32352 32353 Return True if S is a titlecased string and there is at least one 32354 character in S, i.e. upper- and titlecase characters may only 32355 follow uncased characters and lowercase characters only cased ones. 32356 Return False otherwise.""" 32357 return None 32358 def isupper(self, _): 32359 """S.isupper() -> bool 32360 32361 Return True if all cased characters in S are uppercase and there is 32362 at least one cased character in S, False otherwise.""" 32363 return None 32364 itemsize = getset_descriptor() 32365 def join(self, iterable): 32366 """S.join(iterable) -> unicode 32367 32368 Return a string which is the concatenation of the strings in the 32369 iterable. The separator between elements is S.""" 32370 return None 32371 def ljust(self, width, fillchar): 32372 """S.ljust(width[, fillchar]) -> int 32373 32374 Return S left-justified in a Unicode string of length width. Padding is 32375 done using the specified fill character (default is a space).""" 32376 return None 32377 def lower(self, _): 32378 """S.lower() -> unicode 32379 32380 Return a copy of the string S converted to lowercase.""" 32381 return None 32382 def lstrip(self, chars): 32383 """S.lstrip([chars]) -> unicode 32384 32385 Return a copy of the string S with leading whitespace removed. 32386 If chars is given and not None, remove characters in chars instead. 32387 If chars is a str, it will be converted to unicode before stripping""" 32388 return None 32389 nbytes = getset_descriptor() 32390 ndim = getset_descriptor() 32391 def newbyteorder(self, new_order): 32392 """newbyteorder(new_order='S') 32393 32394 Return a new `dtype` with a different byte order. 32395 32396 Changes are also made in all fields and sub-arrays of the data type. 32397 32398 The `new_order` code can be any from the following: 32399 32400 * {'<', 'L'} - little endian 32401 * {'>', 'B'} - big endian 32402 * {'=', 'N'} - native order 32403 * 'S' - swap dtype from current to opposite endian 32404 * {'|', 'I'} - ignore (no change to byte order) 32405 32406 Parameters 32407 ---------- 32408 new_order : str, optional 32409 Byte order to force; a value from the byte order specifications 32410 above. The default value ('S') results in swapping the current 32411 byte order. The code does a case-insensitive check on the first 32412 letter of `new_order` for the alternatives above. For example, 32413 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 32414 32415 32416 Returns 32417 ------- 32418 new_dtype : dtype 32419 New `dtype` object with the given change to the byte order.""" 32420 return dtype() 32421 def partition(self, sep): 32422 """S.partition(sep) -> (head, sep, tail) 32423 32424 Search for the separator sep in S, and return the part before it, 32425 the separator itself, and the part after it. If the separator is not 32426 found, return S and two empty strings.""" 32427 return None 32428 real = getset_descriptor() 32429 def replace(self, old, new, count): 32430 """S.replace(old, new[, count]) -> unicode 32431 32432 Return a copy of S with all occurrences of substring 32433 old replaced by new. If the optional argument count is 32434 given, only the first count occurrences are replaced.""" 32435 return None 32436 def rfind(self, sub, start, end): 32437 """S.rfind(sub [,start [,end]]) -> int 32438 32439 Return the highest index in S where substring sub is found, 32440 such that sub is contained within S[start:end]. Optional 32441 arguments start and end are interpreted as in slice notation. 32442 32443 Return -1 on failure.""" 32444 return None 32445 def rindex(self, sub, start, end): 32446 """S.rindex(sub [,start [,end]]) -> int 32447 32448 Like S.rfind() but raise ValueError when the substring is not found.""" 32449 return None 32450 def rjust(self, width, fillchar): 32451 """S.rjust(width[, fillchar]) -> unicode 32452 32453 Return S right-justified in a Unicode string of length width. Padding is 32454 done using the specified fill character (default is a space).""" 32455 return None 32456 def rpartition(self, sep): 32457 """S.rpartition(sep) -> (head, sep, tail) 32458 32459 Search for the separator sep in S, starting at the end of S, and return 32460 the part before it, the separator itself, and the part after it. If the 32461 separator is not found, return two empty strings and S.""" 32462 return None 32463 def rsplit(self, sep, maxsplit): 32464 """S.rsplit([sep [,maxsplit]]) -> list of strings 32465 32466 Return a list of the words in S, using sep as the 32467 delimiter string, starting at the end of the string and 32468 working to the front. If maxsplit is given, at most maxsplit 32469 splits are done. If sep is not specified, any whitespace string 32470 is a separator.""" 32471 return None 32472 def rstrip(self, chars): 32473 """S.rstrip([chars]) -> unicode 32474 32475 Return a copy of the string S with trailing whitespace removed. 32476 If chars is given and not None, remove characters in chars instead. 32477 If chars is a str, it will be converted to unicode before stripping""" 32478 return None 32479 shape = getset_descriptor() 32480 size = getset_descriptor() 32481 def split(self, sep, maxsplit): 32482 """S.split([sep [,maxsplit]]) -> list of strings 32483 32484 Return a list of the words in S, using sep as the 32485 delimiter string. If maxsplit is given, at most maxsplit 32486 splits are done. If sep is not specified or is None, any 32487 whitespace string is a separator and empty strings are 32488 removed from the result.""" 32489 return None 32490 def splitlines(self, keepends=False): 32491 """S.splitlines(keepends=False) -> list of strings 32492 32493 Return a list of the lines in S, breaking at line boundaries. 32494 Line breaks are not included in the resulting list unless keepends 32495 is given and true.""" 32496 return None 32497 def startswith(self, prefix, start, end): 32498 """S.startswith(prefix[, start[, end]]) -> bool 32499 32500 Return True if S starts with the specified prefix, False otherwise. 32501 With optional start, test S beginning at that position. 32502 With optional end, stop comparing S at that position. 32503 prefix can also be a tuple of strings to try.""" 32504 return None 32505 strides = getset_descriptor() 32506 def strip(self, chars): 32507 """S.strip([chars]) -> unicode 32508 32509 Return a copy of the string S with leading and trailing 32510 whitespace removed. 32511 If chars is given and not None, remove characters in chars instead. 32512 If chars is a str, it will be converted to unicode before stripping""" 32513 return None 32514 def swapcase(self, _): 32515 """S.swapcase() -> unicode 32516 32517 Return a copy of S with uppercase characters converted to lowercase 32518 and vice versa.""" 32519 return None 32520 def title(self, _): 32521 """S.title() -> unicode 32522 32523 Return a titlecased version of S, i.e. words start with title case 32524 characters, all remaining cased characters have lower case.""" 32525 return None 32526 def translate(self, table): 32527 """S.translate(table) -> unicode 32528 32529 Return a copy of the string S, where all characters have been mapped 32530 through the given translation table, which must be a mapping of 32531 Unicode ordinals to Unicode ordinals, Unicode strings or None. 32532 Unmapped characters are left untouched. Characters mapped to None 32533 are deleted.""" 32534 return None 32535 def upper(self, _): 32536 """S.upper() -> unicode 32537 32538 Return a copy of S converted to uppercase.""" 32539 return None 32540 def zfill(self, width): 32541 """S.zfill(width) -> unicode 32542 32543 Pad a numeric string S with zeros on the left, to fill a field 32544 of the specified width. The string S is never truncated.""" 32545 return None 32546 class unicode_: 32547 T = getset_descriptor() 32548 __array_interface__ = getset_descriptor() 32549 __array_priority__ = getset_descriptor() 32550 __array_struct__ = getset_descriptor() 32551 __doc__ = None 32552 def _formatter_field_name_split(self, _): 32553 """None""" 32554 return None 32555 def _formatter_parser(self, _): 32556 """None""" 32557 return None 32558 base = getset_descriptor() 32559 def capitalize(self, _): 32560 """S.capitalize() -> unicode 32561 32562 Return a capitalized version of S, i.e. make the first character 32563 have upper case and the rest lower case.""" 32564 return None 32565 def center(self, width, fillchar): 32566 """S.center(width[, fillchar]) -> unicode 32567 32568 Return S centered in a Unicode string of length width. Padding is 32569 done using the specified fill character (default is a space)""" 32570 return None 32571 def conj(self, _): 32572 """None""" 32573 return None 32574 def count(self, sub, start, end): 32575 """S.count(sub[, start[, end]]) -> int 32576 32577 Return the number of non-overlapping occurrences of substring sub in 32578 Unicode string S[start:end]. Optional arguments start and end are 32579 interpreted as in slice notation.""" 32580 return None 32581 data = getset_descriptor() 32582 def decode(self, encoding, errors): 32583 """S.decode([encoding[,errors]]) -> string or unicode 32584 32585 Decodes S using the codec registered for encoding. encoding defaults 32586 to the default encoding. errors may be given to set a different error 32587 handling scheme. Default is 'strict' meaning that encoding errors raise 32588 a UnicodeDecodeError. Other possible values are 'ignore' and 'replace' 32589 as well as any other name registered with codecs.register_error that is 32590 able to handle UnicodeDecodeErrors.""" 32591 return None 32592 dtype = getset_descriptor() 32593 def encode(self, encoding, errors): 32594 """S.encode([encoding[,errors]]) -> string or unicode 32595 32596 Encodes S using the codec registered for encoding. encoding defaults 32597 to the default encoding. errors may be given to set a different error 32598 handling scheme. Default is 'strict' meaning that encoding errors raise 32599 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 32600 'xmlcharrefreplace' as well as any other name registered with 32601 codecs.register_error that can handle UnicodeEncodeErrors.""" 32602 return None 32603 def endswith(self, suffix, start, end): 32604 """S.endswith(suffix[, start[, end]]) -> bool 32605 32606 Return True if S ends with the specified suffix, False otherwise. 32607 With optional start, test S beginning at that position. 32608 With optional end, stop comparing S at that position. 32609 suffix can also be a tuple of strings to try.""" 32610 return None 32611 def expandtabs(self, tabsize): 32612 """S.expandtabs([tabsize]) -> unicode 32613 32614 Return a copy of S where all tab characters are expanded using spaces. 32615 If tabsize is not given, a tab size of 8 characters is assumed.""" 32616 return None 32617 def find(self, sub, start, end): 32618 """S.find(sub [,start [,end]]) -> int 32619 32620 Return the lowest index in S where substring sub is found, 32621 such that sub is contained within S[start:end]. Optional 32622 arguments start and end are interpreted as in slice notation. 32623 32624 Return -1 on failure.""" 32625 return None 32626 flags = getset_descriptor() 32627 flat = getset_descriptor() 32628 def format(self, args, kwargs): 32629 """S.format(*args, **kwargs) -> unicode 32630 32631 Return a formatted version of S, using substitutions from args and kwargs. 32632 The substitutions are identified by braces ('{' and '}').""" 32633 return None 32634 imag = getset_descriptor() 32635 def index(self, sub, start, end): 32636 """S.index(sub [,start [,end]]) -> int 32637 32638 Like S.find() but raise ValueError when the substring is not found.""" 32639 return None 32640 def isalnum(self, _): 32641 """S.isalnum() -> bool 32642 32643 Return True if all characters in S are alphanumeric 32644 and there is at least one character in S, False otherwise.""" 32645 return None 32646 def isalpha(self, _): 32647 """S.isalpha() -> bool 32648 32649 Return True if all characters in S are alphabetic 32650 and there is at least one character in S, False otherwise.""" 32651 return None 32652 def isdecimal(self, _): 32653 """S.isdecimal() -> bool 32654 32655 Return True if there are only decimal characters in S, 32656 False otherwise.""" 32657 return None 32658 def isdigit(self, _): 32659 """S.isdigit() -> bool 32660 32661 Return True if all characters in S are digits 32662 and there is at least one character in S, False otherwise.""" 32663 return None 32664 def islower(self, _): 32665 """S.islower() -> bool 32666 32667 Return True if all cased characters in S are lowercase and there is 32668 at least one cased character in S, False otherwise.""" 32669 return None 32670 def isnumeric(self, _): 32671 """S.isnumeric() -> bool 32672 32673 Return True if there are only numeric characters in S, 32674 False otherwise.""" 32675 return None 32676 def isspace(self, _): 32677 """S.isspace() -> bool 32678 32679 Return True if all characters in S are whitespace 32680 and there is at least one character in S, False otherwise.""" 32681 return None 32682 def istitle(self, _): 32683 """S.istitle() -> bool 32684 32685 Return True if S is a titlecased string and there is at least one 32686 character in S, i.e. upper- and titlecase characters may only 32687 follow uncased characters and lowercase characters only cased ones. 32688 Return False otherwise.""" 32689 return None 32690 def isupper(self, _): 32691 """S.isupper() -> bool 32692 32693 Return True if all cased characters in S are uppercase and there is 32694 at least one cased character in S, False otherwise.""" 32695 return None 32696 itemsize = getset_descriptor() 32697 def join(self, iterable): 32698 """S.join(iterable) -> unicode 32699 32700 Return a string which is the concatenation of the strings in the 32701 iterable. The separator between elements is S.""" 32702 return None 32703 def ljust(self, width, fillchar): 32704 """S.ljust(width[, fillchar]) -> int 32705 32706 Return S left-justified in a Unicode string of length width. Padding is 32707 done using the specified fill character (default is a space).""" 32708 return None 32709 def lower(self, _): 32710 """S.lower() -> unicode 32711 32712 Return a copy of the string S converted to lowercase.""" 32713 return None 32714 def lstrip(self, chars): 32715 """S.lstrip([chars]) -> unicode 32716 32717 Return a copy of the string S with leading whitespace removed. 32718 If chars is given and not None, remove characters in chars instead. 32719 If chars is a str, it will be converted to unicode before stripping""" 32720 return None 32721 nbytes = getset_descriptor() 32722 ndim = getset_descriptor() 32723 def newbyteorder(self, new_order): 32724 """newbyteorder(new_order='S') 32725 32726 Return a new `dtype` with a different byte order. 32727 32728 Changes are also made in all fields and sub-arrays of the data type. 32729 32730 The `new_order` code can be any from the following: 32731 32732 * {'<', 'L'} - little endian 32733 * {'>', 'B'} - big endian 32734 * {'=', 'N'} - native order 32735 * 'S' - swap dtype from current to opposite endian 32736 * {'|', 'I'} - ignore (no change to byte order) 32737 32738 Parameters 32739 ---------- 32740 new_order : str, optional 32741 Byte order to force; a value from the byte order specifications 32742 above. The default value ('S') results in swapping the current 32743 byte order. The code does a case-insensitive check on the first 32744 letter of `new_order` for the alternatives above. For example, 32745 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 32746 32747 32748 Returns 32749 ------- 32750 new_dtype : dtype 32751 New `dtype` object with the given change to the byte order.""" 32752 return dtype() 32753 def partition(self, sep): 32754 """S.partition(sep) -> (head, sep, tail) 32755 32756 Search for the separator sep in S, and return the part before it, 32757 the separator itself, and the part after it. If the separator is not 32758 found, return S and two empty strings.""" 32759 return None 32760 real = getset_descriptor() 32761 def replace(self, old, new, count): 32762 """S.replace(old, new[, count]) -> unicode 32763 32764 Return a copy of S with all occurrences of substring 32765 old replaced by new. If the optional argument count is 32766 given, only the first count occurrences are replaced.""" 32767 return None 32768 def rfind(self, sub, start, end): 32769 """S.rfind(sub [,start [,end]]) -> int 32770 32771 Return the highest index in S where substring sub is found, 32772 such that sub is contained within S[start:end]. Optional 32773 arguments start and end are interpreted as in slice notation. 32774 32775 Return -1 on failure.""" 32776 return None 32777 def rindex(self, sub, start, end): 32778 """S.rindex(sub [,start [,end]]) -> int 32779 32780 Like S.rfind() but raise ValueError when the substring is not found.""" 32781 return None 32782 def rjust(self, width, fillchar): 32783 """S.rjust(width[, fillchar]) -> unicode 32784 32785 Return S right-justified in a Unicode string of length width. Padding is 32786 done using the specified fill character (default is a space).""" 32787 return None 32788 def rpartition(self, sep): 32789 """S.rpartition(sep) -> (head, sep, tail) 32790 32791 Search for the separator sep in S, starting at the end of S, and return 32792 the part before it, the separator itself, and the part after it. If the 32793 separator is not found, return two empty strings and S.""" 32794 return None 32795 def rsplit(self, sep, maxsplit): 32796 """S.rsplit([sep [,maxsplit]]) -> list of strings 32797 32798 Return a list of the words in S, using sep as the 32799 delimiter string, starting at the end of the string and 32800 working to the front. If maxsplit is given, at most maxsplit 32801 splits are done. If sep is not specified, any whitespace string 32802 is a separator.""" 32803 return None 32804 def rstrip(self, chars): 32805 """S.rstrip([chars]) -> unicode 32806 32807 Return a copy of the string S with trailing whitespace removed. 32808 If chars is given and not None, remove characters in chars instead. 32809 If chars is a str, it will be converted to unicode before stripping""" 32810 return None 32811 shape = getset_descriptor() 32812 size = getset_descriptor() 32813 def split(self, sep, maxsplit): 32814 """S.split([sep [,maxsplit]]) -> list of strings 32815 32816 Return a list of the words in S, using sep as the 32817 delimiter string. If maxsplit is given, at most maxsplit 32818 splits are done. If sep is not specified or is None, any 32819 whitespace string is a separator and empty strings are 32820 removed from the result.""" 32821 return None 32822 def splitlines(self, keepends=False): 32823 """S.splitlines(keepends=False) -> list of strings 32824 32825 Return a list of the lines in S, breaking at line boundaries. 32826 Line breaks are not included in the resulting list unless keepends 32827 is given and true.""" 32828 return None 32829 def startswith(self, prefix, start, end): 32830 """S.startswith(prefix[, start[, end]]) -> bool 32831 32832 Return True if S starts with the specified prefix, False otherwise. 32833 With optional start, test S beginning at that position. 32834 With optional end, stop comparing S at that position. 32835 prefix can also be a tuple of strings to try.""" 32836 return None 32837 strides = getset_descriptor() 32838 def strip(self, chars): 32839 """S.strip([chars]) -> unicode 32840 32841 Return a copy of the string S with leading and trailing 32842 whitespace removed. 32843 If chars is given and not None, remove characters in chars instead. 32844 If chars is a str, it will be converted to unicode before stripping""" 32845 return None 32846 def swapcase(self, _): 32847 """S.swapcase() -> unicode 32848 32849 Return a copy of S with uppercase characters converted to lowercase 32850 and vice versa.""" 32851 return None 32852 def title(self, _): 32853 """S.title() -> unicode 32854 32855 Return a titlecased version of S, i.e. words start with title case 32856 characters, all remaining cased characters have lower case.""" 32857 return None 32858 def translate(self, table): 32859 """S.translate(table) -> unicode 32860 32861 Return a copy of the string S, where all characters have been mapped 32862 through the given translation table, which must be a mapping of 32863 Unicode ordinals to Unicode ordinals, Unicode strings or None. 32864 Unmapped characters are left untouched. Characters mapped to None 32865 are deleted.""" 32866 return None 32867 def upper(self, _): 32868 """S.upper() -> unicode 32869 32870 Return a copy of S converted to uppercase.""" 32871 return None 32872 def zfill(self, width): 32873 """S.zfill(width) -> unicode 32874 32875 Pad a numeric string S with zeros on the left, to fill a field 32876 of the specified width. The string S is never truncated.""" 32877 return None 32878 def union1d(ar1ar2): 32879 """ 32880 Find the union of two arrays. 32881 32882 Return the unique, sorted array of values that are in either of the two 32883 input arrays. 32884 32885 Parameters 32886 ---------- 32887 ar1, ar2 : array_like 32888 Input arrays. They are flattened if they are not already 1D. 32889 32890 Returns 32891 ------- 32892 union1d : ndarray 32893 Unique, sorted union of the input arrays. 32894 32895 See Also 32896 -------- 32897 numpy.lib.arraysetops : Module with a number of other functions for 32898 performing set operations on arrays. 32899 32900 Examples 32901 -------- 32902 >>> np.union1d([-1, 0, 1], [-2, 0, 2]) 32903 array([-2, -1, 0, 1, 2]) 32904 32905 """ 32906 return ndarray() 32907 def unique(ar=False, return_index=False, return_inverse=False): 32908 """ 32909 Find the unique elements of an array. 32910 32911 Returns the sorted unique elements of an array. There are two optional 32912 outputs in addition to the unique elements: the indices of the input array 32913 that give the unique values, and the indices of the unique array that 32914 reconstruct the input array. 32915 32916 Parameters 32917 ---------- 32918 ar : array_like 32919 Input array. This will be flattened if it is not already 1-D. 32920 return_index : bool, optional 32921 If True, also return the indices of `ar` that result in the unique 32922 array. 32923 return_inverse : bool, optional 32924 If True, also return the indices of the unique array that can be used 32925 to reconstruct `ar`. 32926 32927 Returns 32928 ------- 32929 unique : ndarray 32930 The sorted unique values. 32931 unique_indices : ndarray, optional 32932 The indices of the first occurrences of the unique values in the 32933 (flattened) original array. Only provided if `return_index` is True. 32934 unique_inverse : ndarray, optional 32935 The indices to reconstruct the (flattened) original array from the 32936 unique array. Only provided if `return_inverse` is True. 32937 32938 See Also 32939 -------- 32940 numpy.lib.arraysetops : Module with a number of other functions for 32941 performing set operations on arrays. 32942 32943 Examples 32944 -------- 32945 >>> np.unique([1, 1, 2, 2, 3, 3]) 32946 array([1, 2, 3]) 32947 >>> a = np.array([[1, 1], [2, 3]]) 32948 >>> np.unique(a) 32949 array([1, 2, 3]) 32950 32951 Return the indices of the original array that give the unique values: 32952 32953 >>> a = np.array(['a', 'b', 'b', 'c', 'a']) 32954 >>> u, indices = np.unique(a, return_index=True) 32955 >>> u 32956 array(['a', 'b', 'c'], 32957 dtype='|S1') 32958 >>> indices 32959 array([0, 1, 3]) 32960 >>> a[indices] 32961 array(['a', 'b', 'c'], 32962 dtype='|S1') 32963 32964 Reconstruct the input array from the unique values: 32965 32966 >>> a = np.array([1, 2, 6, 4, 2, 3, 2]) 32967 >>> u, indices = np.unique(a, return_inverse=True) 32968 >>> u 32969 array([1, 2, 3, 4, 6]) 32970 >>> indices 32971 array([0, 1, 4, 3, 1, 2, 1]) 32972 >>> u[indices] 32973 array([1, 2, 6, 4, 2, 3, 2]) 32974 32975 """ 32976 return ndarray() 32977 def unpackbits(myarray, axis): 32978 """unpackbits(myarray, axis=None) 32979 32980 Unpacks elements of a uint8 array into a binary-valued output array. 32981 32982 Each element of `myarray` represents a bit-field that should be unpacked 32983 into a binary-valued output array. The shape of the output array is either 32984 1-D (if `axis` is None) or the same shape as the input array with unpacking 32985 done along the axis specified. 32986 32987 Parameters 32988 ---------- 32989 myarray : ndarray, uint8 type 32990 Input array. 32991 axis : int, optional 32992 Unpacks along this axis. 32993 32994 Returns 32995 ------- 32996 unpacked : ndarray, uint8 type 32997 The elements are binary-valued (0 or 1). 32998 32999 See Also 33000 -------- 33001 packbits : Packs the elements of a binary-valued array into bits in a uint8 33002 array. 33003 33004 Examples 33005 -------- 33006 >>> a = np.array([[2], [7], [23]], dtype=np.uint8) 33007 >>> a 33008 array([[ 2], 33009 [ 7], 33010 [23]], dtype=uint8) 33011 >>> b = np.unpackbits(a, axis=1) 33012 >>> b 33013 array([[0, 0, 0, 0, 0, 0, 1, 0], 33014 [0, 0, 0, 0, 0, 1, 1, 1], 33015 [0, 0, 0, 1, 0, 1, 1, 1]], dtype=uint8)""" 33016 return ndarray() 33017 def unravel_index(indices, dims, order): 33018 """unravel_index(indices, dims, order='C') 33019 33020 Converts a flat index or array of flat indices into a tuple 33021 of coordinate arrays. 33022 33023 Parameters 33024 ---------- 33025 indices : array_like 33026 An integer array whose elements are indices into the flattened 33027 version of an array of dimensions ``dims``. Before version 1.6.0, 33028 this function accepted just one index value. 33029 dims : tuple of ints 33030 The shape of the array to use for unraveling ``indices``. 33031 order : {'C', 'F'}, optional 33032 .. versionadded:: 1.6.0 33033 33034 Determines whether the indices should be viewed as indexing in 33035 C (row-major) order or FORTRAN (column-major) order. 33036 33037 Returns 33038 ------- 33039 unraveled_coords : tuple of ndarray 33040 Each array in the tuple has the same shape as the ``indices`` 33041 array. 33042 33043 See Also 33044 -------- 33045 ravel_multi_index 33046 33047 Examples 33048 -------- 33049 >>> np.unravel_index([22, 41, 37], (7,6)) 33050 (array([3, 6, 6]), array([4, 5, 1])) 33051 >>> np.unravel_index([31, 41, 13], (7,6), order='F') 33052 (array([3, 6, 6]), array([4, 5, 1])) 33053 33054 >>> np.unravel_index(1621, (6,7,8,9)) 33055 (3, 1, 4, 1)""" 33056 return tuple() 33057 class unsignedinteger: 33058 T = getset_descriptor() 33059 __array_interface__ = getset_descriptor() 33060 __array_priority__ = getset_descriptor() 33061 __array_struct__ = getset_descriptor() 33062 __doc__ = None 33063 base = getset_descriptor() 33064 def conj(self, _): 33065 """None""" 33066 return None 33067 data = getset_descriptor() 33068 dtype = getset_descriptor() 33069 flags = getset_descriptor() 33070 flat = getset_descriptor() 33071 imag = getset_descriptor() 33072 itemsize = getset_descriptor() 33073 nbytes = getset_descriptor() 33074 ndim = getset_descriptor() 33075 def newbyteorder(self, new_order): 33076 """newbyteorder(new_order='S') 33077 33078 Return a new `dtype` with a different byte order. 33079 33080 Changes are also made in all fields and sub-arrays of the data type. 33081 33082 The `new_order` code can be any from the following: 33083 33084 * {'<', 'L'} - little endian 33085 * {'>', 'B'} - big endian 33086 * {'=', 'N'} - native order 33087 * 'S' - swap dtype from current to opposite endian 33088 * {'|', 'I'} - ignore (no change to byte order) 33089 33090 Parameters 33091 ---------- 33092 new_order : str, optional 33093 Byte order to force; a value from the byte order specifications 33094 above. The default value ('S') results in swapping the current 33095 byte order. The code does a case-insensitive check on the first 33096 letter of `new_order` for the alternatives above. For example, 33097 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 33098 33099 33100 Returns 33101 ------- 33102 new_dtype : dtype 33103 New `dtype` object with the given change to the byte order.""" 33104 return dtype() 33105 real = getset_descriptor() 33106 shape = getset_descriptor() 33107 size = getset_descriptor() 33108 strides = getset_descriptor() 33109 def unwrap(p=-1, discont=3.14159265359, axis=-1): 33110 """ 33111 Unwrap by changing deltas between values to 2*pi complement. 33112 33113 Unwrap radian phase `p` by changing absolute jumps greater than 33114 `discont` to their 2*pi complement along the given axis. 33115 33116 Parameters 33117 ---------- 33118 p : array_like 33119 Input array. 33120 discont : float, optional 33121 Maximum discontinuity between values, default is ``pi``. 33122 axis : int, optional 33123 Axis along which unwrap will operate, default is the last axis. 33124 33125 Returns 33126 ------- 33127 out : ndarray 33128 Output array. 33129 33130 See Also 33131 -------- 33132 rad2deg, deg2rad 33133 33134 Notes 33135 ----- 33136 If the discontinuity in `p` is smaller than ``pi``, but larger than 33137 `discont`, no unwrapping is done because taking the 2*pi complement 33138 would only make the discontinuity larger. 33139 33140 Examples 33141 -------- 33142 >>> phase = np.linspace(0, np.pi, num=5) 33143 >>> phase[3:] += np.pi 33144 >>> phase 33145 array([ 0. , 0.78539816, 1.57079633, 5.49778714, 6.28318531]) 33146 >>> np.unwrap(phase) 33147 array([ 0. , 0.78539816, 1.57079633, -0.78539816, 0. ]) 33148 33149 """ 33150 return ndarray() 33151 class uint16: 33152 T = getset_descriptor() 33153 __array_interface__ = getset_descriptor() 33154 __array_priority__ = getset_descriptor() 33155 __array_struct__ = getset_descriptor() 33156 __doc__ = None 33157 base = getset_descriptor() 33158 def conj(self, _): 33159 """None""" 33160 return None 33161 data = getset_descriptor() 33162 dtype = getset_descriptor() 33163 flags = getset_descriptor() 33164 flat = getset_descriptor() 33165 imag = getset_descriptor() 33166 itemsize = getset_descriptor() 33167 nbytes = getset_descriptor() 33168 ndim = getset_descriptor() 33169 def newbyteorder(self, new_order): 33170 """newbyteorder(new_order='S') 33171 33172 Return a new `dtype` with a different byte order. 33173 33174 Changes are also made in all fields and sub-arrays of the data type. 33175 33176 The `new_order` code can be any from the following: 33177 33178 * {'<', 'L'} - little endian 33179 * {'>', 'B'} - big endian 33180 * {'=', 'N'} - native order 33181 * 'S' - swap dtype from current to opposite endian 33182 * {'|', 'I'} - ignore (no change to byte order) 33183 33184 Parameters 33185 ---------- 33186 new_order : str, optional 33187 Byte order to force; a value from the byte order specifications 33188 above. The default value ('S') results in swapping the current 33189 byte order. The code does a case-insensitive check on the first 33190 letter of `new_order` for the alternatives above. For example, 33191 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 33192 33193 33194 Returns 33195 ------- 33196 new_dtype : dtype 33197 New `dtype` object with the given change to the byte order.""" 33198 return dtype() 33199 real = getset_descriptor() 33200 shape = getset_descriptor() 33201 size = getset_descriptor() 33202 strides = getset_descriptor() 33203 def vander(x=None, N=None): 33204 """ 33205 Generate a Van der Monde matrix. 33206 33207 The columns of the output matrix are decreasing powers of the input 33208 vector. Specifically, the `i`-th output column is the input vector 33209 raised element-wise to the power of ``N - i - 1``. Such a matrix with 33210 a geometric progression in each row is named for Alexandre-Theophile 33211 Vandermonde. 33212 33213 Parameters 33214 ---------- 33215 x : array_like 33216 1-D input array. 33217 N : int, optional 33218 Order of (number of columns in) the output. If `N` is not specified, 33219 a square array is returned (``N = len(x)``). 33220 33221 Returns 33222 ------- 33223 out : ndarray 33224 Van der Monde matrix of order `N`. The first column is ``x^(N-1)``, 33225 the second ``x^(N-2)`` and so forth. 33226 33227 Examples 33228 -------- 33229 >>> x = np.array([1, 2, 3, 5]) 33230 >>> N = 3 33231 >>> np.vander(x, N) 33232 array([[ 1, 1, 1], 33233 [ 4, 2, 1], 33234 [ 9, 3, 1], 33235 [25, 5, 1]]) 33236 33237 >>> np.column_stack([x**(N-1-i) for i in range(N)]) 33238 array([[ 1, 1, 1], 33239 [ 4, 2, 1], 33240 [ 9, 3, 1], 33241 [25, 5, 1]]) 33242 33243 >>> x = np.array([1, 2, 3, 5]) 33244 >>> np.vander(x) 33245 array([[ 1, 1, 1, 1], 33246 [ 8, 4, 2, 1], 33247 [ 27, 9, 3, 1], 33248 [125, 25, 5, 1]]) 33249 33250 The determinant of a square Vandermonde matrix is the product 33251 of the differences between the values of the input vector: 33252 33253 >>> np.linalg.det(np.vander(x)) 33254 48.000000000000043 33255 >>> (5-3)*(5-2)*(5-1)*(3-2)*(3-1)*(2-1) 33256 48 33257 33258 """ 33259 return ndarray() 33260 def var(a=False, axis=None, dtype=None, out=None, ddof=0, keepdims=False): 33261 """ 33262 Compute the variance along the specified axis. 33263 33264 Returns the variance of the array elements, a measure of the spread of a 33265 distribution. The variance is computed for the flattened array by 33266 default, otherwise over the specified axis. 33267 33268 Parameters 33269 ---------- 33270 a : array_like 33271 Array containing numbers whose variance is desired. If `a` is not an 33272 array, a conversion is attempted. 33273 axis : int, optional 33274 Axis along which the variance is computed. The default is to compute 33275 the variance of the flattened array. 33276 dtype : data-type, optional 33277 Type to use in computing the variance. For arrays of integer type 33278 the default is `float32`; for arrays of float types it is the same as 33279 the array type. 33280 out : ndarray, optional 33281 Alternate output array in which to place the result. It must have 33282 the same shape as the expected output, but the type is cast if 33283 necessary. 33284 ddof : int, optional 33285 "Delta Degrees of Freedom": the divisor used in the calculation is 33286 ``N - ddof``, where ``N`` represents the number of elements. By 33287 default `ddof` is zero. 33288 keepdims : bool, optional 33289 If this is set to True, the axes which are reduced are left 33290 in the result as dimensions with size one. With this option, 33291 the result will broadcast correctly against the original `arr`. 33292 33293 Returns 33294 ------- 33295 variance : ndarray, see dtype parameter above 33296 If ``out=None``, returns a new array containing the variance; 33297 otherwise, a reference to the output array is returned. 33298 33299 See Also 33300 -------- 33301 std , mean, nanmean, nanstd, nanvar 33302 numpy.doc.ufuncs : Section "Output arguments" 33303 33304 Notes 33305 ----- 33306 The variance is the average of the squared deviations from the mean, 33307 i.e., ``var = mean(abs(x - x.mean())**2)``. 33308 33309 The mean is normally calculated as ``x.sum() / N``, where ``N = len(x)``. 33310 If, however, `ddof` is specified, the divisor ``N - ddof`` is used 33311 instead. In standard statistical practice, ``ddof=1`` provides an 33312 unbiased estimator of the variance of a hypothetical infinite population. 33313 ``ddof=0`` provides a maximum likelihood estimate of the variance for 33314 normally distributed variables. 33315 33316 Note that for complex numbers, the absolute value is taken before 33317 squaring, so that the result is always real and nonnegative. 33318 33319 For floating-point input, the variance is computed using the same 33320 precision the input has. Depending on the input data, this can cause 33321 the results to be inaccurate, especially for `float32` (see example 33322 below). Specifying a higher-accuracy accumulator using the ``dtype`` 33323 keyword can alleviate this issue. 33324 33325 Examples 33326 -------- 33327 >>> a = np.array([[1,2],[3,4]]) 33328 >>> np.var(a) 33329 1.25 33330 >>> np.var(a, axis=0) 33331 array([ 1., 1.]) 33332 >>> np.var(a, axis=1) 33333 array([ 0.25, 0.25]) 33334 33335 In single precision, var() can be inaccurate: 33336 33337 >>> a = np.zeros((2,512*512), dtype=np.float32) 33338 >>> a[0,:] = 1.0 33339 >>> a[1,:] = 0.1 33340 >>> np.var(a) 33341 0.20405951142311096 33342 33343 Computing the variance in float64 is more accurate: 33344 33345 >>> np.var(a, dtype=np.float64) 33346 0.20249999932997387 33347 >>> ((1-0.55)**2 + (0.1-0.55)**2)/2 33348 0.20250000000000001 33349 33350 """ 33351 return ndarray() 33352 def vdot(a, b): 33353 """vdot(a, b) 33354 33355 Return the dot product of two vectors. 33356 33357 The vdot(`a`, `b`) function handles complex numbers differently than 33358 dot(`a`, `b`). If the first argument is complex the complex conjugate 33359 of the first argument is used for the calculation of the dot product. 33360 33361 Note that `vdot` handles multidimensional arrays differently than `dot`: 33362 it does *not* perform a matrix product, but flattens input arguments 33363 to 1-D vectors first. Consequently, it should only be used for vectors. 33364 33365 Parameters 33366 ---------- 33367 a : array_like 33368 If `a` is complex the complex conjugate is taken before calculation 33369 of the dot product. 33370 b : array_like 33371 Second argument to the dot product. 33372 33373 Returns 33374 ------- 33375 output : ndarray 33376 Dot product of `a` and `b`. Can be an int, float, or 33377 complex depending on the types of `a` and `b`. 33378 33379 See Also 33380 -------- 33381 dot : Return the dot product without using the complex conjugate of the 33382 first argument. 33383 33384 Examples 33385 -------- 33386 >>> a = np.array([1+2j,3+4j]) 33387 >>> b = np.array([5+6j,7+8j]) 33388 >>> np.vdot(a, b) 33389 (70-8j) 33390 >>> np.vdot(b, a) 33391 (70+8j) 33392 33393 Note that higher-dimensional arrays are flattened! 33394 33395 >>> a = np.array([[1, 4], [5, 6]]) 33396 >>> b = np.array([[4, 1], [2, 2]]) 33397 >>> np.vdot(a, b) 33398 30 33399 >>> np.vdot(b, a) 33400 30 33401 >>> 1*4 + 4*1 + 5*2 + 6*2 33402 30""" 33403 return ndarray() 33404 class vectorize: 33405 __dict__ = dictproxy() 33406 __doc__ = str() 33407 __module__ = str() 33408 __weakref__ = getset_descriptor() 33409 def _get_ufunc_and_otypes(self, ufunc, otypes): 33410 """Return (ufunc, otypes).""" 33411 return None 33412 def _vectorize_call(self, _): 33413 """Vectorized call to `func` over positional `args`.""" 33414 return None 33415 class void: 33416 T = getset_descriptor() 33417 __array_interface__ = getset_descriptor() 33418 __array_priority__ = getset_descriptor() 33419 __array_struct__ = getset_descriptor() 33420 __doc__ = None 33421 base = getset_descriptor() 33422 def conj(self, _): 33423 """None""" 33424 return None 33425 data = getset_descriptor() 33426 dtype = getset_descriptor() 33427 flags = getset_descriptor() 33428 flat = getset_descriptor() 33429 def getfield(self, _): 33430 """None""" 33431 return None 33432 imag = getset_descriptor() 33433 itemsize = getset_descriptor() 33434 nbytes = getset_descriptor() 33435 ndim = getset_descriptor() 33436 def newbyteorder(self, new_order): 33437 """newbyteorder(new_order='S') 33438 33439 Return a new `dtype` with a different byte order. 33440 33441 Changes are also made in all fields and sub-arrays of the data type. 33442 33443 The `new_order` code can be any from the following: 33444 33445 * {'<', 'L'} - little endian 33446 * {'>', 'B'} - big endian 33447 * {'=', 'N'} - native order 33448 * 'S' - swap dtype from current to opposite endian 33449 * {'|', 'I'} - ignore (no change to byte order) 33450 33451 Parameters 33452 ---------- 33453 new_order : str, optional 33454 Byte order to force; a value from the byte order specifications 33455 above. The default value ('S') results in swapping the current 33456 byte order. The code does a case-insensitive check on the first 33457 letter of `new_order` for the alternatives above. For example, 33458 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 33459 33460 33461 Returns 33462 ------- 33463 new_dtype : dtype 33464 New `dtype` object with the given change to the byte order.""" 33465 return dtype() 33466 real = getset_descriptor() 33467 def setfield(self, _): 33468 """None""" 33469 return None 33470 shape = getset_descriptor() 33471 size = getset_descriptor() 33472 strides = getset_descriptor() 33473 class void: 33474 T = getset_descriptor() 33475 __array_interface__ = getset_descriptor() 33476 __array_priority__ = getset_descriptor() 33477 __array_struct__ = getset_descriptor() 33478 __doc__ = None 33479 base = getset_descriptor() 33480 def conj(self, _): 33481 """None""" 33482 return None 33483 data = getset_descriptor() 33484 dtype = getset_descriptor() 33485 flags = getset_descriptor() 33486 flat = getset_descriptor() 33487 def getfield(self, _): 33488 """None""" 33489 return None 33490 imag = getset_descriptor() 33491 itemsize = getset_descriptor() 33492 nbytes = getset_descriptor() 33493 ndim = getset_descriptor() 33494 def newbyteorder(self, new_order): 33495 """newbyteorder(new_order='S') 33496 33497 Return a new `dtype` with a different byte order. 33498 33499 Changes are also made in all fields and sub-arrays of the data type. 33500 33501 The `new_order` code can be any from the following: 33502 33503 * {'<', 'L'} - little endian 33504 * {'>', 'B'} - big endian 33505 * {'=', 'N'} - native order 33506 * 'S' - swap dtype from current to opposite endian 33507 * {'|', 'I'} - ignore (no change to byte order) 33508 33509 Parameters 33510 ---------- 33511 new_order : str, optional 33512 Byte order to force; a value from the byte order specifications 33513 above. The default value ('S') results in swapping the current 33514 byte order. The code does a case-insensitive check on the first 33515 letter of `new_order` for the alternatives above. For example, 33516 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 33517 33518 33519 Returns 33520 ------- 33521 new_dtype : dtype 33522 New `dtype` object with the given change to the byte order.""" 33523 return dtype() 33524 real = getset_descriptor() 33525 def setfield(self, _): 33526 """None""" 33527 return None 33528 shape = getset_descriptor() 33529 size = getset_descriptor() 33530 strides = getset_descriptor() 33531 def vsplit(): 33532 """ 33533 Split an array into multiple sub-arrays vertically (row-wise). 33534 33535 Please refer to the ``split`` documentation. ``vsplit`` is equivalent 33536 to ``split`` with `axis=0` (default), the array is always split along the 33537 first axis regardless of the array dimension. 33538 33539 See Also 33540 -------- 33541 split : Split an array into multiple sub-arrays of equal size. 33542 33543 Examples 33544 -------- 33545 >>> x = np.arange(16.0).reshape(4, 4) 33546 >>> x 33547 array([[ 0., 1., 2., 3.], 33548 [ 4., 5., 6., 7.], 33549 [ 8., 9., 10., 11.], 33550 [ 12., 13., 14., 15.]]) 33551 >>> np.vsplit(x, 2) 33552 [array([[ 0., 1., 2., 3.], 33553 [ 4., 5., 6., 7.]]), 33554 array([[ 8., 9., 10., 11.], 33555 [ 12., 13., 14., 15.]])] 33556 >>> np.vsplit(x, np.array([3, 6])) 33557 [array([[ 0., 1., 2., 3.], 33558 [ 4., 5., 6., 7.], 33559 [ 8., 9., 10., 11.]]), 33560 array([[ 12., 13., 14., 15.]]), 33561 array([], dtype=float64)] 33562 33563 With a higher dimensional array the split is still along the first axis. 33564 33565 >>> x = np.arange(8.0).reshape(2, 2, 2) 33566 >>> x 33567 array([[[ 0., 1.], 33568 [ 2., 3.]], 33569 [[ 4., 5.], 33570 [ 6., 7.]]]) 33571 >>> np.vsplit(x, 2) 33572 [array([[[ 0., 1.], 33573 [ 2., 3.]]]), 33574 array([[[ 4., 5.], 33575 [ 6., 7.]]])] 33576 33577 """ 33578 return None 33579 def vstack(tup): 33580 """ 33581 Stack arrays in sequence vertically (row wise). 33582 33583 Take a sequence of arrays and stack them vertically to make a single 33584 array. Rebuild arrays divided by `vsplit`. 33585 33586 Parameters 33587 ---------- 33588 tup : sequence of ndarrays 33589 Tuple containing arrays to be stacked. The arrays must have the same 33590 shape along all but the first axis. 33591 33592 Returns 33593 ------- 33594 stacked : ndarray 33595 The array formed by stacking the given arrays. 33596 33597 See Also 33598 -------- 33599 hstack : Stack arrays in sequence horizontally (column wise). 33600 dstack : Stack arrays in sequence depth wise (along third dimension). 33601 concatenate : Join a sequence of arrays together. 33602 vsplit : Split array into a list of multiple sub-arrays vertically. 33603 33604 Notes 33605 ----- 33606 Equivalent to ``np.concatenate(tup, axis=0)`` if `tup` contains arrays that 33607 are at least 2-dimensional. 33608 33609 Examples 33610 -------- 33611 >>> a = np.array([1, 2, 3]) 33612 >>> b = np.array([2, 3, 4]) 33613 >>> np.vstack((a,b)) 33614 array([[1, 2, 3], 33615 [2, 3, 4]]) 33616 33617 >>> a = np.array([[1], [2], [3]]) 33618 >>> b = np.array([[2], [3], [4]]) 33619 >>> np.vstack((a,b)) 33620 array([[1], 33621 [2], 33622 [3], 33623 [2], 33624 [3], 33625 [4]]) 33626 33627 """ 33628 return ndarray() 33629 def where(condition, x=None, y=None): 33630 """where(condition, [x, y]) 33631 33632 Return elements, either from `x` or `y`, depending on `condition`. 33633 33634 If only `condition` is given, return ``condition.nonzero()``. 33635 33636 Parameters 33637 ---------- 33638 condition : array_like, bool 33639 When True, yield `x`, otherwise yield `y`. 33640 x, y : array_like, optional 33641 Values from which to choose. `x` and `y` need to have the same 33642 shape as `condition`. 33643 33644 Returns 33645 ------- 33646 out : ndarray or tuple of ndarrays 33647 If both `x` and `y` are specified, the output array contains 33648 elements of `x` where `condition` is True, and elements from 33649 `y` elsewhere. 33650 33651 If only `condition` is given, return the tuple 33652 ``condition.nonzero()``, the indices where `condition` is True. 33653 33654 See Also 33655 -------- 33656 nonzero, choose 33657 33658 Notes 33659 ----- 33660 If `x` and `y` are given and input arrays are 1-D, `where` is 33661 equivalent to:: 33662 33663 [xv if c else yv for (c,xv,yv) in zip(condition,x,y)] 33664 33665 Examples 33666 -------- 33667 >>> np.where([[True, False], [True, True]], 33668 ... [[1, 2], [3, 4]], 33669 ... [[9, 8], [7, 6]]) 33670 array([[1, 8], 33671 [3, 4]]) 33672 33673 >>> np.where([[0, 1], [1, 0]]) 33674 (array([0, 1]), array([1, 0])) 33675 33676 >>> x = np.arange(9.).reshape(3, 3) 33677 >>> np.where( x > 5 ) 33678 (array([2, 2, 2]), array([0, 1, 2])) 33679 >>> x[np.where( x > 3.0 )] # Note: result is 1D. 33680 array([ 4., 5., 6., 7., 8.]) 33681 >>> np.where(x < 5, x, -1) # Note: broadcasting. 33682 array([[ 0., 1., 2.], 33683 [ 3., 4., -1.], 33684 [-1., -1., -1.]]) 33685 33686 Find the indices of elements of `x` that are in `goodvalues`. 33687 33688 >>> goodvalues = [3, 4, 7] 33689 >>> ix = np.in1d(x.ravel(), goodvalues).reshape(x.shape) 33690 >>> ix 33691 array([[False, False, False], 33692 [ True, True, False], 33693 [False, True, False]], dtype=bool) 33694 >>> np.where(ix) 33695 (array([1, 1, 2]), array([0, 1, 1]))""" 33696 return ndarray() if False else tuple() 33697 def who(vardict=None): 33698 """ 33699 Print the Numpy arrays in the given dictionary. 33700 33701 If there is no dictionary passed in or `vardict` is None then returns 33702 Numpy arrays in the globals() dictionary (all Numpy arrays in the 33703 namespace). 33704 33705 Parameters 33706 ---------- 33707 vardict : dict, optional 33708 A dictionary possibly containing ndarrays. Default is globals(). 33709 33710 Returns 33711 ------- 33712 out : None 33713 Returns 'None'. 33714 33715 Notes 33716 ----- 33717 Prints out the name, shape, bytes and type of all of the ndarrays present 33718 in `vardict`. 33719 33720 Examples 33721 -------- 33722 >>> a = np.arange(10) 33723 >>> b = np.ones(20) 33724 >>> np.who() 33725 Name Shape Bytes Type 33726 =========================================================== 33727 a 10 40 int32 33728 b 20 160 float64 33729 Upper bound on total bytes = 200 33730 33731 >>> d = {'x': np.arange(2.0), 'y': np.arange(3.0), 'txt': 'Some str', 33732 ... 'idx':5} 33733 >>> np.who(d) 33734 Name Shape Bytes Type 33735 =========================================================== 33736 y 3 24 float64 33737 x 2 16 float64 33738 Upper bound on total bytes = 40 33739 33740 """ 33741 return None() 33742 def zeros(shape, dtype, order): 33743 """zeros(shape, dtype=float, order='C') 33744 33745 Return a new array of given shape and type, filled with zeros. 33746 33747 Parameters 33748 ---------- 33749 shape : int or sequence of ints 33750 Shape of the new array, e.g., ``(2, 3)`` or ``2``. 33751 dtype : data-type, optional 33752 The desired data-type for the array, e.g., `numpy.int8`. Default is 33753 `numpy.float64`. 33754 order : {'C', 'F'}, optional 33755 Whether to store multidimensional data in C- or Fortran-contiguous 33756 (row- or column-wise) order in memory. 33757 33758 Returns 33759 ------- 33760 out : ndarray 33761 Array of zeros with the given shape, dtype, and order. 33762 33763 See Also 33764 -------- 33765 zeros_like : Return an array of zeros with shape and type of input. 33766 ones_like : Return an array of ones with shape and type of input. 33767 empty_like : Return an empty array with shape and type of input. 33768 ones : Return a new array setting values to one. 33769 empty : Return a new uninitialized array. 33770 33771 Examples 33772 -------- 33773 >>> np.zeros(5) 33774 array([ 0., 0., 0., 0., 0.]) 33775 33776 >>> np.zeros((5,), dtype=numpy.int) 33777 array([0, 0, 0, 0, 0]) 33778 33779 >>> np.zeros((2, 1)) 33780 array([[ 0.], 33781 [ 0.]]) 33782 33783 >>> s = (2,2) 33784 >>> np.zeros(s) 33785 array([[ 0., 0.], 33786 [ 0., 0.]]) 33787 33788 >>> np.zeros((2,), dtype=[('x', 'i4'), ('y', 'i4')]) # custom dtype 33789 array([(0, 0), (0, 0)], 33790 dtype=[('x', '<i4'), ('y', '<i4')])""" 33791 return ndarray() 33792 def zeros_like(a=True, dtype=None, order="K", subok=True): 33793 """ 33794 Return an array of zeros with the same shape and type as a given array. 33795 33796 Parameters 33797 ---------- 33798 a : array_like 33799 The shape and data-type of `a` define these same attributes of 33800 the returned array. 33801 dtype : data-type, optional 33802 .. versionadded:: 1.6.0 33803 Overrides the data type of the result. 33804 order : {'C', 'F', 'A', or 'K'}, optional 33805 .. versionadded:: 1.6.0 33806 Overrides the memory layout of the result. 'C' means C-order, 33807 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, 33808 'C' otherwise. 'K' means match the layout of `a` as closely 33809 as possible. 33810 subok : bool, optional. 33811 If True, then the newly created array will use the sub-class 33812 type of 'a', otherwise it will be a base-class array. Defaults 33813 to True. 33814 33815 Returns 33816 ------- 33817 out : ndarray 33818 Array of zeros with the same shape and type as `a`. 33819 33820 See Also 33821 -------- 33822 ones_like : Return an array of ones with shape and type of input. 33823 empty_like : Return an empty array with shape and type of input. 33824 zeros : Return a new array setting values to zero. 33825 ones : Return a new array setting values to one. 33826 empty : Return a new uninitialized array. 33827 33828 Examples 33829 -------- 33830 >>> x = np.arange(6) 33831 >>> x = x.reshape((2, 3)) 33832 >>> x 33833 array([[0, 1, 2], 33834 [3, 4, 5]]) 33835 >>> np.zeros_like(x) 33836 array([[0, 0, 0], 33837 [0, 0, 0]]) 33838 33839 >>> y = np.arange(3, dtype=np.float) 33840 >>> y 33841 array([ 0., 1., 2.]) 33842 >>> np.zeros_like(y) 33843 array([ 0., 0., 0.]) 33844 33845 """ 33846 return ndarray() 33847 class ctypeslib: 33848 class PyCArrayType: 33849 __bases__ = tuple() 33850 __basicsize__ = int() 33851 __dict__ = dictproxy() 33852 __dictoffset__ = int() 33853 __doc__ = str() 33854 __flags__ = int() 33855 __itemsize__ = int() 33856 __module__ = str() 33857 __mro__ = tuple() 33858 __name__ = str() 33859 __weakrefoffset__ = int() 33860 def _from_address(self, integer): 33861 """C.from_address(integer) -> C instance 33862 access a C instance at the specified address""" 33863 return None 33864 def _from_buffer(self, object, offset=0): 33865 """C.from_buffer(object, offset=0) -> C instance 33866 create a C instance from a writeable buffer""" 33867 return None 33868 def _from_buffer_copy(self, object, offset=0): 33869 """C.from_buffer_copy(object, offset=0) -> C instance 33870 create a C instance from a readable buffer""" 33871 return None 33872 def _from_param(self, _): 33873 """Convert a Python object into a function call parameter.""" 33874 return None 33875 def in_dll(self, dll, name): 33876 """C.in_dll(dll, name) -> C instance 33877 access a C instance in a dll""" 33878 return None 33879 def mro(self, _): 33880 """mro() -> list 33881 return a type's method resolution order""" 33882 return None 33883 __all__ = list() 33884 __builtins__ = dict() 33885 __doc__ = str() 33886 __file__ = str() 33887 __name__ = str() 33888 __package__ = None 33889 class dtype: 33890 __doc__ = str() 33891 alignment = member_descriptor() 33892 base = getset_descriptor() 33893 byteorder = member_descriptor() 33894 char = member_descriptor() 33895 descr = getset_descriptor() 33896 fields = getset_descriptor() 33897 flags = member_descriptor() 33898 hasobject = getset_descriptor() 33899 isalignedstruct = getset_descriptor() 33900 isbuiltin = getset_descriptor() 33901 isnative = getset_descriptor() 33902 itemsize = member_descriptor() 33903 kind = member_descriptor() 33904 metadata = getset_descriptor() 33905 name = getset_descriptor() 33906 names = getset_descriptor() 33907 def newbyteorder(self, new_order): 33908 """newbyteorder(new_order='S') 33909 33910 Return a new dtype with a different byte order. 33911 33912 Changes are also made in all fields and sub-arrays of the data type. 33913 33914 Parameters 33915 ---------- 33916 new_order : string, optional 33917 Byte order to force; a value from the byte order 33918 specifications below. The default value ('S') results in 33919 swapping the current byte order. 33920 `new_order` codes can be any of:: 33921 33922 * 'S' - swap dtype from current to opposite endian 33923 * {'<', 'L'} - little endian 33924 * {'>', 'B'} - big endian 33925 * {'=', 'N'} - native order 33926 * {'|', 'I'} - ignore (no change to byte order) 33927 33928 The code does a case-insensitive check on the first letter of 33929 `new_order` for these alternatives. For example, any of '>' 33930 or 'B' or 'b' or 'brian' are valid to specify big-endian. 33931 33932 Returns 33933 ------- 33934 new_dtype : dtype 33935 New dtype object with the given change to the byte order. 33936 33937 Notes 33938 ----- 33939 Changes are also made in all fields and sub-arrays of the data type. 33940 33941 Examples 33942 -------- 33943 >>> import sys 33944 >>> sys_is_le = sys.byteorder == 'little' 33945 >>> native_code = sys_is_le and '<' or '>' 33946 >>> swapped_code = sys_is_le and '>' or '<' 33947 >>> native_dt = np.dtype(native_code+'i2') 33948 >>> swapped_dt = np.dtype(swapped_code+'i2') 33949 >>> native_dt.newbyteorder('S') == swapped_dt 33950 True 33951 >>> native_dt.newbyteorder() == swapped_dt 33952 True 33953 >>> native_dt == swapped_dt.newbyteorder('S') 33954 True 33955 >>> native_dt == swapped_dt.newbyteorder('=') 33956 True 33957 >>> native_dt == swapped_dt.newbyteorder('N') 33958 True 33959 >>> native_dt == native_dt.newbyteorder('|') 33960 True 33961 >>> np.dtype('<i2') == native_dt.newbyteorder('<') 33962 True 33963 >>> np.dtype('<i2') == native_dt.newbyteorder('L') 33964 True 33965 >>> np.dtype('>i2') == native_dt.newbyteorder('>') 33966 True 33967 >>> np.dtype('>i2') == native_dt.newbyteorder('B') 33968 True""" 33969 return dtype() 33970 num = member_descriptor() 33971 shape = getset_descriptor() 33972 str = getset_descriptor() 33973 subdtype = getset_descriptor() 33974 type = member_descriptor() 33975 _flagdict = dict() 33976 _flagnames = list() 33977 def _flags__fromnum(self, _): 33978 """None""" 33979 return None 33980 def _ndptr(self, _): 33981 """None""" 33982 return None 33983 def c_void_p(self, _): 33984 """None""" 33985 return None 33986 def _num__fromflags(self, _): 33987 """None""" 33988 return None 33989 _pointer_type_cache = dict() 33990 _typecodes = dict() 33991 absolute_import = instance() 33992 def array(self, object, dtype, copy, order, subok, ndmin): 33993 """array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0) 33994 33995 Create an array. 33996 33997 Parameters 33998 ---------- 33999 object : array_like 34000 An array, any object exposing the array interface, an 34001 object whose __array__ method returns an array, or any 34002 (nested) sequence. 34003 dtype : data-type, optional 34004 The desired data-type for the array. If not given, then 34005 the type will be determined as the minimum type required 34006 to hold the objects in the sequence. This argument can only 34007 be used to 'upcast' the array. For downcasting, use the 34008 .astype(t) method. 34009 copy : bool, optional 34010 If true (default), then the object is copied. Otherwise, a copy 34011 will only be made if __array__ returns a copy, if obj is a 34012 nested sequence, or if a copy is needed to satisfy any of the other 34013 requirements (`dtype`, `order`, etc.). 34014 order : {'C', 'F', 'A'}, optional 34015 Specify the order of the array. If order is 'C' (default), then the 34016 array will be in C-contiguous order (last-index varies the 34017 fastest). If order is 'F', then the returned array 34018 will be in Fortran-contiguous order (first-index varies the 34019 fastest). If order is 'A', then the returned array may 34020 be in any order (either C-, Fortran-contiguous, or even 34021 discontiguous). 34022 subok : bool, optional 34023 If True, then sub-classes will be passed-through, otherwise 34024 the returned array will be forced to be a base-class array (default). 34025 ndmin : int, optional 34026 Specifies the minimum number of dimensions that the resulting 34027 array should have. Ones will be pre-pended to the shape as 34028 needed to meet this requirement. 34029 34030 Returns 34031 ------- 34032 out : ndarray 34033 An array object satisfying the specified requirements. 34034 34035 See Also 34036 -------- 34037 empty, empty_like, zeros, zeros_like, ones, ones_like, fill 34038 34039 Examples 34040 -------- 34041 >>> np.array([1, 2, 3]) 34042 array([1, 2, 3]) 34043 34044 Upcasting: 34045 34046 >>> np.array([1, 2, 3.0]) 34047 array([ 1., 2., 3.]) 34048 34049 More than one dimension: 34050 34051 >>> np.array([[1, 2], [3, 4]]) 34052 array([[1, 2], 34053 [3, 4]]) 34054 34055 Minimum dimensions 2: 34056 34057 >>> np.array([1, 2, 3], ndmin=2) 34058 array([[1, 2, 3]]) 34059 34060 Type provided: 34061 34062 >>> np.array([1, 2, 3], dtype=complex) 34063 array([ 1.+0.j, 2.+0.j, 3.+0.j]) 34064 34065 Data-type consisting of more than one element: 34066 34067 >>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')]) 34068 >>> x['a'] 34069 array([1, 3]) 34070 34071 Creating an array from sub-classes: 34072 34073 >>> np.array(np.mat('1 2; 3 4')) 34074 array([[1, 2], 34075 [3, 4]]) 34076 34077 >>> np.array(np.mat('1 2; 3 4'), subok=True) 34078 matrix([[1, 2], 34079 [3, 4]])""" 34080 return ndarray() 34081 def as_array(self, obj=None, shape=None): 34082 """Create a numpy array from a ctypes array or a ctypes POINTER. 34083 The numpy array shares the memory with the ctypes object. 34084 34085 The size parameter must be given if converting from a ctypes POINTER. 34086 The size parameter is ignored if converting from a ctypes array 34087 """ 34088 return None 34089 def as_ctypes(self, _): 34090 """Create and return a ctypes object from a numpy array. Actually 34091 anything that exposes the __array_interface__ is accepted.""" 34092 return None 34093 def c_long(self, _): 34094 """None""" 34095 return None 34096 code = str() 34097 def ctypes_load_library(self): 34098 """`ctypes_load_library` is deprecated, use `load_library` instead!""" 34099 return None 34100 def deprecate(self): 34101 """ 34102 Issues a DeprecationWarning, adds warning to `old_name`'s 34103 docstring, rebinds ``old_name.__name__`` and returns the new 34104 function object. 34105 34106 This function may also be used as a decorator. 34107 34108 Parameters 34109 ---------- 34110 func : function 34111 The function to be deprecated. 34112 old_name : str, optional 34113 The name of the function to be deprecated. Default is None, in which 34114 case the name of `func` is used. 34115 new_name : str, optional 34116 The new name for the function. Default is None, in which case 34117 the deprecation message is that `old_name` is deprecated. If given, 34118 the deprecation message is that `old_name` is deprecated and `new_name` 34119 should be used instead. 34120 message : str, optional 34121 Additional explanation of the deprecation. Displayed in the docstring 34122 after the warning. 34123 34124 Returns 34125 ------- 34126 old_func : function 34127 The deprecated function. 34128 34129 Examples 34130 -------- 34131 Note that ``olduint`` returns a value after printing Deprecation Warning: 34132 34133 >>> olduint = np.deprecate(np.uint) 34134 >>> olduint(6) 34135 /usr/lib/python2.5/site-packages/numpy/lib/utils.py:114: 34136 DeprecationWarning: uint32 is deprecated 34137 warnings.warn(str1, DeprecationWarning) 34138 6 34139 34140 """ 34141 return None 34142 division = instance() 34143 class flagsobj: 34144 __doc__ = None 34145 aligned = getset_descriptor() 34146 behaved = getset_descriptor() 34147 c_contiguous = getset_descriptor() 34148 carray = getset_descriptor() 34149 contiguous = getset_descriptor() 34150 f_contiguous = getset_descriptor() 34151 farray = getset_descriptor() 34152 fnc = getset_descriptor() 34153 forc = getset_descriptor() 34154 fortran = getset_descriptor() 34155 num = getset_descriptor() 34156 owndata = getset_descriptor() 34157 updateifcopy = getset_descriptor() 34158 writeable = getset_descriptor() 34159 class integer: 34160 T = getset_descriptor() 34161 __array_interface__ = getset_descriptor() 34162 __array_priority__ = getset_descriptor() 34163 __array_struct__ = getset_descriptor() 34164 __doc__ = None 34165 base = getset_descriptor() 34166 def conj(self, _): 34167 """None""" 34168 return None 34169 data = getset_descriptor() 34170 dtype = getset_descriptor() 34171 flags = getset_descriptor() 34172 flat = getset_descriptor() 34173 imag = getset_descriptor() 34174 itemsize = getset_descriptor() 34175 nbytes = getset_descriptor() 34176 ndim = getset_descriptor() 34177 def newbyteorder(self, new_order): 34178 """newbyteorder(new_order='S') 34179 34180 Return a new `dtype` with a different byte order. 34181 34182 Changes are also made in all fields and sub-arrays of the data type. 34183 34184 The `new_order` code can be any from the following: 34185 34186 * {'<', 'L'} - little endian 34187 * {'>', 'B'} - big endian 34188 * {'=', 'N'} - native order 34189 * 'S' - swap dtype from current to opposite endian 34190 * {'|', 'I'} - ignore (no change to byte order) 34191 34192 Parameters 34193 ---------- 34194 new_order : str, optional 34195 Byte order to force; a value from the byte order specifications 34196 above. The default value ('S') results in swapping the current 34197 byte order. The code does a case-insensitive check on the first 34198 letter of `new_order` for the alternatives above. For example, 34199 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 34200 34201 34202 Returns 34203 ------- 34204 new_dtype : dtype 34205 New `dtype` object with the given change to the byte order.""" 34206 return None 34207 real = getset_descriptor() 34208 shape = getset_descriptor() 34209 size = getset_descriptor() 34210 strides = getset_descriptor() 34211 def load_library(self, _): 34212 """None""" 34213 return None 34214 class ndarray: 34215 T = getset_descriptor() 34216 __array_finalize__ = getset_descriptor() 34217 __array_interface__ = getset_descriptor() 34218 __array_priority__ = getset_descriptor() 34219 __array_struct__ = getset_descriptor() 34220 __doc__ = str() 34221 def all(self, axis=None, out=None): 34222 """a.all(axis=None, out=None) 34223 34224 Returns True if all elements evaluate to True. 34225 34226 Refer to `numpy.all` for full documentation. 34227 34228 See Also 34229 -------- 34230 numpy.all : equivalent function""" 34231 return None 34232 def any(self, axis=None, out=None): 34233 """a.any(axis=None, out=None) 34234 34235 Returns True if any of the elements of `a` evaluate to True. 34236 34237 Refer to `numpy.any` for full documentation. 34238 34239 See Also 34240 -------- 34241 numpy.any : equivalent function""" 34242 return None 34243 def argmax(self, axis=None, out=None): 34244 """a.argmax(axis=None, out=None) 34245 34246 Return indices of the maximum values along the given axis. 34247 34248 Refer to `numpy.argmax` for full documentation. 34249 34250 See Also 34251 -------- 34252 numpy.argmax : equivalent function""" 34253 return None 34254 def argmin(self, axis=None, out=None): 34255 """a.argmin(axis=None, out=None) 34256 34257 Return indices of the minimum values along the given axis of `a`. 34258 34259 Refer to `numpy.argmin` for detailed documentation. 34260 34261 See Also 34262 -------- 34263 numpy.argmin : equivalent function""" 34264 return None 34265 def argpartition(self, kth, axis=_1, kind=quickselect, order=None): 34266 """a.argpartition(kth, axis=-1, kind='quickselect', order=None) 34267 34268 Returns the indices that would partition this array. 34269 34270 Refer to `numpy.argpartition` for full documentation. 34271 34272 .. versionadded:: 1.8.0 34273 34274 See Also 34275 -------- 34276 numpy.argpartition : equivalent function""" 34277 return None 34278 def argsort(self, axis=_1, kind=quicksort, order=None): 34279 """a.argsort(axis=-1, kind='quicksort', order=None) 34280 34281 Returns the indices that would sort this array. 34282 34283 Refer to `numpy.argsort` for full documentation. 34284 34285 See Also 34286 -------- 34287 numpy.argsort : equivalent function""" 34288 return None 34289 def astype(self, dtype, order, casting, subok, copy): 34290 """a.astype(dtype, order='K', casting='unsafe', subok=True, copy=True) 34291 34292 Copy of the array, cast to a specified type. 34293 34294 Parameters 34295 ---------- 34296 dtype : str or dtype 34297 Typecode or data-type to which the array is cast. 34298 order : {'C', 'F', 'A', 'K'}, optional 34299 Controls the memory layout order of the result. 34300 'C' means C order, 'F' means Fortran order, 'A' 34301 means 'F' order if all the arrays are Fortran contiguous, 34302 'C' order otherwise, and 'K' means as close to the 34303 order the array elements appear in memory as possible. 34304 Default is 'K'. 34305 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional 34306 Controls what kind of data casting may occur. Defaults to 'unsafe' 34307 for backwards compatibility. 34308 34309 * 'no' means the data types should not be cast at all. 34310 * 'equiv' means only byte-order changes are allowed. 34311 * 'safe' means only casts which can preserve values are allowed. 34312 * 'same_kind' means only safe casts or casts within a kind, 34313 like float64 to float32, are allowed. 34314 * 'unsafe' means any data conversions may be done. 34315 subok : bool, optional 34316 If True, then sub-classes will be passed-through (default), otherwise 34317 the returned array will be forced to be a base-class array. 34318 copy : bool, optional 34319 By default, astype always returns a newly allocated array. If this 34320 is set to false, and the `dtype`, `order`, and `subok` 34321 requirements are satisfied, the input array is returned instead 34322 of a copy. 34323 34324 Returns 34325 ------- 34326 arr_t : ndarray 34327 Unless `copy` is False and the other conditions for returning the input 34328 array are satisfied (see description for `copy` input paramter), `arr_t` 34329 is a new array of the same shape as the input array, with dtype, order 34330 given by `dtype`, `order`. 34331 34332 Raises 34333 ------ 34334 ComplexWarning 34335 When casting from complex to float or int. To avoid this, 34336 one should use ``a.real.astype(t)``. 34337 34338 Examples 34339 -------- 34340 >>> x = np.array([1, 2, 2.5]) 34341 >>> x 34342 array([ 1. , 2. , 2.5]) 34343 34344 >>> x.astype(int) 34345 array([1, 2, 2])""" 34346 return ndarray() 34347 base = getset_descriptor() 34348 def byteswap(self, inplace): 34349 """a.byteswap(inplace) 34350 34351 Swap the bytes of the array elements 34352 34353 Toggle between low-endian and big-endian data representation by 34354 returning a byteswapped array, optionally swapped in-place. 34355 34356 Parameters 34357 ---------- 34358 inplace : bool, optional 34359 If ``True``, swap bytes in-place, default is ``False``. 34360 34361 Returns 34362 ------- 34363 out : ndarray 34364 The byteswapped array. If `inplace` is ``True``, this is 34365 a view to self. 34366 34367 Examples 34368 -------- 34369 >>> A = np.array([1, 256, 8755], dtype=np.int16) 34370 >>> map(hex, A) 34371 ['0x1', '0x100', '0x2233'] 34372 >>> A.byteswap(True) 34373 array([ 256, 1, 13090], dtype=int16) 34374 >>> map(hex, A) 34375 ['0x100', '0x1', '0x3322'] 34376 34377 Arrays of strings are not swapped 34378 34379 >>> A = np.array(['ceg', 'fac']) 34380 >>> A.byteswap() 34381 array(['ceg', 'fac'], 34382 dtype='|S3')""" 34383 return ndarray() 34384 def choose(self, choices, out=None, mode=_raise): 34385 """a.choose(choices, out=None, mode='raise') 34386 34387 Use an index array to construct a new array from a set of choices. 34388 34389 Refer to `numpy.choose` for full documentation. 34390 34391 See Also 34392 -------- 34393 numpy.choose : equivalent function""" 34394 return None 34395 def clip(self, a_min, a_max, out=None): 34396 """a.clip(a_min, a_max, out=None) 34397 34398 Return an array whose values are limited to ``[a_min, a_max]``. 34399 34400 Refer to `numpy.clip` for full documentation. 34401 34402 See Also 34403 -------- 34404 numpy.clip : equivalent function""" 34405 return None 34406 def compress(self, condition, axis=None, out=None): 34407 """a.compress(condition, axis=None, out=None) 34408 34409 Return selected slices of this array along given axis. 34410 34411 Refer to `numpy.compress` for full documentation. 34412 34413 See Also 34414 -------- 34415 numpy.compress : equivalent function""" 34416 return None 34417 def conj(self, _): 34418 """a.conj() 34419 34420 Complex-conjugate all elements. 34421 34422 Refer to `numpy.conjugate` for full documentation. 34423 34424 See Also 34425 -------- 34426 numpy.conjugate : equivalent function""" 34427 return None 34428 def conjugate(self, _): 34429 """a.conjugate() 34430 34431 Return the complex conjugate, element-wise. 34432 34433 Refer to `numpy.conjugate` for full documentation. 34434 34435 See Also 34436 -------- 34437 numpy.conjugate : equivalent function""" 34438 return None 34439 def copy(self, order): 34440 """a.copy(order='C') 34441 34442 Return a copy of the array. 34443 34444 Parameters 34445 ---------- 34446 order : {'C', 'F', 'A', 'K'}, optional 34447 Controls the memory layout of the copy. 'C' means C-order, 34448 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, 34449 'C' otherwise. 'K' means match the layout of `a` as closely 34450 as possible. (Note that this function and :func:numpy.copy are very 34451 similar, but have different default values for their order= 34452 arguments.) 34453 34454 See also 34455 -------- 34456 numpy.copy 34457 numpy.copyto 34458 34459 Examples 34460 -------- 34461 >>> x = np.array([[1,2,3],[4,5,6]], order='F') 34462 34463 >>> y = x.copy() 34464 34465 >>> x.fill(0) 34466 34467 >>> x 34468 array([[0, 0, 0], 34469 [0, 0, 0]]) 34470 34471 >>> y 34472 array([[1, 2, 3], 34473 [4, 5, 6]]) 34474 34475 >>> y.flags['C_CONTIGUOUS'] 34476 True""" 34477 return None 34478 ctypes = getset_descriptor() 34479 def cumprod(self, axis=None, dtype=None, out=None): 34480 """a.cumprod(axis=None, dtype=None, out=None) 34481 34482 Return the cumulative product of the elements along the given axis. 34483 34484 Refer to `numpy.cumprod` for full documentation. 34485 34486 See Also 34487 -------- 34488 numpy.cumprod : equivalent function""" 34489 return None 34490 def cumsum(self, axis=None, dtype=None, out=None): 34491 """a.cumsum(axis=None, dtype=None, out=None) 34492 34493 Return the cumulative sum of the elements along the given axis. 34494 34495 Refer to `numpy.cumsum` for full documentation. 34496 34497 See Also 34498 -------- 34499 numpy.cumsum : equivalent function""" 34500 return None 34501 data = getset_descriptor() 34502 def diagonal(self, offset=0, axis1=0, axis2=1): 34503 """a.diagonal(offset=0, axis1=0, axis2=1) 34504 34505 Return specified diagonals. 34506 34507 Refer to :func:`numpy.diagonal` for full documentation. 34508 34509 See Also 34510 -------- 34511 numpy.diagonal : equivalent function""" 34512 return None 34513 def dot(self, b, out=None): 34514 """a.dot(b, out=None) 34515 34516 Dot product of two arrays. 34517 34518 Refer to `numpy.dot` for full documentation. 34519 34520 See Also 34521 -------- 34522 numpy.dot : equivalent function 34523 34524 Examples 34525 -------- 34526 >>> a = np.eye(2) 34527 >>> b = np.ones((2, 2)) * 2 34528 >>> a.dot(b) 34529 array([[ 2., 2.], 34530 [ 2., 2.]]) 34531 34532 This array method can be conveniently chained: 34533 34534 >>> a.dot(b).dot(b) 34535 array([[ 8., 8.], 34536 [ 8., 8.]])""" 34537 return None 34538 dtype = getset_descriptor() 34539 def dump(self, file): 34540 """a.dump(file) 34541 34542 Dump a pickle of the array to the specified file. 34543 The array can be read back with pickle.load or numpy.load. 34544 34545 Parameters 34546 ---------- 34547 file : str 34548 A string naming the dump file.""" 34549 return None 34550 def dumps(self, _): 34551 """a.dumps() 34552 34553 Returns the pickle of the array as a string. 34554 pickle.loads or numpy.loads will convert the string back to an array. 34555 34556 Parameters 34557 ---------- 34558 None""" 34559 return None 34560 def fill(self, value): 34561 """a.fill(value) 34562 34563 Fill the array with a scalar value. 34564 34565 Parameters 34566 ---------- 34567 value : scalar 34568 All elements of `a` will be assigned this value. 34569 34570 Examples 34571 -------- 34572 >>> a = np.array([1, 2]) 34573 >>> a.fill(0) 34574 >>> a 34575 array([0, 0]) 34576 >>> a = np.empty(2) 34577 >>> a.fill(1) 34578 >>> a 34579 array([ 1., 1.])""" 34580 return None 34581 flags = getset_descriptor() 34582 flat = getset_descriptor() 34583 def flatten(self, order): 34584 """a.flatten(order='C') 34585 34586 Return a copy of the array collapsed into one dimension. 34587 34588 Parameters 34589 ---------- 34590 order : {'C', 'F', 'A'}, optional 34591 Whether to flatten in C (row-major), Fortran (column-major) order, 34592 or preserve the C/Fortran ordering from `a`. 34593 The default is 'C'. 34594 34595 Returns 34596 ------- 34597 y : ndarray 34598 A copy of the input array, flattened to one dimension. 34599 34600 See Also 34601 -------- 34602 ravel : Return a flattened array. 34603 flat : A 1-D flat iterator over the array. 34604 34605 Examples 34606 -------- 34607 >>> a = np.array([[1,2], [3,4]]) 34608 >>> a.flatten() 34609 array([1, 2, 3, 4]) 34610 >>> a.flatten('F') 34611 array([1, 3, 2, 4])""" 34612 return ndarray() 34613 def getfield(self, dtype, offset): 34614 """a.getfield(dtype, offset=0) 34615 34616 Returns a field of the given array as a certain type. 34617 34618 A field is a view of the array data with a given data-type. The values in 34619 the view are determined by the given type and the offset into the current 34620 array in bytes. The offset needs to be such that the view dtype fits in the 34621 array dtype; for example an array of dtype complex128 has 16-byte elements. 34622 If taking a view with a 32-bit integer (4 bytes), the offset needs to be 34623 between 0 and 12 bytes. 34624 34625 Parameters 34626 ---------- 34627 dtype : str or dtype 34628 The data type of the view. The dtype size of the view can not be larger 34629 than that of the array itself. 34630 offset : int 34631 Number of bytes to skip before beginning the element view. 34632 34633 Examples 34634 -------- 34635 >>> x = np.diag([1.+1.j]*2) 34636 >>> x[1, 1] = 2 + 4.j 34637 >>> x 34638 array([[ 1.+1.j, 0.+0.j], 34639 [ 0.+0.j, 2.+4.j]]) 34640 >>> x.getfield(np.float64) 34641 array([[ 1., 0.], 34642 [ 0., 2.]]) 34643 34644 By choosing an offset of 8 bytes we can select the complex part of the 34645 array for our view: 34646 34647 >>> x.getfield(np.float64, offset=8) 34648 array([[ 1., 0.], 34649 [ 0., 4.]])""" 34650 return array() 34651 imag = getset_descriptor() 34652 def item(self, ESCargs): 34653 """a.item(*args) 34654 34655 Copy an element of an array to a standard Python scalar and return it. 34656 34657 Parameters 34658 ---------- 34659 \*args : Arguments (variable number and type) 34660 34661 * none: in this case, the method only works for arrays 34662 with one element (`a.size == 1`), which element is 34663 copied into a standard Python scalar object and returned. 34664 34665 * int_type: this argument is interpreted as a flat index into 34666 the array, specifying which element to copy and return. 34667 34668 * tuple of int_types: functions as does a single int_type argument, 34669 except that the argument is interpreted as an nd-index into the 34670 array. 34671 34672 Returns 34673 ------- 34674 z : Standard Python scalar object 34675 A copy of the specified element of the array as a suitable 34676 Python scalar 34677 34678 Notes 34679 ----- 34680 When the data type of `a` is longdouble or clongdouble, item() returns 34681 a scalar array object because there is no available Python scalar that 34682 would not lose information. Void arrays return a buffer object for item(), 34683 unless fields are defined, in which case a tuple is returned. 34684 34685 `item` is very similar to a[args], except, instead of an array scalar, 34686 a standard Python scalar is returned. This can be useful for speeding up 34687 access to elements of the array and doing arithmetic on elements of the 34688 array using Python's optimized math. 34689 34690 Examples 34691 -------- 34692 >>> x = np.random.randint(9, size=(3, 3)) 34693 >>> x 34694 array([[3, 1, 7], 34695 [2, 8, 3], 34696 [8, 5, 3]]) 34697 >>> x.item(3) 34698 2 34699 >>> x.item(7) 34700 5 34701 >>> x.item((0, 1)) 34702 1 34703 >>> x.item((2, 2)) 34704 3""" 34705 return Standard() 34706 def itemset(self, ESCargs): 34707 """a.itemset(*args) 34708 34709 Insert scalar into an array (scalar is cast to array's dtype, if possible) 34710 34711 There must be at least 1 argument, and define the last argument 34712 as *item*. Then, ``a.itemset(*args)`` is equivalent to but faster 34713 than ``a[args] = item``. The item should be a scalar value and `args` 34714 must select a single item in the array `a`. 34715 34716 Parameters 34717 ---------- 34718 \*args : Arguments 34719 If one argument: a scalar, only used in case `a` is of size 1. 34720 If two arguments: the last argument is the value to be set 34721 and must be a scalar, the first argument specifies a single array 34722 element location. It is either an int or a tuple. 34723 34724 Notes 34725 ----- 34726 Compared to indexing syntax, `itemset` provides some speed increase 34727 for placing a scalar into a particular location in an `ndarray`, 34728 if you must do this. However, generally this is discouraged: 34729 among other problems, it complicates the appearance of the code. 34730 Also, when using `itemset` (and `item`) inside a loop, be sure 34731 to assign the methods to a local variable to avoid the attribute 34732 look-up at each loop iteration. 34733 34734 Examples 34735 -------- 34736 >>> x = np.random.randint(9, size=(3, 3)) 34737 >>> x 34738 array([[3, 1, 7], 34739 [2, 8, 3], 34740 [8, 5, 3]]) 34741 >>> x.itemset(4, 0) 34742 >>> x.itemset((2, 2), 9) 34743 >>> x 34744 array([[3, 1, 7], 34745 [2, 0, 3], 34746 [8, 5, 9]])""" 34747 return None 34748 itemsize = getset_descriptor() 34749 def max(self, axis=None, out=None): 34750 """a.max(axis=None, out=None) 34751 34752 Return the maximum along a given axis. 34753 34754 Refer to `numpy.amax` for full documentation. 34755 34756 See Also 34757 -------- 34758 numpy.amax : equivalent function""" 34759 return None 34760 def mean(self, axis=None, dtype=None, out=None): 34761 """a.mean(axis=None, dtype=None, out=None) 34762 34763 Returns the average of the array elements along given axis. 34764 34765 Refer to `numpy.mean` for full documentation. 34766 34767 See Also 34768 -------- 34769 numpy.mean : equivalent function""" 34770 return None 34771 def min(self, axis=None, out=None): 34772 """a.min(axis=None, out=None) 34773 34774 Return the minimum along a given axis. 34775 34776 Refer to `numpy.amin` for full documentation. 34777 34778 See Also 34779 -------- 34780 numpy.amin : equivalent function""" 34781 return None 34782 nbytes = getset_descriptor() 34783 ndim = getset_descriptor() 34784 def newbyteorder(self, new_order): 34785 """arr.newbyteorder(new_order='S') 34786 34787 Return the array with the same data viewed with a different byte order. 34788 34789 Equivalent to:: 34790 34791 arr.view(arr.dtype.newbytorder(new_order)) 34792 34793 Changes are also made in all fields and sub-arrays of the array data 34794 type. 34795 34796 34797 34798 Parameters 34799 ---------- 34800 new_order : string, optional 34801 Byte order to force; a value from the byte order specifications 34802 above. `new_order` codes can be any of:: 34803 34804 * 'S' - swap dtype from current to opposite endian 34805 * {'<', 'L'} - little endian 34806 * {'>', 'B'} - big endian 34807 * {'=', 'N'} - native order 34808 * {'|', 'I'} - ignore (no change to byte order) 34809 34810 The default value ('S') results in swapping the current 34811 byte order. The code does a case-insensitive check on the first 34812 letter of `new_order` for the alternatives above. For example, 34813 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. 34814 34815 34816 Returns 34817 ------- 34818 new_arr : array 34819 New array object with the dtype reflecting given change to the 34820 byte order.""" 34821 return array() 34822 def nonzero(self, _): 34823 """a.nonzero() 34824 34825 Return the indices of the elements that are non-zero. 34826 34827 Refer to `numpy.nonzero` for full documentation. 34828 34829 See Also 34830 -------- 34831 numpy.nonzero : equivalent function""" 34832 return None 34833 def partition(self, kth, axis, kind, order): 34834 """a.partition(kth, axis=-1, kind='introselect', order=None) 34835 34836 Rearranges the elements in the array in such a way that value of the 34837 element in kth position is in the position it would be in a sorted array. 34838 All elements smaller than the kth element are moved before this element and 34839 all equal or greater are moved behind it. The ordering of the elements in 34840 the two partitions is undefined. 34841 34842 .. versionadded:: 1.8.0 34843 34844 Parameters 34845 ---------- 34846 kth : int or sequence of ints 34847 Element index to partition by. The kth element value will be in its 34848 final sorted position and all smaller elements will be moved before it 34849 and all equal or greater elements behind it. 34850 The order all elements in the partitions is undefined. 34851 If provided with a sequence of kth it will partition all elements 34852 indexed by kth of them into their sorted position at once. 34853 axis : int, optional 34854 Axis along which to sort. Default is -1, which means sort along the 34855 last axis. 34856 kind : {'introselect'}, optional 34857 Selection algorithm. Default is 'introselect'. 34858 order : list, optional 34859 When `a` is an array with fields defined, this argument specifies 34860 which fields to compare first, second, etc. Not all fields need be 34861 specified. 34862 34863 See Also 34864 -------- 34865 numpy.partition : Return a parititioned copy of an array. 34866 argpartition : Indirect partition. 34867 sort : Full sort. 34868 34869 Notes 34870 ----- 34871 See ``np.partition`` for notes on the different algorithms. 34872 34873 Examples 34874 -------- 34875 >>> a = np.array([3, 4, 2, 1]) 34876 >>> a.partition(a, 3) 34877 >>> a 34878 array([2, 1, 3, 4]) 34879 34880 >>> a.partition((1, 3)) 34881 array([1, 2, 3, 4])""" 34882 return None 34883 def prod(self, axis=None, dtype=None, out=None): 34884 """a.prod(axis=None, dtype=None, out=None) 34885 34886 Return the product of the array elements over the given axis 34887 34888 Refer to `numpy.prod` for full documentation. 34889 34890 See Also 34891 -------- 34892 numpy.prod : equivalent function""" 34893 return None 34894 def ptp(self, axis=None, out=None): 34895 """a.ptp(axis=None, out=None) 34896 34897 Peak to peak (maximum - minimum) value along a given axis. 34898 34899 Refer to `numpy.ptp` for full documentation. 34900 34901 See Also 34902 -------- 34903 numpy.ptp : equivalent function""" 34904 return None 34905 def put(self, indices, values, mode=_raise): 34906 """a.put(indices, values, mode='raise') 34907 34908 Set ``a.flat[n] = values[n]`` for all `n` in indices. 34909 34910 Refer to `numpy.put` for full documentation. 34911 34912 See Also 34913 -------- 34914 numpy.put : equivalent function""" 34915 return None 34916 def ravel(self, order): 34917 """a.ravel([order]) 34918 34919 Return a flattened array. 34920 34921 Refer to `numpy.ravel` for full documentation. 34922 34923 See Also 34924 -------- 34925 numpy.ravel : equivalent function 34926 34927 ndarray.flat : a flat iterator on the array.""" 34928 return None 34929 real = getset_descriptor() 34930 def repeat(self, repeats, axis=None): 34931 """a.repeat(repeats, axis=None) 34932 34933 Repeat elements of an array. 34934 34935 Refer to `numpy.repeat` for full documentation. 34936 34937 See Also 34938 -------- 34939 numpy.repeat : equivalent function""" 34940 return None 34941 def reshape(self, shape, order=C): 34942 """a.reshape(shape, order='C') 34943 34944 Returns an array containing the same data with a new shape. 34945 34946 Refer to `numpy.reshape` for full documentation. 34947 34948 See Also 34949 -------- 34950 numpy.reshape : equivalent function""" 34951 return None 34952 def resize(self, new_shape, refcheck): 34953 """a.resize(new_shape, refcheck=True) 34954 34955 Change shape and size of array in-place. 34956 34957 Parameters 34958 ---------- 34959 new_shape : tuple of ints, or `n` ints 34960 Shape of resized array. 34961 refcheck : bool, optional 34962 If False, reference count will not be checked. Default is True. 34963 34964 Returns 34965 ------- 34966 None 34967 34968 Raises 34969 ------ 34970 ValueError 34971 If `a` does not own its own data or references or views to it exist, 34972 and the data memory must be changed. 34973 34974 SystemError 34975 If the `order` keyword argument is specified. This behaviour is a 34976 bug in NumPy. 34977 34978 See Also 34979 -------- 34980 resize : Return a new array with the specified shape. 34981 34982 Notes 34983 ----- 34984 This reallocates space for the data area if necessary. 34985 34986 Only contiguous arrays (data elements consecutive in memory) can be 34987 resized. 34988 34989 The purpose of the reference count check is to make sure you 34990 do not use this array as a buffer for another Python object and then 34991 reallocate the memory. However, reference counts can increase in 34992 other ways so if you are sure that you have not shared the memory 34993 for this array with another Python object, then you may safely set 34994 `refcheck` to False. 34995 34996 Examples 34997 -------- 34998 Shrinking an array: array is flattened (in the order that the data are 34999 stored in memory), resized, and reshaped: 35000 35001 >>> a = np.array([[0, 1], [2, 3]], order='C') 35002 >>> a.resize((2, 1)) 35003 >>> a 35004 array([[0], 35005 [1]]) 35006 35007 >>> a = np.array([[0, 1], [2, 3]], order='F') 35008 >>> a.resize((2, 1)) 35009 >>> a 35010 array([[0], 35011 [2]]) 35012 35013 Enlarging an array: as above, but missing entries are filled with zeros: 35014 35015 >>> b = np.array([[0, 1], [2, 3]]) 35016 >>> b.resize(2, 3) # new_shape parameter doesn't have to be a tuple 35017 >>> b 35018 array([[0, 1, 2], 35019 [3, 0, 0]]) 35020 35021 Referencing an array prevents resizing... 35022 35023 >>> c = a 35024 >>> a.resize((1, 1)) 35025 Traceback (most recent call last): 35026 ... 35027 ValueError: cannot resize an array that has been referenced ... 35028 35029 Unless `refcheck` is False: 35030 35031 >>> a.resize((1, 1), refcheck=False) 35032 >>> a 35033 array([[0]]) 35034 >>> c 35035 array([[0]])""" 35036 return None 35037 def round(self, decimals=0, out=None): 35038 """a.round(decimals=0, out=None) 35039 35040 Return `a` with each element rounded to the given number of decimals. 35041 35042 Refer to `numpy.around` for full documentation. 35043 35044 See Also 35045 -------- 35046 numpy.around : equivalent function""" 35047 return None 35048 def searchsorted(self, v, side=left, sorter=None): 35049 """a.searchsorted(v, side='left', sorter=None) 35050 35051 Find indices where elements of v should be inserted in a to maintain order. 35052 35053 For full documentation, see `numpy.searchsorted` 35054 35055 See Also 35056 -------- 35057 numpy.searchsorted : equivalent function""" 35058 return None 35059 def setfield(self, val, dtype, offset): 35060 """a.setfield(val, dtype, offset=0) 35061 35062 Put a value into a specified place in a field defined by a data-type. 35063 35064 Place `val` into `a`'s field defined by `dtype` and beginning `offset` 35065 bytes into the field. 35066 35067 Parameters 35068 ---------- 35069 val : object 35070 Value to be placed in field. 35071 dtype : dtype object 35072 Data-type of the field in which to place `val`. 35073 offset : int, optional 35074 The number of bytes into the field at which to place `val`. 35075 35076 Returns 35077 ------- 35078 None 35079 35080 See Also 35081 -------- 35082 getfield 35083 35084 Examples 35085 -------- 35086 >>> x = np.eye(3) 35087 >>> x.getfield(np.float64) 35088 array([[ 1., 0., 0.], 35089 [ 0., 1., 0.], 35090 [ 0., 0., 1.]]) 35091 >>> x.setfield(3, np.int32) 35092 >>> x.getfield(np.int32) 35093 array([[3, 3, 3], 35094 [3, 3, 3], 35095 [3, 3, 3]]) 35096 >>> x 35097 array([[ 1.00000000e+000, 1.48219694e-323, 1.48219694e-323], 35098 [ 1.48219694e-323, 1.00000000e+000, 1.48219694e-323], 35099 [ 1.48219694e-323, 1.48219694e-323, 1.00000000e+000]]) 35100 >>> x.setfield(np.eye(3), np.int32) 35101 >>> x 35102 array([[ 1., 0., 0.], 35103 [ 0., 1., 0.], 35104 [ 0., 0., 1.]])""" 35105 return None 35106 def setflags(self, write, align, uic): 35107 """a.setflags(write=None, align=None, uic=None) 35108 35109 Set array flags WRITEABLE, ALIGNED, and UPDATEIFCOPY, respectively. 35110 35111 These Boolean-valued flags affect how numpy interprets the memory 35112 area used by `a` (see Notes below). The ALIGNED flag can only 35113 be set to True if the data is actually aligned according to the type. 35114 The UPDATEIFCOPY flag can never be set to True. The flag WRITEABLE 35115 can only be set to True if the array owns its own memory, or the 35116 ultimate owner of the memory exposes a writeable buffer interface, 35117 or is a string. (The exception for string is made so that unpickling 35118 can be done without copying memory.) 35119 35120 Parameters 35121 ---------- 35122 write : bool, optional 35123 Describes whether or not `a` can be written to. 35124 align : bool, optional 35125 Describes whether or not `a` is aligned properly for its type. 35126 uic : bool, optional 35127 Describes whether or not `a` is a copy of another "base" array. 35128 35129 Notes 35130 ----- 35131 Array flags provide information about how the memory area used 35132 for the array is to be interpreted. There are 6 Boolean flags 35133 in use, only three of which can be changed by the user: 35134 UPDATEIFCOPY, WRITEABLE, and ALIGNED. 35135 35136 WRITEABLE (W) the data area can be written to; 35137 35138 ALIGNED (A) the data and strides are aligned appropriately for the hardware 35139 (as determined by the compiler); 35140 35141 UPDATEIFCOPY (U) this array is a copy of some other array (referenced 35142 by .base). When this array is deallocated, the base array will be 35143 updated with the contents of this array. 35144 35145 All flags can be accessed using their first (upper case) letter as well 35146 as the full name. 35147 35148 Examples 35149 -------- 35150 >>> y 35151 array([[3, 1, 7], 35152 [2, 0, 0], 35153 [8, 5, 9]]) 35154 >>> y.flags 35155 C_CONTIGUOUS : True 35156 F_CONTIGUOUS : False 35157 OWNDATA : True 35158 WRITEABLE : True 35159 ALIGNED : True 35160 UPDATEIFCOPY : False 35161 >>> y.setflags(write=0, align=0) 35162 >>> y.flags 35163 C_CONTIGUOUS : True 35164 F_CONTIGUOUS : False 35165 OWNDATA : True 35166 WRITEABLE : False 35167 ALIGNED : False 35168 UPDATEIFCOPY : False 35169 >>> y.setflags(uic=1) 35170 Traceback (most recent call last): 35171 File "<stdin>", line 1, in <module> 35172 ValueError: cannot set UPDATEIFCOPY flag to True""" 35173 return None 35174 shape = getset_descriptor() 35175 size = getset_descriptor() 35176 def sort(self, axis, kind, order): 35177 """a.sort(axis=-1, kind='quicksort', order=None) 35178 35179 Sort an array, in-place. 35180 35181 Parameters 35182 ---------- 35183 axis : int, optional 35184 Axis along which to sort. Default is -1, which means sort along the 35185 last axis. 35186 kind : {'quicksort', 'mergesort', 'heapsort'}, optional 35187 Sorting algorithm. Default is 'quicksort'. 35188 order : list, optional 35189 When `a` is an array with fields defined, this argument specifies 35190 which fields to compare first, second, etc. Not all fields need be 35191 specified. 35192 35193 See Also 35194 -------- 35195 numpy.sort : Return a sorted copy of an array. 35196 argsort : Indirect sort. 35197 lexsort : Indirect stable sort on multiple keys. 35198 searchsorted : Find elements in sorted array. 35199 partition: Partial sort. 35200 35201 Notes 35202 ----- 35203 See ``sort`` for notes on the different sorting algorithms. 35204 35205 Examples 35206 -------- 35207 >>> a = np.array([[1,4], [3,1]]) 35208 >>> a.sort(axis=1) 35209 >>> a 35210 array([[1, 4], 35211 [1, 3]]) 35212 >>> a.sort(axis=0) 35213 >>> a 35214 array([[1, 3], 35215 [1, 4]]) 35216 35217 Use the `order` keyword to specify a field to use when sorting a 35218 structured array: 35219 35220 >>> a = np.array([('a', 2), ('c', 1)], dtype=[('x', 'S1'), ('y', int)]) 35221 >>> a.sort(order='y') 35222 >>> a 35223 array([('c', 1), ('a', 2)], 35224 dtype=[('x', '|S1'), ('y', '<i4')])""" 35225 return None 35226 def squeeze(self, axis=None): 35227 """a.squeeze(axis=None) 35228 35229 Remove single-dimensional entries from the shape of `a`. 35230 35231 Refer to `numpy.squeeze` for full documentation. 35232 35233 See Also 35234 -------- 35235 numpy.squeeze : equivalent function""" 35236 return None 35237 def std(self, axis=None, dtype=None, out=None, ddof=0): 35238 """a.std(axis=None, dtype=None, out=None, ddof=0) 35239 35240 Returns the standard deviation of the array elements along given axis. 35241 35242 Refer to `numpy.std` for full documentation. 35243 35244 See Also 35245 -------- 35246 numpy.std : equivalent function""" 35247 return None 35248 strides = getset_descriptor() 35249 def sum(self, axis=None, dtype=None, out=None): 35250 """a.sum(axis=None, dtype=None, out=None) 35251 35252 Return the sum of the array elements over the given axis. 35253 35254 Refer to `numpy.sum` for full documentation. 35255 35256 See Also 35257 -------- 35258 numpy.sum : equivalent function""" 35259 return None 35260 def swapaxes(self, axis1, axis2): 35261 """a.swapaxes(axis1, axis2) 35262 35263 Return a view of the array with `axis1` and `axis2` interchanged. 35264 35265 Refer to `numpy.swapaxes` for full documentation. 35266 35267 See Also 35268 -------- 35269 numpy.swapaxes : equivalent function""" 35270 return None 35271 def take(self, indices, axis=None, out=None, mode=_raise): 35272 """a.take(indices, axis=None, out=None, mode='raise') 35273 35274 Return an array formed from the elements of `a` at the given indices. 35275 35276 Refer to `numpy.take` for full documentation. 35277 35278 See Also 35279 -------- 35280 numpy.take : equivalent function""" 35281 return None 35282 def tofile(self, fid, sep, format): 35283 """a.tofile(fid, sep="", format="%s") 35284 35285 Write array to a file as text or binary (default). 35286 35287 Data is always written in 'C' order, independent of the order of `a`. 35288 The data produced by this method can be recovered using the function 35289 fromfile(). 35290 35291 Parameters 35292 ---------- 35293 fid : file or str 35294 An open file object, or a string containing a filename. 35295 sep : str 35296 Separator between array items for text output. 35297 If "" (empty), a binary file is written, equivalent to 35298 ``file.write(a.tostring())``. 35299 format : str 35300 Format string for text file output. 35301 Each entry in the array is formatted to text by first converting 35302 it to the closest Python type, and then using "format" % item. 35303 35304 Notes 35305 ----- 35306 This is a convenience function for quick storage of array data. 35307 Information on endianness and precision is lost, so this method is not a 35308 good choice for files intended to archive data or transport data between 35309 machines with different endianness. Some of these problems can be overcome 35310 by outputting the data as text files, at the expense of speed and file 35311 size.""" 35312 return None 35313 def tolist(self, _): 35314 """a.tolist() 35315 35316 Return the array as a (possibly nested) list. 35317 35318 Return a copy of the array data as a (nested) Python list. 35319 Data items are converted to the nearest compatible Python type. 35320 35321 Parameters 35322 ---------- 35323 none 35324 35325 Returns 35326 ------- 35327 y : list 35328 The possibly nested list of array elements. 35329 35330 Notes 35331 ----- 35332 The array may be recreated, ``a = np.array(a.tolist())``. 35333 35334 Examples 35335 -------- 35336 >>> a = np.array([1, 2]) 35337 >>> a.tolist() 35338 [1, 2] 35339 >>> a = np.array([[1, 2], [3, 4]]) 35340 >>> list(a) 35341 [array([1, 2]), array([3, 4])] 35342 >>> a.tolist() 35343 [[1, 2], [3, 4]]""" 35344 return list() 35345 def tostring(self, order): 35346 """a.tostring(order='C') 35347 35348 Construct a Python string containing the raw data bytes in the array. 35349 35350 Constructs a Python string showing a copy of the raw contents of 35351 data memory. The string can be produced in either 'C' or 'Fortran', 35352 or 'Any' order (the default is 'C'-order). 'Any' order means C-order 35353 unless the F_CONTIGUOUS flag in the array is set, in which case it 35354 means 'Fortran' order. 35355 35356 Parameters 35357 ---------- 35358 order : {'C', 'F', None}, optional 35359 Order of the data for multidimensional arrays: 35360 C, Fortran, or the same as for the original array. 35361 35362 Returns 35363 ------- 35364 s : str 35365 A Python string exhibiting a copy of `a`'s raw data. 35366 35367 Examples 35368 -------- 35369 >>> x = np.array([[0, 1], [2, 3]]) 35370 >>> x.tostring() 35371 '\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00' 35372 >>> x.tostring('C') == x.tostring() 35373 True 35374 >>> x.tostring('F') 35375 '\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00'""" 35376 return str() 35377 def trace(self, offset=0, axis1=0, axis2=1, dtype=None, out=None): 35378 """a.trace(offset=0, axis1=0, axis2=1, dtype=None, out=None) 35379 35380 Return the sum along diagonals of the array. 35381 35382 Refer to `numpy.trace` for full documentation. 35383 35384 See Also 35385 -------- 35386 numpy.trace : equivalent function""" 35387 return None 35388 def transpose(self, axes): 35389 """a.transpose(*axes) 35390 35391 Returns a view of the array with axes transposed. 35392 35393 For a 1-D array, this has no effect. (To change between column and 35394 row vectors, first cast the 1-D array into a matrix object.) 35395 For a 2-D array, this is the usual matrix transpose. 35396 For an n-D array, if axes are given, their order indicates how the 35397 axes are permuted (see Examples). If axes are not provided and 35398 ``a.shape = (i[0], i[1], ... i[n-2], i[n-1])``, then 35399 ``a.transpose().shape = (i[n-1], i[n-2], ... i[1], i[0])``. 35400 35401 Parameters 35402 ---------- 35403 axes : None, tuple of ints, or `n` ints 35404 35405 * None or no argument: reverses the order of the axes. 35406 35407 * tuple of ints: `i` in the `j`-th place in the tuple means `a`'s 35408 `i`-th axis becomes `a.transpose()`'s `j`-th axis. 35409 35410 * `n` ints: same as an n-tuple of the same ints (this form is 35411 intended simply as a "convenience" alternative to the tuple form) 35412 35413 Returns 35414 ------- 35415 out : ndarray 35416 View of `a`, with axes suitably permuted. 35417 35418 See Also 35419 -------- 35420 ndarray.T : Array property returning the array transposed. 35421 35422 Examples 35423 -------- 35424 >>> a = np.array([[1, 2], [3, 4]]) 35425 >>> a 35426 array([[1, 2], 35427 [3, 4]]) 35428 >>> a.transpose() 35429 array([[1, 3], 35430 [2, 4]]) 35431 >>> a.transpose((1, 0)) 35432 array([[1, 3], 35433 [2, 4]]) 35434 >>> a.transpose(1, 0) 35435 array([[1, 3], 35436 [2, 4]])""" 35437 return ndarray() 35438 def var(self, axis=None, dtype=None, out=None, ddof=0): 35439 """a.var(axis=None, dtype=None, out=None, ddof=0) 35440 35441 Returns the variance of the array elements, along given axis. 35442 35443 Refer to `numpy.var` for full documentation. 35444 35445 See Also 35446 -------- 35447 numpy.var : equivalent function""" 35448 return None 35449 def view(self, dtype, type): 35450 """a.view(dtype=None, type=None) 35451 35452 New view of array with the same data. 35453 35454 Parameters 35455 ---------- 35456 dtype : data-type or ndarray sub-class, optional 35457 Data-type descriptor of the returned view, e.g., float32 or int16. The 35458 default, None, results in the view having the same data-type as `a`. 35459 This argument can also be specified as an ndarray sub-class, which 35460 then specifies the type of the returned object (this is equivalent to 35461 setting the ``type`` parameter). 35462 type : Python type, optional 35463 Type of the returned view, e.g., ndarray or matrix. Again, the 35464 default None results in type preservation. 35465 35466 Notes 35467 ----- 35468 ``a.view()`` is used two different ways: 35469 35470 ``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view 35471 of the array's memory with a different data-type. This can cause a 35472 reinterpretation of the bytes of memory. 35473 35474 ``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just 35475 returns an instance of `ndarray_subclass` that looks at the same array 35476 (same shape, dtype, etc.) This does not cause a reinterpretation of the 35477 memory. 35478 35479 For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of 35480 bytes per entry than the previous dtype (for example, converting a 35481 regular array to a structured array), then the behavior of the view 35482 cannot be predicted just from the superficial appearance of ``a`` (shown 35483 by ``print(a)``). It also depends on exactly how ``a`` is stored in 35484 memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus 35485 defined as a slice or transpose, etc., the view may give different 35486 results. 35487 35488 35489 Examples 35490 -------- 35491 >>> x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)]) 35492 35493 Viewing array data using a different type and dtype: 35494 35495 >>> y = x.view(dtype=np.int16, type=np.matrix) 35496 >>> y 35497 matrix([[513]], dtype=int16) 35498 >>> print type(y) 35499 <class 'numpy.matrixlib.defmatrix.matrix'> 35500 35501 Creating a view on a structured array so it can be used in calculations 35502 35503 >>> x = np.array([(1, 2),(3,4)], dtype=[('a', np.int8), ('b', np.int8)]) 35504 >>> xv = x.view(dtype=np.int8).reshape(-1,2) 35505 >>> xv 35506 array([[1, 2], 35507 [3, 4]], dtype=int8) 35508 >>> xv.mean(0) 35509 array([ 2., 3.]) 35510 35511 Making changes to the view changes the underlying array 35512 35513 >>> xv[0,1] = 20 35514 >>> print x 35515 [(1, 20) (3, 4)] 35516 35517 Using a view to convert an array to a record array: 35518 35519 >>> z = x.view(np.recarray) 35520 >>> z.a 35521 array([1], dtype=int8) 35522 35523 Views share data: 35524 35525 >>> x[0] = (9, 10) 35526 >>> z[0] 35527 (9, 10) 35528 35529 Views that change the dtype size (bytes per entry) should normally be 35530 avoided on arrays defined by slices, transposes, fortran-ordering, etc.: 35531 35532 >>> x = np.array([[1,2,3],[4,5,6]], dtype=np.int16) 35533 >>> y = x[:, 0:2] 35534 >>> y 35535 array([[1, 2], 35536 [4, 5]], dtype=int16) 35537 >>> y.view(dtype=[('width', np.int16), ('length', np.int16)]) 35538 Traceback (most recent call last): 35539 File "<stdin>", line 1, in <module> 35540 ValueError: new type not compatible with array. 35541 >>> z = y.copy() 35542 >>> z.view(dtype=[('width', np.int16), ('length', np.int16)]) 35543 array([[(1, 2)], 35544 [(4, 5)]], dtype=[('width', '<i2'), ('length', '<i2')])""" 35545 return None 35546 def ndpointer(self, dtype=None, ndim=None, shape=None, flags=None): 35547 """ 35548 Array-checking restype/argtypes. 35549 35550 An ndpointer instance is used to describe an ndarray in restypes 35551 and argtypes specifications. This approach is more flexible than 35552 using, for example, ``POINTER(c_double)``, since several restrictions 35553 can be specified, which are verified upon calling the ctypes function. 35554 These include data type, number of dimensions, shape and flags. If a 35555 given array does not satisfy the specified restrictions, 35556 a ``TypeError`` is raised. 35557 35558 Parameters 35559 ---------- 35560 dtype : data-type, optional 35561 Array data-type. 35562 ndim : int, optional 35563 Number of array dimensions. 35564 shape : tuple of ints, optional 35565 Array shape. 35566 flags : str or tuple of str 35567 Array flags; may be one or more of: 35568 35569 - C_CONTIGUOUS / C / CONTIGUOUS 35570 - F_CONTIGUOUS / F / FORTRAN 35571 - OWNDATA / O 35572 - WRITEABLE / W 35573 - ALIGNED / A 35574 - UPDATEIFCOPY / U 35575 35576 Returns 35577 ------- 35578 klass : ndpointer type object 35579 A type object, which is an ``_ndtpr`` instance containing 35580 dtype, ndim, shape and flags information. 35581 35582 Raises 35583 ------ 35584 TypeError 35585 If a given array does not satisfy the specified restrictions. 35586 35587 Examples 35588 -------- 35589 >>> clib.somefunc.argtypes = [np.ctypeslib.ndpointer(dtype=np.float64, 35590 ... ndim=1, 35591 ... flags='C_CONTIGUOUS')] 35592 ... #doctest: +SKIP 35593 >>> clib.somefunc(np.array([1, 2, 3], dtype=np.float64)) 35594 ... #doctest: +SKIP 35595 35596 """ 35597 return ndpointer() 35598 def prep_array(self, _): 35599 """Given a ctypes array type, construct and attach an 35600 __array_interface__ property to it if it does not yet have one. 35601 """ 35602 return None 35603 def prep_pointer(self, _): 35604 """Given a ctypes pointer object, construct and 35605 attach an __array_interface__ property to it if it does not 35606 yet have one. 35607 """ 35608 return None 35609 def prep_simple(self, _): 35610 """Given a ctypes simple type, construct and attach an 35611 __array_interface__ property to it if it does not yet have one. 35612 """ 35613 return None 35614 print_function = instance() 35615 simple_types = list() 35616 def c_double(self, _): 35617 """None""" 35618 return None 35619 types = tuple() 35620 class lib: 35621 class scimath: 35622 __all__ = list() 35623 __builtins__ = dict() 35624 __doc__ = str() 35625 __file__ = str() 35626 __name__ = str() 35627 __package__ = None 35628 def _fix_int_lt_zero(self, x): 35629 """Convert `x` to double if it has real, negative components. 35630 35631 Otherwise, output is just the array version of the input (via asarray). 35632 35633 Parameters 35634 ---------- 35635 x : array_like 35636 35637 Returns 35638 ------- 35639 array 35640 35641 Examples 35642 -------- 35643 >>> np.lib.scimath._fix_int_lt_zero([1,2]) 35644 array([1, 2]) 35645 35646 >>> np.lib.scimath._fix_int_lt_zero([-1,2]) 35647 array([-1., 2.]) 35648 """ 35649 return None 35650 def _fix_real_abs_gt_1(self, x): 35651 """Convert `x` to complex if it has real components x_i with abs(x_i)>1. 35652 35653 Otherwise, output is just the array version of the input (via asarray). 35654 35655 Parameters 35656 ---------- 35657 x : array_like 35658 35659 Returns 35660 ------- 35661 array 35662 35663 Examples 35664 -------- 35665 >>> np.lib.scimath._fix_real_abs_gt_1([0,1]) 35666 array([0, 1]) 35667 35668 >>> np.lib.scimath._fix_real_abs_gt_1([0,2]) 35669 array([ 0.+0.j, 2.+0.j]) 35670 """ 35671 return None 35672 def _fix_real_lt_zero(self, x): 35673 """Convert `x` to complex if it has real, negative components. 35674 35675 Otherwise, output is just the array version of the input (via asarray). 35676 35677 Parameters 35678 ---------- 35679 x : array_like 35680 35681 Returns 35682 ------- 35683 array 35684 35685 Examples 35686 -------- 35687 >>> np.lib.scimath._fix_real_lt_zero([1,2]) 35688 array([1, 2]) 35689 35690 >>> np.lib.scimath._fix_real_lt_zero([-1,2]) 35691 array([-1.+0.j, 2.+0.j]) 35692 """ 35693 return None 35694 _ln2 = float64() 35695 def _tocomplex(self, arr): 35696 """Convert its input `arr` to a complex array. 35697 35698 The input is returned as a complex array of the smallest type that will fit 35699 the original data: types like single, byte, short, etc. become csingle, 35700 while others become cdouble. 35701 35702 A copy of the input is always made. 35703 35704 Parameters 35705 ---------- 35706 arr : array 35707 35708 Returns 35709 ------- 35710 array 35711 An array with the same input data as the input but in complex form. 35712 35713 Examples 35714 -------- 35715 35716 First, consider an input of type short: 35717 35718 >>> a = np.array([1,2,3],np.short) 35719 35720 >>> ac = np.lib.scimath._tocomplex(a); ac 35721 array([ 1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) 35722 35723 >>> ac.dtype 35724 dtype('complex64') 35725 35726 If the input is of type double, the output is correspondingly of the 35727 complex double type as well: 35728 35729 >>> b = np.array([1,2,3],np.double) 35730 35731 >>> bc = np.lib.scimath._tocomplex(b); bc 35732 array([ 1.+0.j, 2.+0.j, 3.+0.j]) 35733 35734 >>> bc.dtype 35735 dtype('complex128') 35736 35737 Note that even if the input was complex to begin with, a copy is still 35738 made, since the astype() method always copies: 35739 35740 >>> c = np.array([1,2,3],np.csingle) 35741 35742 >>> cc = np.lib.scimath._tocomplex(c); cc 35743 array([ 1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) 35744 35745 >>> c *= 2; c 35746 array([ 2.+0.j, 4.+0.j, 6.+0.j], dtype=complex64) 35747 35748 >>> cc 35749 array([ 1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) 35750 """ 35751 return None 35752 absolute_import = instance() 35753 def any(self, a=False, axis=None, out=None, keepdims=False): 35754 """ 35755 Test whether any array element along a given axis evaluates to True. 35756 35757 Returns single boolean unless `axis` is not ``None`` 35758 35759 Parameters 35760 ---------- 35761 a : array_like 35762 Input array or object that can be converted to an array. 35763 axis : None or int or tuple of ints, optional 35764 Axis or axes along which a logical OR reduction is performed. 35765 The default (`axis` = `None`) is perform a logical OR over all 35766 the dimensions of the input array. `axis` may be negative, in 35767 which case it counts from the last to the first axis. 35768 35769 .. versionadded:: 1.7.0 35770 35771 If this is a tuple of ints, a reduction is performed on multiple 35772 axes, instead of a single axis or all the axes as before. 35773 out : ndarray, optional 35774 Alternate output array in which to place the result. It must have 35775 the same shape as the expected output and its type is preserved 35776 (e.g., if it is of type float, then it will remain so, returning 35777 1.0 for True and 0.0 for False, regardless of the type of `a`). 35778 See `doc.ufuncs` (Section "Output arguments") for details. 35779 keepdims : bool, optional 35780 If this is set to True, the axes which are reduced are left 35781 in the result as dimensions with size one. With this option, 35782 the result will broadcast correctly against the original `arr`. 35783 35784 Returns 35785 ------- 35786 any : bool or ndarray 35787 A new boolean or `ndarray` is returned unless `out` is specified, 35788 in which case a reference to `out` is returned. 35789 35790 See Also 35791 -------- 35792 ndarray.any : equivalent method 35793 35794 all : Test whether all elements along a given axis evaluate to True. 35795 35796 Notes 35797 ----- 35798 Not a Number (NaN), positive infinity and negative infinity evaluate 35799 to `True` because these are not equal to zero. 35800 35801 Examples 35802 -------- 35803 >>> np.any([[True, False], [True, True]]) 35804 True 35805 35806 >>> np.any([[True, False], [False, False]], axis=0) 35807 array([ True, False], dtype=bool) 35808 35809 >>> np.any([-1, 0, 5]) 35810 True 35811 35812 >>> np.any(np.nan) 35813 True 35814 35815 >>> o=np.array([False]) 35816 >>> z=np.any([-1, 4, 5], out=o) 35817 >>> z, o 35818 (array([ True], dtype=bool), array([ True], dtype=bool)) 35819 >>> # Check now that z is a reference to o 35820 >>> z is o 35821 True 35822 >>> id(z), id(o) # identity of z and o # doctest: +SKIP 35823 (191614240, 191614240) 35824 35825 """ 35826 return bool() if False else ndarray() 35827 def arccos(self, x): 35828 """ 35829 Compute the inverse cosine of x. 35830 35831 Return the "principal value" (for a description of this, see 35832 `numpy.arccos`) of the inverse cosine of `x`. For real `x` such that 35833 `abs(x) <= 1`, this is a real number in the closed interval 35834 :math:`[0, \pi]`. Otherwise, the complex principle value is returned. 35835 35836 Parameters 35837 ---------- 35838 x : array_like or scalar 35839 The value(s) whose arccos is (are) required. 35840 35841 Returns 35842 ------- 35843 out : ndarray or scalar 35844 The inverse cosine(s) of the `x` value(s). If `x` was a scalar, so 35845 is `out`, otherwise an array object is returned. 35846 35847 See Also 35848 -------- 35849 numpy.arccos 35850 35851 Notes 35852 ----- 35853 For an arccos() that returns ``NAN`` when real `x` is not in the 35854 interval ``[-1,1]``, use `numpy.arccos`. 35855 35856 Examples 35857 -------- 35858 >>> np.set_printoptions(precision=4) 35859 35860 >>> np.emath.arccos(1) # a scalar is returned 35861 0.0 35862 35863 >>> np.emath.arccos([1,2]) 35864 array([ 0.-0.j , 0.+1.317j]) 35865 35866 """ 35867 return ndarray() if False else float() 35868 def arcsin(self, x): 35869 """ 35870 Compute the inverse sine of x. 35871 35872 Return the "principal value" (for a description of this, see 35873 `numpy.arcsin`) of the inverse sine of `x`. For real `x` such that 35874 `abs(x) <= 1`, this is a real number in the closed interval 35875 :math:`[-\pi/2, \pi/2]`. Otherwise, the complex principle value is 35876 returned. 35877 35878 Parameters 35879 ---------- 35880 x : array_like or scalar 35881 The value(s) whose arcsin is (are) required. 35882 35883 Returns 35884 ------- 35885 out : ndarray or scalar 35886 The inverse sine(s) of the `x` value(s). If `x` was a scalar, so 35887 is `out`, otherwise an array object is returned. 35888 35889 See Also 35890 -------- 35891 numpy.arcsin 35892 35893 Notes 35894 ----- 35895 For an arcsin() that returns ``NAN`` when real `x` is not in the 35896 interval ``[-1,1]``, use `numpy.arcsin`. 35897 35898 Examples 35899 -------- 35900 >>> np.set_printoptions(precision=4) 35901 35902 >>> np.emath.arcsin(0) 35903 0.0 35904 35905 >>> np.emath.arcsin([0,1]) 35906 array([ 0. , 1.5708]) 35907 35908 """ 35909 return ndarray() if False else float() 35910 def arctanh(self, x): 35911 """ 35912 Compute the inverse hyperbolic tangent of `x`. 35913 35914 Return the "principal value" (for a description of this, see 35915 `numpy.arctanh`) of `arctanh(x)`. For real `x` such that 35916 `abs(x) < 1`, this is a real number. If `abs(x) > 1`, or if `x` is 35917 complex, the result is complex. Finally, `x = 1` returns``inf`` and 35918 `x=-1` returns ``-inf``. 35919 35920 Parameters 35921 ---------- 35922 x : array_like 35923 The value(s) whose arctanh is (are) required. 35924 35925 Returns 35926 ------- 35927 out : ndarray or scalar 35928 The inverse hyperbolic tangent(s) of the `x` value(s). If `x` was 35929 a scalar so is `out`, otherwise an array is returned. 35930 35931 35932 See Also 35933 -------- 35934 numpy.arctanh 35935 35936 Notes 35937 ----- 35938 For an arctanh() that returns ``NAN`` when real `x` is not in the 35939 interval ``(-1,1)``, use `numpy.arctanh` (this latter, however, does 35940 return +/-inf for `x = +/-1`). 35941 35942 Examples 35943 -------- 35944 >>> np.set_printoptions(precision=4) 35945 35946 >>> np.emath.arctanh(np.matrix(np.eye(2))) 35947 array([[ Inf, 0.], 35948 [ 0., Inf]]) 35949 >>> np.emath.arctanh([1j]) 35950 array([ 0.+0.7854j]) 35951 35952 """ 35953 return ndarray() if False else float() 35954 def asarray(self, a=None, dtype=None, order=None): 35955 """ 35956 Convert the input to an array. 35957 35958 Parameters 35959 ---------- 35960 a : array_like 35961 Input data, in any form that can be converted to an array. This 35962 includes lists, lists of tuples, tuples, tuples of tuples, tuples 35963 of lists and ndarrays. 35964 dtype : data-type, optional 35965 By default, the data-type is inferred from the input data. 35966 order : {'C', 'F'}, optional 35967 Whether to use row-major ('C') or column-major ('F' for FORTRAN) 35968 memory representation. Defaults to 'C'. 35969 35970 Returns 35971 ------- 35972 out : ndarray 35973 Array interpretation of `a`. No copy is performed if the input 35974 is already an ndarray. If `a` is a subclass of ndarray, a base 35975 class ndarray is returned. 35976 35977 See Also 35978 -------- 35979 asanyarray : Similar function which passes through subclasses. 35980 ascontiguousarray : Convert input to a contiguous array. 35981 asfarray : Convert input to a floating point ndarray. 35982 asfortranarray : Convert input to an ndarray with column-major 35983 memory order. 35984 asarray_chkfinite : Similar function which checks input for NaNs and Infs. 35985 fromiter : Create an array from an iterator. 35986 fromfunction : Construct an array by executing a function on grid 35987 positions. 35988 35989 Examples 35990 -------- 35991 Convert a list into an array: 35992 35993 >>> a = [1, 2] 35994 >>> np.asarray(a) 35995 array([1, 2]) 35996 35997 Existing arrays are not copied: 35998 35999 >>> a = np.array([1, 2]) 36000 >>> np.asarray(a) is a 36001 True 36002 36003 If `dtype` is set, array is copied only if dtype does not match: 36004 36005 >>> a = np.array([1, 2], dtype=np.float32) 36006 >>> np.asarray(a, dtype=np.float32) is a 36007 True 36008 >>> np.asarray(a, dtype=np.float64) is a 36009 False 36010 36011 Contrary to `asanyarray`, ndarray subclasses are not passed through: 36012 36013 >>> issubclass(np.matrix, np.ndarray) 36014 True 36015 >>> a = np.matrix([[1, 2]]) 36016 >>> np.asarray(a) is a 36017 False 36018 >>> np.asanyarray(a) is a 36019 True 36020 36021 """ 36022 return ndarray() 36023 division = instance() 36024 def isreal(self, x): 36025 """ 36026 Returns a bool array, where True if input element is real. 36027 36028 If element has complex type with zero complex part, the return value 36029 for that element is True. 36030 36031 Parameters 36032 ---------- 36033 x : array_like 36034 Input array. 36035 36036 Returns 36037 ------- 36038 out : ndarray, bool 36039 Boolean array of same shape as `x`. 36040 36041 See Also 36042 -------- 36043 iscomplex 36044 isrealobj : Return True if x is not a complex type. 36045 36046 Examples 36047 -------- 36048 >>> np.isreal([1+1j, 1+0j, 4.5, 3, 2, 2j]) 36049 array([False, True, True, True, True, False], dtype=bool) 36050 36051 """ 36052 return ndarray() 36053 def log(self, x): 36054 """ 36055 Compute the natural logarithm of `x`. 36056 36057 Return the "principal value" (for a description of this, see `numpy.log`) 36058 of :math:`log_e(x)`. For real `x > 0`, this is a real number (``log(0)`` 36059 returns ``-inf`` and ``log(np.inf)`` returns ``inf``). Otherwise, the 36060 complex principle value is returned. 36061 36062 Parameters 36063 ---------- 36064 x : array_like 36065 The value(s) whose log is (are) required. 36066 36067 Returns 36068 ------- 36069 out : ndarray or scalar 36070 The log of the `x` value(s). If `x` was a scalar, so is `out`, 36071 otherwise an array is returned. 36072 36073 See Also 36074 -------- 36075 numpy.log 36076 36077 Notes 36078 ----- 36079 For a log() that returns ``NAN`` when real `x < 0`, use `numpy.log` 36080 (note, however, that otherwise `numpy.log` and this `log` are identical, 36081 i.e., both return ``-inf`` for `x = 0`, ``inf`` for `x = inf`, and, 36082 notably, the complex principle value if ``x.imag != 0``). 36083 36084 Examples 36085 -------- 36086 >>> np.emath.log(np.exp(1)) 36087 1.0 36088 36089 Negative arguments are handled "correctly" (recall that 36090 ``exp(log(x)) == x`` does *not* hold for real ``x < 0``): 36091 36092 >>> np.emath.log(-np.exp(1)) == (1 + np.pi * 1j) 36093 True 36094 36095 """ 36096 return ndarray() if False else float() 36097 def log10(self, x): 36098 """ 36099 Compute the logarithm base 10 of `x`. 36100 36101 Return the "principal value" (for a description of this, see 36102 `numpy.log10`) of :math:`log_{10}(x)`. For real `x > 0`, this 36103 is a real number (``log10(0)`` returns ``-inf`` and ``log10(np.inf)`` 36104 returns ``inf``). Otherwise, the complex principle value is returned. 36105 36106 Parameters 36107 ---------- 36108 x : array_like or scalar 36109 The value(s) whose log base 10 is (are) required. 36110 36111 Returns 36112 ------- 36113 out : ndarray or scalar 36114 The log base 10 of the `x` value(s). If `x` was a scalar, so is `out`, 36115 otherwise an array object is returned. 36116 36117 See Also 36118 -------- 36119 numpy.log10 36120 36121 Notes 36122 ----- 36123 For a log10() that returns ``NAN`` when real `x < 0`, use `numpy.log10` 36124 (note, however, that otherwise `numpy.log10` and this `log10` are 36125 identical, i.e., both return ``-inf`` for `x = 0`, ``inf`` for `x = inf`, 36126 and, notably, the complex principle value if ``x.imag != 0``). 36127 36128 Examples 36129 -------- 36130 36131 (We set the printing precision so the example can be auto-tested) 36132 36133 >>> np.set_printoptions(precision=4) 36134 36135 >>> np.emath.log10(10**1) 36136 1.0 36137 36138 >>> np.emath.log10([-10**1, -10**2, 10**2]) 36139 array([ 1.+1.3644j, 2.+1.3644j, 2.+0.j ]) 36140 36141 """ 36142 return ndarray() if False else float() 36143 def log2(self, x): 36144 """ 36145 Compute the logarithm base 2 of `x`. 36146 36147 Return the "principal value" (for a description of this, see 36148 `numpy.log2`) of :math:`log_2(x)`. For real `x > 0`, this is 36149 a real number (``log2(0)`` returns ``-inf`` and ``log2(np.inf)`` returns 36150 ``inf``). Otherwise, the complex principle value is returned. 36151 36152 Parameters 36153 ---------- 36154 x : array_like 36155 The value(s) whose log base 2 is (are) required. 36156 36157 Returns 36158 ------- 36159 out : ndarray or scalar 36160 The log base 2 of the `x` value(s). If `x` was a scalar, so is `out`, 36161 otherwise an array is returned. 36162 36163 See Also 36164 -------- 36165 numpy.log2 36166 36167 Notes 36168 ----- 36169 For a log2() that returns ``NAN`` when real `x < 0`, use `numpy.log2` 36170 (note, however, that otherwise `numpy.log2` and this `log2` are 36171 identical, i.e., both return ``-inf`` for `x = 0`, ``inf`` for `x = inf`, 36172 and, notably, the complex principle value if ``x.imag != 0``). 36173 36174 Examples 36175 -------- 36176 We set the printing precision so the example can be auto-tested: 36177 36178 >>> np.set_printoptions(precision=4) 36179 36180 >>> np.emath.log2(8) 36181 3.0 36182 >>> np.emath.log2([-4, -8, 8]) 36183 array([ 2.+4.5324j, 3.+4.5324j, 3.+0.j ]) 36184 36185 """ 36186 return ndarray() if False else float() 36187 def logn(self, n, x): 36188 """ 36189 Take log base n of x. 36190 36191 If `x` contains negative inputs, the answer is computed and returned in the 36192 complex domain. 36193 36194 Parameters 36195 ---------- 36196 n : int 36197 The base in which the log is taken. 36198 x : array_like 36199 The value(s) whose log base `n` is (are) required. 36200 36201 Returns 36202 ------- 36203 out : ndarray or scalar 36204 The log base `n` of the `x` value(s). If `x` was a scalar, so is 36205 `out`, otherwise an array is returned. 36206 36207 Examples 36208 -------- 36209 >>> np.set_printoptions(precision=4) 36210 36211 >>> np.lib.scimath.logn(2, [4, 8]) 36212 array([ 2., 3.]) 36213 >>> np.lib.scimath.logn(2, [-4, -8, 8]) 36214 array([ 2.+4.5324j, 3.+4.5324j, 3.+0.j ]) 36215 36216 """ 36217 return ndarray() if False else float() 36218 def power(self, x, p): 36219 """ 36220 Return x to the power p, (x**p). 36221 36222 If `x` contains negative values, the output is converted to the 36223 complex domain. 36224 36225 Parameters 36226 ---------- 36227 x : array_like 36228 The input value(s). 36229 p : array_like of ints 36230 The power(s) to which `x` is raised. If `x` contains multiple values, 36231 `p` has to either be a scalar, or contain the same number of values 36232 as `x`. In the latter case, the result is 36233 ``x[0]**p[0], x[1]**p[1], ...``. 36234 36235 Returns 36236 ------- 36237 out : ndarray or scalar 36238 The result of ``x**p``. If `x` and `p` are scalars, so is `out`, 36239 otherwise an array is returned. 36240 36241 See Also 36242 -------- 36243 numpy.power 36244 36245 Examples 36246 -------- 36247 >>> np.set_printoptions(precision=4) 36248 36249 >>> np.lib.scimath.power([2, 4], 2) 36250 array([ 4, 16]) 36251 >>> np.lib.scimath.power([2, 4], -2) 36252 array([ 0.25 , 0.0625]) 36253 >>> np.lib.scimath.power([-2, 4], 2) 36254 array([ 4.+0.j, 16.+0.j]) 36255 36256 """ 36257 return ndarray() if False else float() 36258 print_function = instance() 36259 def sqrt(self, x): 36260 """ 36261 Compute the square root of x. 36262 36263 For negative input elements, a complex value is returned 36264 (unlike `numpy.sqrt` which returns NaN). 36265 36266 Parameters 36267 ---------- 36268 x : array_like 36269 The input value(s). 36270 36271 Returns 36272 ------- 36273 out : ndarray or scalar 36274 The square root of `x`. If `x` was a scalar, so is `out`, 36275 otherwise an array is returned. 36276 36277 See Also 36278 -------- 36279 numpy.sqrt 36280 36281 Examples 36282 -------- 36283 For real, non-negative inputs this works just like `numpy.sqrt`: 36284 36285 >>> np.lib.scimath.sqrt(1) 36286 1.0 36287 >>> np.lib.scimath.sqrt([1, 4]) 36288 array([ 1., 2.]) 36289 36290 But it automatically handles negative inputs: 36291 36292 >>> np.lib.scimath.sqrt(-1) 36293 (0.0+1.0j) 36294 >>> np.lib.scimath.sqrt([-1,4]) 36295 array([ 0.+1.j, 2.+0.j]) 36296 36297 """ 36298 return ndarray() if False else float() 36299 class fft: 36300 class NoseTester: 36301 __dict__ = dictproxy() 36302 __doc__ = str() 36303 __module__ = str() 36304 __weakref__ = getset_descriptor() 36305 def _get_custom_doctester(self, _): 36306 """ Return instantiated plugin for doctests 36307 36308 Allows subclassing of this class to override doctester 36309 36310 A return value of None means use the nose builtin doctest plugin 36311 """ 36312 return None 36313 def _show_system_info(self, _): 36314 """None""" 36315 return None 36316 def _test_argv(self, label, verbose, extra_argv): 36317 """ Generate argv for nosetest command 36318 36319 Parameters 36320 ---------- 36321 label : {'fast', 'full', '', attribute identifier}, optional 36322 see ``test`` docstring 36323 verbose : int, optional 36324 Verbosity value for test outputs, in the range 1-10. Default is 1. 36325 extra_argv : list, optional 36326 List with any extra arguments to pass to nosetests. 36327 36328 Returns 36329 ------- 36330 argv : list 36331 command line arguments that will be passed to nose 36332 """ 36333 return list() 36334 def bench(self=None, label="fast", verbose=1, extra_argv=None): 36335 """ 36336 Run benchmarks for module using nose. 36337 36338 Parameters 36339 ---------- 36340 label : {'fast', 'full', '', attribute identifier}, optional 36341 Identifies the benchmarks to run. This can be a string to pass to 36342 the nosetests executable with the '-A' option, or one of several 36343 special values. Special values are: 36344 * 'fast' - the default - which corresponds to the ``nosetests -A`` 36345 option of 'not slow'. 36346 * 'full' - fast (as above) and slow benchmarks as in the 36347 'no -A' option to nosetests - this is the same as ''. 36348 * None or '' - run all tests. 36349 attribute_identifier - string passed directly to nosetests as '-A'. 36350 verbose : int, optional 36351 Verbosity value for benchmark outputs, in the range 1-10. Default is 1. 36352 extra_argv : list, optional 36353 List with any extra arguments to pass to nosetests. 36354 36355 Returns 36356 ------- 36357 success : bool 36358 Returns True if running the benchmarks works, False if an error 36359 occurred. 36360 36361 Notes 36362 ----- 36363 Benchmarks are like tests, but have names starting with "bench" instead 36364 of "test", and can be found under the "benchmarks" sub-directory of the 36365 module. 36366 36367 Each NumPy module exposes `bench` in its namespace to run all benchmarks 36368 for it. 36369 36370 Examples 36371 -------- 36372 >>> success = np.lib.bench() #doctest: +SKIP 36373 Running benchmarks for numpy.lib 36374 ... 36375 using 562341 items: 36376 unique: 36377 0.11 36378 unique1d: 36379 0.11 36380 ratio: 1.0 36381 nUnique: 56230 == 56230 36382 ... 36383 OK 36384 36385 >>> success #doctest: +SKIP 36386 True 36387 36388 """ 36389 return bool() 36390 excludes = list() 36391 def prepare_test_args(self=False, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False): 36392 """ 36393 Run tests for module using nose. 36394 36395 This method does the heavy lifting for the `test` method. It takes all 36396 the same arguments, for details see `test`. 36397 36398 See Also 36399 -------- 36400 test 36401 36402 """ 36403 return None 36404 def test(self=None, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None): 36405 """ 36406 Run tests for module using nose. 36407 36408 Parameters 36409 ---------- 36410 label : {'fast', 'full', '', attribute identifier}, optional 36411 Identifies the tests to run. This can be a string to pass to 36412 the nosetests executable with the '-A' option, or one of several 36413 special values. Special values are: 36414 * 'fast' - the default - which corresponds to the ``nosetests -A`` 36415 option of 'not slow'. 36416 * 'full' - fast (as above) and slow tests as in the 36417 'no -A' option to nosetests - this is the same as ''. 36418 * None or '' - run all tests. 36419 attribute_identifier - string passed directly to nosetests as '-A'. 36420 verbose : int, optional 36421 Verbosity value for test outputs, in the range 1-10. Default is 1. 36422 extra_argv : list, optional 36423 List with any extra arguments to pass to nosetests. 36424 doctests : bool, optional 36425 If True, run doctests in module. Default is False. 36426 coverage : bool, optional 36427 If True, report coverage of NumPy code. Default is False. 36428 (This requires the `coverage module: 36429 <http://nedbatchelder.com/code/modules/coverage.html>`_). 36430 raise_warnings : str or sequence of warnings, optional 36431 This specifies which warnings to configure as 'raise' instead 36432 of 'warn' during the test execution. Valid strings are: 36433 36434 - "develop" : equals ``(DeprecationWarning, RuntimeWarning)`` 36435 - "release" : equals ``()``, don't raise on any warnings. 36436 36437 Returns 36438 ------- 36439 result : object 36440 Returns the result of running the tests as a 36441 ``nose.result.TextTestResult`` object. 36442 36443 Notes 36444 ----- 36445 Each NumPy module exposes `test` in its namespace to run all tests for it. 36446 For example, to run all tests for numpy.lib: 36447 36448 >>> np.lib.test() #doctest: +SKIP 36449 36450 Examples 36451 -------- 36452 >>> result = np.lib.test() #doctest: +SKIP 36453 Running unit tests for numpy.lib 36454 ... 36455 Ran 976 tests in 3.933s 36456 36457 OK 36458 36459 >>> result.errors #doctest: +SKIP 36460 [] 36461 >>> result.knownfail #doctest: +SKIP 36462 [] 36463 """ 36464 return object() 36465 __builtins__ = dict() 36466 __doc__ = str() 36467 __file__ = str() 36468 __name__ = str() 36469 __package__ = str() 36470 __path__ = list() 36471 absolute_import = instance() 36472 def bench(self=None, label="fast", verbose=1, extra_argv=None): 36473 """ 36474 Run benchmarks for module using nose. 36475 36476 Parameters 36477 ---------- 36478 label : {'fast', 'full', '', attribute identifier}, optional 36479 Identifies the benchmarks to run. This can be a string to pass to 36480 the nosetests executable with the '-A' option, or one of several 36481 special values. Special values are: 36482 * 'fast' - the default - which corresponds to the ``nosetests -A`` 36483 option of 'not slow'. 36484 * 'full' - fast (as above) and slow benchmarks as in the 36485 'no -A' option to nosetests - this is the same as ''. 36486 * None or '' - run all tests. 36487 attribute_identifier - string passed directly to nosetests as '-A'. 36488 verbose : int, optional 36489 Verbosity value for benchmark outputs, in the range 1-10. Default is 1. 36490 extra_argv : list, optional 36491 List with any extra arguments to pass to nosetests. 36492 36493 Returns 36494 ------- 36495 success : bool 36496 Returns True if running the benchmarks works, False if an error 36497 occurred. 36498 36499 Notes 36500 ----- 36501 Benchmarks are like tests, but have names starting with "bench" instead 36502 of "test", and can be found under the "benchmarks" sub-directory of the 36503 module. 36504 36505 Each NumPy module exposes `bench` in its namespace to run all benchmarks 36506 for it. 36507 36508 Examples 36509 -------- 36510 >>> success = np.lib.bench() #doctest: +SKIP 36511 Running benchmarks for numpy.lib 36512 ... 36513 using 562341 items: 36514 unique: 36515 0.11 36516 unique1d: 36517 0.11 36518 ratio: 1.0 36519 nUnique: 56230 == 56230 36520 ... 36521 OK 36522 36523 >>> success #doctest: +SKIP 36524 True 36525 36526 """ 36527 return bool() 36528 division = instance() 36529 def fft(self, a=-1, n=None, axis=-1): 36530 """ 36531 Compute the one-dimensional discrete Fourier Transform. 36532 36533 This function computes the one-dimensional *n*-point discrete Fourier 36534 Transform (DFT) with the efficient Fast Fourier Transform (FFT) 36535 algorithm [CT]. 36536 36537 Parameters 36538 ---------- 36539 a : array_like 36540 Input array, can be complex. 36541 n : int, optional 36542 Length of the transformed axis of the output. 36543 If `n` is smaller than the length of the input, the input is cropped. 36544 If it is larger, the input is padded with zeros. If `n` is not given, 36545 the length of the input (along the axis specified by `axis`) is used. 36546 axis : int, optional 36547 Axis over which to compute the FFT. If not given, the last axis is 36548 used. 36549 36550 Returns 36551 ------- 36552 out : complex ndarray 36553 The truncated or zero-padded input, transformed along the axis 36554 indicated by `axis`, or the last one if `axis` is not specified. 36555 36556 Raises 36557 ------ 36558 IndexError 36559 if `axes` is larger than the last axis of `a`. 36560 36561 See Also 36562 -------- 36563 numpy.fft : for definition of the DFT and conventions used. 36564 ifft : The inverse of `fft`. 36565 fft2 : The two-dimensional FFT. 36566 fftn : The *n*-dimensional FFT. 36567 rfftn : The *n*-dimensional FFT of real input. 36568 fftfreq : Frequency bins for given FFT parameters. 36569 36570 Notes 36571 ----- 36572 FFT (Fast Fourier Transform) refers to a way the discrete Fourier 36573 Transform (DFT) can be calculated efficiently, by using symmetries in the 36574 calculated terms. The symmetry is highest when `n` is a power of 2, and 36575 the transform is therefore most efficient for these sizes. 36576 36577 The DFT is defined, with the conventions used in this implementation, in 36578 the documentation for the `numpy.fft` module. 36579 36580 References 36581 ---------- 36582 .. [CT] Cooley, James W., and John W. Tukey, 1965, "An algorithm for the 36583 machine calculation of complex Fourier series," *Math. Comput.* 36584 19: 297-301. 36585 36586 Examples 36587 -------- 36588 >>> np.fft.fft(np.exp(2j * np.pi * np.arange(8) / 8)) 36589 array([ -3.44505240e-16 +1.14383329e-17j, 36590 8.00000000e+00 -5.71092652e-15j, 36591 2.33482938e-16 +1.22460635e-16j, 36592 1.64863782e-15 +1.77635684e-15j, 36593 9.95839695e-17 +2.33482938e-16j, 36594 0.00000000e+00 +1.66837030e-15j, 36595 1.14383329e-17 +1.22460635e-16j, 36596 -1.64863782e-15 +1.77635684e-15j]) 36597 36598 >>> import matplotlib.pyplot as plt 36599 >>> t = np.arange(256) 36600 >>> sp = np.fft.fft(np.sin(t)) 36601 >>> freq = np.fft.fftfreq(t.shape[-1]) 36602 >>> plt.plot(freq, sp.real, freq, sp.imag) 36603 [<matplotlib.lines.Line2D object at 0x...>, <matplotlib.lines.Line2D object at 0x...>] 36604 >>> plt.show() 36605 36606 In this example, real input has an FFT which is Hermitian, i.e., symmetric 36607 in the real part and anti-symmetric in the imaginary part, as described in 36608 the `numpy.fft` documentation. 36609 36610 """ 36611 return complex() 36612 def fft2(self, a="(-2, -1)", s=None, axes="(-2, -1)"): 36613 """ 36614 Compute the 2-dimensional discrete Fourier Transform 36615 36616 This function computes the *n*-dimensional discrete Fourier Transform 36617 over any axes in an *M*-dimensional array by means of the 36618 Fast Fourier Transform (FFT). By default, the transform is computed over 36619 the last two axes of the input array, i.e., a 2-dimensional FFT. 36620 36621 Parameters 36622 ---------- 36623 a : array_like 36624 Input array, can be complex 36625 s : sequence of ints, optional 36626 Shape (length of each transformed axis) of the output 36627 (`s[0]` refers to axis 0, `s[1]` to axis 1, etc.). 36628 This corresponds to `n` for `fft(x, n)`. 36629 Along each axis, if the given shape is smaller than that of the input, 36630 the input is cropped. If it is larger, the input is padded with zeros. 36631 if `s` is not given, the shape of the input (along the axes specified 36632 by `axes`) is used. 36633 axes : sequence of ints, optional 36634 Axes over which to compute the FFT. If not given, the last two 36635 axes are used. A repeated index in `axes` means the transform over 36636 that axis is performed multiple times. A one-element sequence means 36637 that a one-dimensional FFT is performed. 36638 36639 Returns 36640 ------- 36641 out : complex ndarray 36642 The truncated or zero-padded input, transformed along the axes 36643 indicated by `axes`, or the last two axes if `axes` is not given. 36644 36645 Raises 36646 ------ 36647 ValueError 36648 If `s` and `axes` have different length, or `axes` not given and 36649 ``len(s) != 2``. 36650 IndexError 36651 If an element of `axes` is larger than than the number of axes of `a`. 36652 36653 See Also 36654 -------- 36655 numpy.fft : Overall view of discrete Fourier transforms, with definitions 36656 and conventions used. 36657 ifft2 : The inverse two-dimensional FFT. 36658 fft : The one-dimensional FFT. 36659 fftn : The *n*-dimensional FFT. 36660 fftshift : Shifts zero-frequency terms to the center of the array. 36661 For two-dimensional input, swaps first and third quadrants, and second 36662 and fourth quadrants. 36663 36664 Notes 36665 ----- 36666 `fft2` is just `fftn` with a different default for `axes`. 36667 36668 The output, analogously to `fft`, contains the term for zero frequency in 36669 the low-order corner of the transformed axes, the positive frequency terms 36670 in the first half of these axes, the term for the Nyquist frequency in the 36671 middle of the axes and the negative frequency terms in the second half of 36672 the axes, in order of decreasingly negative frequency. 36673 36674 See `fftn` for details and a plotting example, and `numpy.fft` for 36675 definitions and conventions used. 36676 36677 36678 Examples 36679 -------- 36680 >>> a = np.mgrid[:5, :5][0] 36681 >>> np.fft.fft2(a) 36682 array([[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], 36683 [ 5.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], 36684 [ 10.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], 36685 [ 15.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], 36686 [ 20.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j]]) 36687 36688 """ 36689 return complex() 36690 def fftfreq(self, n=1.0, d=1.0): 36691 """ 36692 Return the Discrete Fourier Transform sample frequencies. 36693 36694 The returned float array `f` contains the frequency bin centers in cycles 36695 per unit of the sample spacing (with zero at the start). For instance, if 36696 the sample spacing is in seconds, then the frequency unit is cycles/second. 36697 36698 Given a window length `n` and a sample spacing `d`:: 36699 36700 f = [0, 1, ..., n/2-1, -n/2, ..., -1] / (d*n) if n is even 36701 f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n) if n is odd 36702 36703 Parameters 36704 ---------- 36705 n : int 36706 Window length. 36707 d : scalar, optional 36708 Sample spacing (inverse of the sampling rate). Defaults to 1. 36709 36710 Returns 36711 ------- 36712 f : ndarray 36713 Array of length `n` containing the sample frequencies. 36714 36715 Examples 36716 -------- 36717 >>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float) 36718 >>> fourier = np.fft.fft(signal) 36719 >>> n = signal.size 36720 >>> timestep = 0.1 36721 >>> freq = np.fft.fftfreq(n, d=timestep) 36722 >>> freq 36723 array([ 0. , 1.25, 2.5 , 3.75, -5. , -3.75, -2.5 , -1.25]) 36724 36725 """ 36726 return ndarray() 36727 def fftn(self, a=None, s=None, axes=None): 36728 """ 36729 Compute the N-dimensional discrete Fourier Transform. 36730 36731 This function computes the *N*-dimensional discrete Fourier Transform over 36732 any number of axes in an *M*-dimensional array by means of the Fast Fourier 36733 Transform (FFT). 36734 36735 Parameters 36736 ---------- 36737 a : array_like 36738 Input array, can be complex. 36739 s : sequence of ints, optional 36740 Shape (length of each transformed axis) of the output 36741 (`s[0]` refers to axis 0, `s[1]` to axis 1, etc.). 36742 This corresponds to `n` for `fft(x, n)`. 36743 Along any axis, if the given shape is smaller than that of the input, 36744 the input is cropped. If it is larger, the input is padded with zeros. 36745 if `s` is not given, the shape of the input (along the axes specified 36746 by `axes`) is used. 36747 axes : sequence of ints, optional 36748 Axes over which to compute the FFT. If not given, the last ``len(s)`` 36749 axes are used, or all axes if `s` is also not specified. 36750 Repeated indices in `axes` means that the transform over that axis is 36751 performed multiple times. 36752 36753 Returns 36754 ------- 36755 out : complex ndarray 36756 The truncated or zero-padded input, transformed along the axes 36757 indicated by `axes`, or by a combination of `s` and `a`, 36758 as explained in the parameters section above. 36759 36760 Raises 36761 ------ 36762 ValueError 36763 If `s` and `axes` have different length. 36764 IndexError 36765 If an element of `axes` is larger than than the number of axes of `a`. 36766 36767 See Also 36768 -------- 36769 numpy.fft : Overall view of discrete Fourier transforms, with definitions 36770 and conventions used. 36771 ifftn : The inverse of `fftn`, the inverse *n*-dimensional FFT. 36772 fft : The one-dimensional FFT, with definitions and conventions used. 36773 rfftn : The *n*-dimensional FFT of real input. 36774 fft2 : The two-dimensional FFT. 36775 fftshift : Shifts zero-frequency terms to centre of array 36776 36777 Notes 36778 ----- 36779 The output, analogously to `fft`, contains the term for zero frequency in 36780 the low-order corner of all axes, the positive frequency terms in the 36781 first half of all axes, the term for the Nyquist frequency in the middle 36782 of all axes and the negative frequency terms in the second half of all 36783 axes, in order of decreasingly negative frequency. 36784 36785 See `numpy.fft` for details, definitions and conventions used. 36786 36787 Examples 36788 -------- 36789 >>> a = np.mgrid[:3, :3, :3][0] 36790 >>> np.fft.fftn(a, axes=(1, 2)) 36791 array([[[ 0.+0.j, 0.+0.j, 0.+0.j], 36792 [ 0.+0.j, 0.+0.j, 0.+0.j], 36793 [ 0.+0.j, 0.+0.j, 0.+0.j]], 36794 [[ 9.+0.j, 0.+0.j, 0.+0.j], 36795 [ 0.+0.j, 0.+0.j, 0.+0.j], 36796 [ 0.+0.j, 0.+0.j, 0.+0.j]], 36797 [[ 18.+0.j, 0.+0.j, 0.+0.j], 36798 [ 0.+0.j, 0.+0.j, 0.+0.j], 36799 [ 0.+0.j, 0.+0.j, 0.+0.j]]]) 36800 >>> np.fft.fftn(a, (2, 2), axes=(0, 1)) 36801 array([[[ 2.+0.j, 2.+0.j, 2.+0.j], 36802 [ 0.+0.j, 0.+0.j, 0.+0.j]], 36803 [[-2.+0.j, -2.+0.j, -2.+0.j], 36804 [ 0.+0.j, 0.+0.j, 0.+0.j]]]) 36805 36806 >>> import matplotlib.pyplot as plt 36807 >>> [X, Y] = np.meshgrid(2 * np.pi * np.arange(200) / 12, 36808 ... 2 * np.pi * np.arange(200) / 34) 36809 >>> S = np.sin(X) + np.cos(Y) + np.random.uniform(0, 1, X.shape) 36810 >>> FS = np.fft.fftn(S) 36811 >>> plt.imshow(np.log(np.abs(np.fft.fftshift(FS))**2)) 36812 <matplotlib.image.AxesImage object at 0x...> 36813 >>> plt.show() 36814 36815 """ 36816 return complex() 36817 def fftshift(self, x=None, axes=None): 36818 """ 36819 Shift the zero-frequency component to the center of the spectrum. 36820 36821 This function swaps half-spaces for all axes listed (defaults to all). 36822 Note that ``y[0]`` is the Nyquist component only if ``len(x)`` is even. 36823 36824 Parameters 36825 ---------- 36826 x : array_like 36827 Input array. 36828 axes : int or shape tuple, optional 36829 Axes over which to shift. Default is None, which shifts all axes. 36830 36831 Returns 36832 ------- 36833 y : ndarray 36834 The shifted array. 36835 36836 See Also 36837 -------- 36838 ifftshift : The inverse of `fftshift`. 36839 36840 Examples 36841 -------- 36842 >>> freqs = np.fft.fftfreq(10, 0.1) 36843 >>> freqs 36844 array([ 0., 1., 2., 3., 4., -5., -4., -3., -2., -1.]) 36845 >>> np.fft.fftshift(freqs) 36846 array([-5., -4., -3., -2., -1., 0., 1., 2., 3., 4.]) 36847 36848 Shift the zero-frequency component only along the second axis: 36849 36850 >>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3) 36851 >>> freqs 36852 array([[ 0., 1., 2.], 36853 [ 3., 4., -4.], 36854 [-3., -2., -1.]]) 36855 >>> np.fft.fftshift(freqs, axes=(1,)) 36856 array([[ 2., 0., 1.], 36857 [-4., 3., 4.], 36858 [-1., -3., -2.]]) 36859 36860 """ 36861 return ndarray() 36862 def hfft(self, a=-1, n=None, axis=-1): 36863 """ 36864 Compute the FFT of a signal whose spectrum has Hermitian symmetry. 36865 36866 Parameters 36867 ---------- 36868 a : array_like 36869 The input array. 36870 n : int, optional 36871 The length of the FFT. 36872 axis : int, optional 36873 The axis over which to compute the FFT, assuming Hermitian symmetry 36874 of the spectrum. Default is the last axis. 36875 36876 Returns 36877 ------- 36878 out : ndarray 36879 The transformed input. 36880 36881 See also 36882 -------- 36883 rfft : Compute the one-dimensional FFT for real input. 36884 ihfft : The inverse of `hfft`. 36885 36886 Notes 36887 ----- 36888 `hfft`/`ihfft` are a pair analogous to `rfft`/`irfft`, but for the 36889 opposite case: here the signal is real in the frequency domain and has 36890 Hermite symmetry in the time domain. So here it's `hfft` for which 36891 you must supply the length of the result if it is to be odd: 36892 ``ihfft(hfft(a), len(a)) == a``, within numerical accuracy. 36893 36894 Examples 36895 -------- 36896 >>> signal = np.array([[1, 1.j], [-1.j, 2]]) 36897 >>> np.conj(signal.T) - signal # check Hermitian symmetry 36898 array([[ 0.-0.j, 0.+0.j], 36899 [ 0.+0.j, 0.-0.j]]) 36900 >>> freq_spectrum = np.fft.hfft(signal) 36901 >>> freq_spectrum 36902 array([[ 1., 1.], 36903 [ 2., -2.]]) 36904 36905 """ 36906 return ndarray() 36907 def ifft(self, a=-1, n=None, axis=-1): 36908 """ 36909 Compute the one-dimensional inverse discrete Fourier Transform. 36910 36911 This function computes the inverse of the one-dimensional *n*-point 36912 discrete Fourier transform computed by `fft`. In other words, 36913 ``ifft(fft(a)) == a`` to within numerical accuracy. 36914 For a general description of the algorithm and definitions, 36915 see `numpy.fft`. 36916 36917 The input should be ordered in the same way as is returned by `fft`, 36918 i.e., ``a[0]`` should contain the zero frequency term, 36919 ``a[1:n/2+1]`` should contain the positive-frequency terms, and 36920 ``a[n/2+1:]`` should contain the negative-frequency terms, in order of 36921 decreasingly negative frequency. See `numpy.fft` for details. 36922 36923 Parameters 36924 ---------- 36925 a : array_like 36926 Input array, can be complex. 36927 n : int, optional 36928 Length of the transformed axis of the output. 36929 If `n` is smaller than the length of the input, the input is cropped. 36930 If it is larger, the input is padded with zeros. If `n` is not given, 36931 the length of the input (along the axis specified by `axis`) is used. 36932 See notes about padding issues. 36933 axis : int, optional 36934 Axis over which to compute the inverse DFT. If not given, the last 36935 axis is used. 36936 36937 Returns 36938 ------- 36939 out : complex ndarray 36940 The truncated or zero-padded input, transformed along the axis 36941 indicated by `axis`, or the last one if `axis` is not specified. 36942 36943 Raises 36944 ------ 36945 IndexError 36946 If `axes` is larger than the last axis of `a`. 36947 36948 See Also 36949 -------- 36950 numpy.fft : An introduction, with definitions and general explanations. 36951 fft : The one-dimensional (forward) FFT, of which `ifft` is the inverse 36952 ifft2 : The two-dimensional inverse FFT. 36953 ifftn : The n-dimensional inverse FFT. 36954 36955 Notes 36956 ----- 36957 If the input parameter `n` is larger than the size of the input, the input 36958 is padded by appending zeros at the end. Even though this is the common 36959 approach, it might lead to surprising results. If a different padding is 36960 desired, it must be performed before calling `ifft`. 36961 36962 Examples 36963 -------- 36964 >>> np.fft.ifft([0, 4, 0, 0]) 36965 array([ 1.+0.j, 0.+1.j, -1.+0.j, 0.-1.j]) 36966 36967 Create and plot a band-limited signal with random phases: 36968 36969 >>> import matplotlib.pyplot as plt 36970 >>> t = np.arange(400) 36971 >>> n = np.zeros((400,), dtype=complex) 36972 >>> n[40:60] = np.exp(1j*np.random.uniform(0, 2*np.pi, (20,))) 36973 >>> s = np.fft.ifft(n) 36974 >>> plt.plot(t, s.real, 'b-', t, s.imag, 'r--') 36975 [<matplotlib.lines.Line2D object at 0x...>, <matplotlib.lines.Line2D object at 0x...>] 36976 >>> plt.legend(('real', 'imaginary')) 36977 <matplotlib.legend.Legend object at 0x...> 36978 >>> plt.show() 36979 36980 """ 36981 return complex() 36982 def ifft2(self, a="(-2, -1)", s=None, axes="(-2, -1)"): 36983 """ 36984 Compute the 2-dimensional inverse discrete Fourier Transform. 36985 36986 This function computes the inverse of the 2-dimensional discrete Fourier 36987 Transform over any number of axes in an M-dimensional array by means of 36988 the Fast Fourier Transform (FFT). In other words, ``ifft2(fft2(a)) == a`` 36989 to within numerical accuracy. By default, the inverse transform is 36990 computed over the last two axes of the input array. 36991 36992 The input, analogously to `ifft`, should be ordered in the same way as is 36993 returned by `fft2`, i.e. it should have the term for zero frequency 36994 in the low-order corner of the two axes, the positive frequency terms in 36995 the first half of these axes, the term for the Nyquist frequency in the 36996 middle of the axes and the negative frequency terms in the second half of 36997 both axes, in order of decreasingly negative frequency. 36998 36999 Parameters 37000 ---------- 37001 a : array_like 37002 Input array, can be complex. 37003 s : sequence of ints, optional 37004 Shape (length of each axis) of the output (``s[0]`` refers to axis 0, 37005 ``s[1]`` to axis 1, etc.). This corresponds to `n` for ``ifft(x, n)``. 37006 Along each axis, if the given shape is smaller than that of the input, 37007 the input is cropped. If it is larger, the input is padded with zeros. 37008 if `s` is not given, the shape of the input (along the axes specified 37009 by `axes`) is used. See notes for issue on `ifft` zero padding. 37010 axes : sequence of ints, optional 37011 Axes over which to compute the FFT. If not given, the last two 37012 axes are used. A repeated index in `axes` means the transform over 37013 that axis is performed multiple times. A one-element sequence means 37014 that a one-dimensional FFT is performed. 37015 37016 Returns 37017 ------- 37018 out : complex ndarray 37019 The truncated or zero-padded input, transformed along the axes 37020 indicated by `axes`, or the last two axes if `axes` is not given. 37021 37022 Raises 37023 ------ 37024 ValueError 37025 If `s` and `axes` have different length, or `axes` not given and 37026 ``len(s) != 2``. 37027 IndexError 37028 If an element of `axes` is larger than than the number of axes of `a`. 37029 37030 See Also 37031 -------- 37032 numpy.fft : Overall view of discrete Fourier transforms, with definitions 37033 and conventions used. 37034 fft2 : The forward 2-dimensional FFT, of which `ifft2` is the inverse. 37035 ifftn : The inverse of the *n*-dimensional FFT. 37036 fft : The one-dimensional FFT. 37037 ifft : The one-dimensional inverse FFT. 37038 37039 Notes 37040 ----- 37041 `ifft2` is just `ifftn` with a different default for `axes`. 37042 37043 See `ifftn` for details and a plotting example, and `numpy.fft` for 37044 definition and conventions used. 37045 37046 Zero-padding, analogously with `ifft`, is performed by appending zeros to 37047 the input along the specified dimension. Although this is the common 37048 approach, it might lead to surprising results. If another form of zero 37049 padding is desired, it must be performed before `ifft2` is called. 37050 37051 Examples 37052 -------- 37053 >>> a = 4 * np.eye(4) 37054 >>> np.fft.ifft2(a) 37055 array([[ 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], 37056 [ 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j], 37057 [ 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], 37058 [ 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]]) 37059 37060 """ 37061 return complex() 37062 def ifftn(self, a=None, s=None, axes=None): 37063 """ 37064 Compute the N-dimensional inverse discrete Fourier Transform. 37065 37066 This function computes the inverse of the N-dimensional discrete 37067 Fourier Transform over any number of axes in an M-dimensional array by 37068 means of the Fast Fourier Transform (FFT). In other words, 37069 ``ifftn(fftn(a)) == a`` to within numerical accuracy. 37070 For a description of the definitions and conventions used, see `numpy.fft`. 37071 37072 The input, analogously to `ifft`, should be ordered in the same way as is 37073 returned by `fftn`, i.e. it should have the term for zero frequency 37074 in all axes in the low-order corner, the positive frequency terms in the 37075 first half of all axes, the term for the Nyquist frequency in the middle 37076 of all axes and the negative frequency terms in the second half of all 37077 axes, in order of decreasingly negative frequency. 37078 37079 Parameters 37080 ---------- 37081 a : array_like 37082 Input array, can be complex. 37083 s : sequence of ints, optional 37084 Shape (length of each transformed axis) of the output 37085 (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.). 37086 This corresponds to ``n`` for ``ifft(x, n)``. 37087 Along any axis, if the given shape is smaller than that of the input, 37088 the input is cropped. If it is larger, the input is padded with zeros. 37089 if `s` is not given, the shape of the input (along the axes specified 37090 by `axes`) is used. See notes for issue on `ifft` zero padding. 37091 axes : sequence of ints, optional 37092 Axes over which to compute the IFFT. If not given, the last ``len(s)`` 37093 axes are used, or all axes if `s` is also not specified. 37094 Repeated indices in `axes` means that the inverse transform over that 37095 axis is performed multiple times. 37096 37097 Returns 37098 ------- 37099 out : complex ndarray 37100 The truncated or zero-padded input, transformed along the axes 37101 indicated by `axes`, or by a combination of `s` or `a`, 37102 as explained in the parameters section above. 37103 37104 Raises 37105 ------ 37106 ValueError 37107 If `s` and `axes` have different length. 37108 IndexError 37109 If an element of `axes` is larger than than the number of axes of `a`. 37110 37111 See Also 37112 -------- 37113 numpy.fft : Overall view of discrete Fourier transforms, with definitions 37114 and conventions used. 37115 fftn : The forward *n*-dimensional FFT, of which `ifftn` is the inverse. 37116 ifft : The one-dimensional inverse FFT. 37117 ifft2 : The two-dimensional inverse FFT. 37118 ifftshift : Undoes `fftshift`, shifts zero-frequency terms to beginning 37119 of array. 37120 37121 Notes 37122 ----- 37123 See `numpy.fft` for definitions and conventions used. 37124 37125 Zero-padding, analogously with `ifft`, is performed by appending zeros to 37126 the input along the specified dimension. Although this is the common 37127 approach, it might lead to surprising results. If another form of zero 37128 padding is desired, it must be performed before `ifftn` is called. 37129 37130 Examples 37131 -------- 37132 >>> a = np.eye(4) 37133 >>> np.fft.ifftn(np.fft.fftn(a, axes=(0,)), axes=(1,)) 37134 array([[ 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], 37135 [ 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], 37136 [ 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], 37137 [ 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]]) 37138 37139 37140 Create and plot an image with band-limited frequency content: 37141 37142 >>> import matplotlib.pyplot as plt 37143 >>> n = np.zeros((200,200), dtype=complex) 37144 >>> n[60:80, 20:40] = np.exp(1j*np.random.uniform(0, 2*np.pi, (20, 20))) 37145 >>> im = np.fft.ifftn(n).real 37146 >>> plt.imshow(im) 37147 <matplotlib.image.AxesImage object at 0x...> 37148 >>> plt.show() 37149 37150 """ 37151 return complex() 37152 def ifftshift(self, x=None, axes=None): 37153 """ 37154 The inverse of fftshift. 37155 37156 Parameters 37157 ---------- 37158 x : array_like 37159 Input array. 37160 axes : int or shape tuple, optional 37161 Axes over which to calculate. Defaults to None, which shifts all axes. 37162 37163 Returns 37164 ------- 37165 y : ndarray 37166 The shifted array. 37167 37168 See Also 37169 -------- 37170 fftshift : Shift zero-frequency component to the center of the spectrum. 37171 37172 Examples 37173 -------- 37174 >>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3) 37175 >>> freqs 37176 array([[ 0., 1., 2.], 37177 [ 3., 4., -4.], 37178 [-3., -2., -1.]]) 37179 >>> np.fft.ifftshift(np.fft.fftshift(freqs)) 37180 array([[ 0., 1., 2.], 37181 [ 3., 4., -4.], 37182 [-3., -2., -1.]]) 37183 37184 """ 37185 return ndarray() 37186 def ihfft(self, a=-1, n=None, axis=-1): 37187 """ 37188 Compute the inverse FFT of a signal whose spectrum has Hermitian symmetry. 37189 37190 Parameters 37191 ---------- 37192 a : array_like 37193 Input array. 37194 n : int, optional 37195 Length of the inverse FFT. 37196 axis : int, optional 37197 Axis over which to compute the inverse FFT, assuming Hermitian 37198 symmetry of the spectrum. Default is the last axis. 37199 37200 Returns 37201 ------- 37202 out : ndarray 37203 The transformed input. 37204 37205 See also 37206 -------- 37207 hfft, irfft 37208 37209 Notes 37210 ----- 37211 `hfft`/`ihfft` are a pair analogous to `rfft`/`irfft`, but for the 37212 opposite case: here the signal is real in the frequency domain and has 37213 Hermite symmetry in the time domain. So here it's `hfft` for which 37214 you must supply the length of the result if it is to be odd: 37215 ``ihfft(hfft(a), len(a)) == a``, within numerical accuracy. 37216 37217 """ 37218 return ndarray() 37219 def irfft(self, a=-1, n=None, axis=-1): 37220 """ 37221 Compute the inverse of the n-point DFT for real input. 37222 37223 This function computes the inverse of the one-dimensional *n*-point 37224 discrete Fourier Transform of real input computed by `rfft`. 37225 In other words, ``irfft(rfft(a), len(a)) == a`` to within numerical 37226 accuracy. (See Notes below for why ``len(a)`` is necessary here.) 37227 37228 The input is expected to be in the form returned by `rfft`, i.e. the 37229 real zero-frequency term followed by the complex positive frequency terms 37230 in order of increasing frequency. Since the discrete Fourier Transform of 37231 real input is Hermite-symmetric, the negative frequency terms are taken 37232 to be the complex conjugates of the corresponding positive frequency terms. 37233 37234 Parameters 37235 ---------- 37236 a : array_like 37237 The input array. 37238 n : int, optional 37239 Length of the transformed axis of the output. 37240 For `n` output points, ``n//2+1`` input points are necessary. If the 37241 input is longer than this, it is cropped. If it is shorter than this, 37242 it is padded with zeros. If `n` is not given, it is determined from 37243 the length of the input (along the axis specified by `axis`). 37244 axis : int, optional 37245 Axis over which to compute the inverse FFT. 37246 37247 Returns 37248 ------- 37249 out : ndarray 37250 The truncated or zero-padded input, transformed along the axis 37251 indicated by `axis`, or the last one if `axis` is not specified. 37252 The length of the transformed axis is `n`, or, if `n` is not given, 37253 ``2*(m-1)`` where `m` is the length of the transformed axis of the 37254 input. To get an odd number of output points, `n` must be specified. 37255 37256 Raises 37257 ------ 37258 IndexError 37259 If `axis` is larger than the last axis of `a`. 37260 37261 See Also 37262 -------- 37263 numpy.fft : For definition of the DFT and conventions used. 37264 rfft : The one-dimensional FFT of real input, of which `irfft` is inverse. 37265 fft : The one-dimensional FFT. 37266 irfft2 : The inverse of the two-dimensional FFT of real input. 37267 irfftn : The inverse of the *n*-dimensional FFT of real input. 37268 37269 Notes 37270 ----- 37271 Returns the real valued `n`-point inverse discrete Fourier transform 37272 of `a`, where `a` contains the non-negative frequency terms of a 37273 Hermite-symmetric sequence. `n` is the length of the result, not the 37274 input. 37275 37276 If you specify an `n` such that `a` must be zero-padded or truncated, the 37277 extra/removed values will be added/removed at high frequencies. One can 37278 thus resample a series to `m` points via Fourier interpolation by: 37279 ``a_resamp = irfft(rfft(a), m)``. 37280 37281 37282 Examples 37283 -------- 37284 >>> np.fft.ifft([1, -1j, -1, 1j]) 37285 array([ 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]) 37286 >>> np.fft.irfft([1, -1j, -1]) 37287 array([ 0., 1., 0., 0.]) 37288 37289 Notice how the last term in the input to the ordinary `ifft` is the 37290 complex conjugate of the second term, and the output has zero imaginary 37291 part everywhere. When calling `irfft`, the negative frequencies are not 37292 specified, and the output array is purely real. 37293 37294 """ 37295 return ndarray() 37296 def irfft2(self, a="(-2, -1)", s=None, axes="(-2, -1)"): 37297 """ 37298 Compute the 2-dimensional inverse FFT of a real array. 37299 37300 Parameters 37301 ---------- 37302 a : array_like 37303 The input array 37304 s : sequence of ints, optional 37305 Shape of the inverse FFT. 37306 axes : sequence of ints, optional 37307 The axes over which to compute the inverse fft. 37308 Default is the last two axes. 37309 37310 Returns 37311 ------- 37312 out : ndarray 37313 The result of the inverse real 2-D FFT. 37314 37315 See Also 37316 -------- 37317 irfftn : Compute the inverse of the N-dimensional FFT of real input. 37318 37319 Notes 37320 ----- 37321 This is really `irfftn` with different defaults. 37322 For more details see `irfftn`. 37323 37324 """ 37325 return ndarray() 37326 def irfftn(self, a=None, s=None, axes=None): 37327 """ 37328 Compute the inverse of the N-dimensional FFT of real input. 37329 37330 This function computes the inverse of the N-dimensional discrete 37331 Fourier Transform for real input over any number of axes in an 37332 M-dimensional array by means of the Fast Fourier Transform (FFT). In 37333 other words, ``irfftn(rfftn(a), a.shape) == a`` to within numerical 37334 accuracy. (The ``a.shape`` is necessary like ``len(a)`` is for `irfft`, 37335 and for the same reason.) 37336 37337 The input should be ordered in the same way as is returned by `rfftn`, 37338 i.e. as for `irfft` for the final transformation axis, and as for `ifftn` 37339 along all the other axes. 37340 37341 Parameters 37342 ---------- 37343 a : array_like 37344 Input array. 37345 s : sequence of ints, optional 37346 Shape (length of each transformed axis) of the output 37347 (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.). `s` is also the 37348 number of input points used along this axis, except for the last axis, 37349 where ``s[-1]//2+1`` points of the input are used. 37350 Along any axis, if the shape indicated by `s` is smaller than that of 37351 the input, the input is cropped. If it is larger, the input is padded 37352 with zeros. If `s` is not given, the shape of the input (along the 37353 axes specified by `axes`) is used. 37354 axes : sequence of ints, optional 37355 Axes over which to compute the inverse FFT. If not given, the last 37356 `len(s)` axes are used, or all axes if `s` is also not specified. 37357 Repeated indices in `axes` means that the inverse transform over that 37358 axis is performed multiple times. 37359 37360 Returns 37361 ------- 37362 out : ndarray 37363 The truncated or zero-padded input, transformed along the axes 37364 indicated by `axes`, or by a combination of `s` or `a`, 37365 as explained in the parameters section above. 37366 The length of each transformed axis is as given by the corresponding 37367 element of `s`, or the length of the input in every axis except for the 37368 last one if `s` is not given. In the final transformed axis the length 37369 of the output when `s` is not given is ``2*(m-1)`` where `m` is the 37370 length of the final transformed axis of the input. To get an odd 37371 number of output points in the final axis, `s` must be specified. 37372 37373 Raises 37374 ------ 37375 ValueError 37376 If `s` and `axes` have different length. 37377 IndexError 37378 If an element of `axes` is larger than than the number of axes of `a`. 37379 37380 See Also 37381 -------- 37382 rfftn : The forward n-dimensional FFT of real input, 37383 of which `ifftn` is the inverse. 37384 fft : The one-dimensional FFT, with definitions and conventions used. 37385 irfft : The inverse of the one-dimensional FFT of real input. 37386 irfft2 : The inverse of the two-dimensional FFT of real input. 37387 37388 Notes 37389 ----- 37390 See `fft` for definitions and conventions used. 37391 37392 See `rfft` for definitions and conventions used for real input. 37393 37394 Examples 37395 -------- 37396 >>> a = np.zeros((3, 2, 2)) 37397 >>> a[0, 0, 0] = 3 * 2 * 2 37398 >>> np.fft.irfftn(a) 37399 array([[[ 1., 1.], 37400 [ 1., 1.]], 37401 [[ 1., 1.], 37402 [ 1., 1.]], 37403 [[ 1., 1.], 37404 [ 1., 1.]]]) 37405 37406 """ 37407 return ndarray() 37408 print_function = instance() 37409 def rfft(self, a=-1, n=None, axis=-1): 37410 """ 37411 Compute the one-dimensional discrete Fourier Transform for real input. 37412 37413 This function computes the one-dimensional *n*-point discrete Fourier 37414 Transform (DFT) of a real-valued array by means of an efficient algorithm 37415 called the Fast Fourier Transform (FFT). 37416 37417 Parameters 37418 ---------- 37419 a : array_like 37420 Input array 37421 n : int, optional 37422 Number of points along transformation axis in the input to use. 37423 If `n` is smaller than the length of the input, the input is cropped. 37424 If it is larger, the input is padded with zeros. If `n` is not given, 37425 the length of the input (along the axis specified by `axis`) is used. 37426 axis : int, optional 37427 Axis over which to compute the FFT. If not given, the last axis is 37428 used. 37429 37430 Returns 37431 ------- 37432 out : complex ndarray 37433 The truncated or zero-padded input, transformed along the axis 37434 indicated by `axis`, or the last one if `axis` is not specified. 37435 If `n` is even, the length of the transformed axis is ``(n/2)+1``. 37436 If `n` is odd, the length is ``(n+1)/2``. 37437 37438 Raises 37439 ------ 37440 IndexError 37441 If `axis` is larger than the last axis of `a`. 37442 37443 See Also 37444 -------- 37445 numpy.fft : For definition of the DFT and conventions used. 37446 irfft : The inverse of `rfft`. 37447 fft : The one-dimensional FFT of general (complex) input. 37448 fftn : The *n*-dimensional FFT. 37449 rfftn : The *n*-dimensional FFT of real input. 37450 37451 Notes 37452 ----- 37453 When the DFT is computed for purely real input, the output is 37454 Hermite-symmetric, i.e. the negative frequency terms are just the complex 37455 conjugates of the corresponding positive-frequency terms, and the 37456 negative-frequency terms are therefore redundant. This function does not 37457 compute the negative frequency terms, and the length of the transformed 37458 axis of the output is therefore ``n//2+1``. 37459 37460 When ``A = rfft(a)`` and fs is the sampling frequency, ``A[0]`` contains 37461 the zero-frequency term 0*fs, which is real due to Hermitian symmetry. 37462 37463 If `n` is even, ``A[-1]`` contains the term representing both positive 37464 and negative Nyquist frequency (+fs/2 and -fs/2), and must also be purely 37465 real. If `n` is odd, there is no term at fs/2; ``A[-1]`` contains 37466 the largest positive frequency (fs/2*(n-1)/n), and is complex in the 37467 general case. 37468 37469 If the input `a` contains an imaginary part, it is silently discarded. 37470 37471 Examples 37472 -------- 37473 >>> np.fft.fft([0, 1, 0, 0]) 37474 array([ 1.+0.j, 0.-1.j, -1.+0.j, 0.+1.j]) 37475 >>> np.fft.rfft([0, 1, 0, 0]) 37476 array([ 1.+0.j, 0.-1.j, -1.+0.j]) 37477 37478 Notice how the final element of the `fft` output is the complex conjugate 37479 of the second element, for real input. For `rfft`, this symmetry is 37480 exploited to compute only the non-negative frequency terms. 37481 37482 """ 37483 return complex() 37484 def rfft2(self, a="(-2, -1)", s=None, axes="(-2, -1)"): 37485 """ 37486 Compute the 2-dimensional FFT of a real array. 37487 37488 Parameters 37489 ---------- 37490 a : array 37491 Input array, taken to be real. 37492 s : sequence of ints, optional 37493 Shape of the FFT. 37494 axes : sequence of ints, optional 37495 Axes over which to compute the FFT. 37496 37497 Returns 37498 ------- 37499 out : ndarray 37500 The result of the real 2-D FFT. 37501 37502 See Also 37503 -------- 37504 rfftn : Compute the N-dimensional discrete Fourier Transform for real 37505 input. 37506 37507 Notes 37508 ----- 37509 This is really just `rfftn` with different default behavior. 37510 For more details see `rfftn`. 37511 37512 """ 37513 return ndarray() 37514 def rfftfreq(self, n=1.0, d=1.0): 37515 """ 37516 Return the Discrete Fourier Transform sample frequencies 37517 (for usage with rfft, irfft). 37518 37519 The returned float array `f` contains the frequency bin centers in cycles 37520 per unit of the sample spacing (with zero at the start). For instance, if 37521 the sample spacing is in seconds, then the frequency unit is cycles/second. 37522 37523 Given a window length `n` and a sample spacing `d`:: 37524 37525 f = [0, 1, ..., n/2-1, n/2] / (d*n) if n is even 37526 f = [0, 1, ..., (n-1)/2-1, (n-1)/2] / (d*n) if n is odd 37527 37528 Unlike `fftfreq` (but like `scipy.fftpack.rfftfreq`) 37529 the Nyquist frequency component is considered to be positive. 37530 37531 Parameters 37532 ---------- 37533 n : int 37534 Window length. 37535 d : scalar, optional 37536 Sample spacing (inverse of the sampling rate). Defaults to 1. 37537 37538 Returns 37539 ------- 37540 f : ndarray 37541 Array of length ``n//2 + 1`` containing the sample frequencies. 37542 37543 Examples 37544 -------- 37545 >>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5, -3, 4], dtype=float) 37546 >>> fourier = np.fft.rfft(signal) 37547 >>> n = signal.size 37548 >>> sample_rate = 100 37549 >>> freq = np.fft.fftfreq(n, d=1./sample_rate) 37550 >>> freq 37551 array([ 0., 10., 20., 30., 40., -50., -40., -30., -20., -10.]) 37552 >>> freq = np.fft.rfftfreq(n, d=1./sample_rate) 37553 >>> freq 37554 array([ 0., 10., 20., 30., 40., 50.]) 37555 37556 """ 37557 return ndarray() 37558 def rfftn(self, a=None, s=None, axes=None): 37559 """ 37560 Compute the N-dimensional discrete Fourier Transform for real input. 37561 37562 This function computes the N-dimensional discrete Fourier Transform over 37563 any number of axes in an M-dimensional real array by means of the Fast 37564 Fourier Transform (FFT). By default, all axes are transformed, with the 37565 real transform performed over the last axis, while the remaining 37566 transforms are complex. 37567 37568 Parameters 37569 ---------- 37570 a : array_like 37571 Input array, taken to be real. 37572 s : sequence of ints, optional 37573 Shape (length along each transformed axis) to use from the input. 37574 (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.). 37575 The final element of `s` corresponds to `n` for ``rfft(x, n)``, while 37576 for the remaining axes, it corresponds to `n` for ``fft(x, n)``. 37577 Along any axis, if the given shape is smaller than that of the input, 37578 the input is cropped. If it is larger, the input is padded with zeros. 37579 if `s` is not given, the shape of the input (along the axes specified 37580 by `axes`) is used. 37581 axes : sequence of ints, optional 37582 Axes over which to compute the FFT. If not given, the last ``len(s)`` 37583 axes are used, or all axes if `s` is also not specified. 37584 37585 Returns 37586 ------- 37587 out : complex ndarray 37588 The truncated or zero-padded input, transformed along the axes 37589 indicated by `axes`, or by a combination of `s` and `a`, 37590 as explained in the parameters section above. 37591 The length of the last axis transformed will be ``s[-1]//2+1``, 37592 while the remaining transformed axes will have lengths according to 37593 `s`, or unchanged from the input. 37594 37595 Raises 37596 ------ 37597 ValueError 37598 If `s` and `axes` have different length. 37599 IndexError 37600 If an element of `axes` is larger than than the number of axes of `a`. 37601 37602 See Also 37603 -------- 37604 irfftn : The inverse of `rfftn`, i.e. the inverse of the n-dimensional FFT 37605 of real input. 37606 fft : The one-dimensional FFT, with definitions and conventions used. 37607 rfft : The one-dimensional FFT of real input. 37608 fftn : The n-dimensional FFT. 37609 rfft2 : The two-dimensional FFT of real input. 37610 37611 Notes 37612 ----- 37613 The transform for real input is performed over the last transformation 37614 axis, as by `rfft`, then the transform over the remaining axes is 37615 performed as by `fftn`. The order of the output is as for `rfft` for the 37616 final transformation axis, and as for `fftn` for the remaining 37617 transformation axes. 37618 37619 See `fft` for details, definitions and conventions used. 37620 37621 Examples 37622 -------- 37623 >>> a = np.ones((2, 2, 2)) 37624 >>> np.fft.rfftn(a) 37625 array([[[ 8.+0.j, 0.+0.j], 37626 [ 0.+0.j, 0.+0.j]], 37627 [[ 0.+0.j, 0.+0.j], 37628 [ 0.+0.j, 0.+0.j]]]) 37629 37630 >>> np.fft.rfftn(a, axes=(2, 0)) 37631 array([[[ 4.+0.j, 0.+0.j], 37632 [ 4.+0.j, 0.+0.j]], 37633 [[ 0.+0.j, 0.+0.j], 37634 [ 0.+0.j, 0.+0.j]]]) 37635 37636 """ 37637 return complex() 37638 def test(self=None, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None): 37639 """ 37640 Run tests for module using nose. 37641 37642 Parameters 37643 ---------- 37644 label : {'fast', 'full', '', attribute identifier}, optional 37645 Identifies the tests to run. This can be a string to pass to 37646 the nosetests executable with the '-A' option, or one of several 37647 special values. Special values are: 37648 * 'fast' - the default - which corresponds to the ``nosetests -A`` 37649 option of 'not slow'. 37650 * 'full' - fast (as above) and slow tests as in the 37651 'no -A' option to nosetests - this is the same as ''. 37652 * None or '' - run all tests. 37653 attribute_identifier - string passed directly to nosetests as '-A'. 37654 verbose : int, optional 37655 Verbosity value for test outputs, in the range 1-10. Default is 1. 37656 extra_argv : list, optional 37657 List with any extra arguments to pass to nosetests. 37658 doctests : bool, optional 37659 If True, run doctests in module. Default is False. 37660 coverage : bool, optional 37661 If True, report coverage of NumPy code. Default is False. 37662 (This requires the `coverage module: 37663 <http://nedbatchelder.com/code/modules/coverage.html>`_). 37664 raise_warnings : str or sequence of warnings, optional 37665 This specifies which warnings to configure as 'raise' instead 37666 of 'warn' during the test execution. Valid strings are: 37667 37668 - "develop" : equals ``(DeprecationWarning, RuntimeWarning)`` 37669 - "release" : equals ``()``, don't raise on any warnings. 37670 37671 Returns 37672 ------- 37673 result : object 37674 Returns the result of running the tests as a 37675 ``nose.result.TextTestResult`` object. 37676 37677 Notes 37678 ----- 37679 Each NumPy module exposes `test` in its namespace to run all tests for it. 37680 For example, to run all tests for numpy.lib: 37681 37682 >>> np.lib.test() #doctest: +SKIP 37683 37684 Examples 37685 -------- 37686 >>> result = np.lib.test() #doctest: +SKIP 37687 Running unit tests for numpy.lib 37688 ... 37689 Ran 976 tests in 3.933s 37690 37691 OK 37692 37693 >>> result.errors #doctest: +SKIP 37694 [] 37695 >>> result.knownfail #doctest: +SKIP 37696 [] 37697 """ 37698 return object() 37699 class linalg: 37700 class LinAlgError: 37701 __dict__ = dictproxy() 37702 __doc__ = str() 37703 __module__ = str() 37704 __weakref__ = getset_descriptor() 37705 args = getset_descriptor() 37706 message = getset_descriptor() 37707 class NoseTester: 37708 __dict__ = dictproxy() 37709 __doc__ = str() 37710 __module__ = str() 37711 __weakref__ = getset_descriptor() 37712 def _get_custom_doctester(self, _): 37713 """ Return instantiated plugin for doctests 37714 37715 Allows subclassing of this class to override doctester 37716 37717 A return value of None means use the nose builtin doctest plugin 37718 """ 37719 return None 37720 def _show_system_info(self, _): 37721 """None""" 37722 return None 37723 def _test_argv(self, label, verbose, extra_argv): 37724 """ Generate argv for nosetest command 37725 37726 Parameters 37727 ---------- 37728 label : {'fast', 'full', '', attribute identifier}, optional 37729 see ``test`` docstring 37730 verbose : int, optional 37731 Verbosity value for test outputs, in the range 1-10. Default is 1. 37732 extra_argv : list, optional 37733 List with any extra arguments to pass to nosetests. 37734 37735 Returns 37736 ------- 37737 argv : list 37738 command line arguments that will be passed to nose 37739 """ 37740 return list() 37741 def bench(self=None, label="fast", verbose=1, extra_argv=None): 37742 """ 37743 Run benchmarks for module using nose. 37744 37745 Parameters 37746 ---------- 37747 label : {'fast', 'full', '', attribute identifier}, optional 37748 Identifies the benchmarks to run. This can be a string to pass to 37749 the nosetests executable with the '-A' option, or one of several 37750 special values. Special values are: 37751 * 'fast' - the default - which corresponds to the ``nosetests -A`` 37752 option of 'not slow'. 37753 * 'full' - fast (as above) and slow benchmarks as in the 37754 'no -A' option to nosetests - this is the same as ''. 37755 * None or '' - run all tests. 37756 attribute_identifier - string passed directly to nosetests as '-A'. 37757 verbose : int, optional 37758 Verbosity value for benchmark outputs, in the range 1-10. Default is 1. 37759 extra_argv : list, optional 37760 List with any extra arguments to pass to nosetests. 37761 37762 Returns 37763 ------- 37764 success : bool 37765 Returns True if running the benchmarks works, False if an error 37766 occurred. 37767 37768 Notes 37769 ----- 37770 Benchmarks are like tests, but have names starting with "bench" instead 37771 of "test", and can be found under the "benchmarks" sub-directory of the 37772 module. 37773 37774 Each NumPy module exposes `bench` in its namespace to run all benchmarks 37775 for it. 37776 37777 Examples 37778 -------- 37779 >>> success = np.lib.bench() #doctest: +SKIP 37780 Running benchmarks for numpy.lib 37781 ... 37782 using 562341 items: 37783 unique: 37784 0.11 37785 unique1d: 37786 0.11 37787 ratio: 1.0 37788 nUnique: 56230 == 56230 37789 ... 37790 OK 37791 37792 >>> success #doctest: +SKIP 37793 True 37794 37795 """ 37796 return bool() 37797 excludes = list() 37798 def prepare_test_args(self=False, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False): 37799 """ 37800 Run tests for module using nose. 37801 37802 This method does the heavy lifting for the `test` method. It takes all 37803 the same arguments, for details see `test`. 37804 37805 See Also 37806 -------- 37807 test 37808 37809 """ 37810 return None 37811 def test(self=None, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None): 37812 """ 37813 Run tests for module using nose. 37814 37815 Parameters 37816 ---------- 37817 label : {'fast', 'full', '', attribute identifier}, optional 37818 Identifies the tests to run. This can be a string to pass to 37819 the nosetests executable with the '-A' option, or one of several 37820 special values. Special values are: 37821 * 'fast' - the default - which corresponds to the ``nosetests -A`` 37822 option of 'not slow'. 37823 * 'full' - fast (as above) and slow tests as in the 37824 'no -A' option to nosetests - this is the same as ''. 37825 * None or '' - run all tests. 37826 attribute_identifier - string passed directly to nosetests as '-A'. 37827 verbose : int, optional 37828 Verbosity value for test outputs, in the range 1-10. Default is 1. 37829 extra_argv : list, optional 37830 List with any extra arguments to pass to nosetests. 37831 doctests : bool, optional 37832 If True, run doctests in module. Default is False. 37833 coverage : bool, optional 37834 If True, report coverage of NumPy code. Default is False. 37835 (This requires the `coverage module: 37836 <http://nedbatchelder.com/code/modules/coverage.html>`_). 37837 raise_warnings : str or sequence of warnings, optional 37838 This specifies which warnings to configure as 'raise' instead 37839 of 'warn' during the test execution. Valid strings are: 37840 37841 - "develop" : equals ``(DeprecationWarning, RuntimeWarning)`` 37842 - "release" : equals ``()``, don't raise on any warnings. 37843 37844 Returns 37845 ------- 37846 result : object 37847 Returns the result of running the tests as a 37848 ``nose.result.TextTestResult`` object. 37849 37850 Notes 37851 ----- 37852 Each NumPy module exposes `test` in its namespace to run all tests for it. 37853 For example, to run all tests for numpy.lib: 37854 37855 >>> np.lib.test() #doctest: +SKIP 37856 37857 Examples 37858 -------- 37859 >>> result = np.lib.test() #doctest: +SKIP 37860 Running unit tests for numpy.lib 37861 ... 37862 Ran 976 tests in 3.933s 37863 37864 OK 37865 37866 >>> result.errors #doctest: +SKIP 37867 [] 37868 >>> result.knownfail #doctest: +SKIP 37869 [] 37870 """ 37871 return object() 37872 __builtins__ = dict() 37873 __doc__ = str() 37874 __file__ = str() 37875 __name__ = str() 37876 __package__ = str() 37877 __path__ = list() 37878 absolute_import = instance() 37879 def test(self=None, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None): 37880 """ 37881 Run tests for module using nose. 37882 37883 Parameters 37884 ---------- 37885 label : {'fast', 'full', '', attribute identifier}, optional 37886 Identifies the tests to run. This can be a string to pass to 37887 the nosetests executable with the '-A' option, or one of several 37888 special values. Special values are: 37889 * 'fast' - the default - which corresponds to the ``nosetests -A`` 37890 option of 'not slow'. 37891 * 'full' - fast (as above) and slow tests as in the 37892 'no -A' option to nosetests - this is the same as ''. 37893 * None or '' - run all tests. 37894 attribute_identifier - string passed directly to nosetests as '-A'. 37895 verbose : int, optional 37896 Verbosity value for test outputs, in the range 1-10. Default is 1. 37897 extra_argv : list, optional 37898 List with any extra arguments to pass to nosetests. 37899 doctests : bool, optional 37900 If True, run doctests in module. Default is False. 37901 coverage : bool, optional 37902 If True, report coverage of NumPy code. Default is False. 37903 (This requires the `coverage module: 37904 <http://nedbatchelder.com/code/modules/coverage.html>`_). 37905 raise_warnings : str or sequence of warnings, optional 37906 This specifies which warnings to configure as 'raise' instead 37907 of 'warn' during the test execution. Valid strings are: 37908 37909 - "develop" : equals ``(DeprecationWarning, RuntimeWarning)`` 37910 - "release" : equals ``()``, don't raise on any warnings. 37911 37912 Returns 37913 ------- 37914 result : object 37915 Returns the result of running the tests as a 37916 ``nose.result.TextTestResult`` object. 37917 37918 Notes 37919 ----- 37920 Each NumPy module exposes `test` in its namespace to run all tests for it. 37921 For example, to run all tests for numpy.lib: 37922 37923 >>> np.lib.test() #doctest: +SKIP 37924 37925 Examples 37926 -------- 37927 >>> result = np.lib.test() #doctest: +SKIP 37928 Running unit tests for numpy.lib 37929 ... 37930 Ran 976 tests in 3.933s 37931 37932 OK 37933 37934 >>> result.errors #doctest: +SKIP 37935 [] 37936 >>> result.knownfail #doctest: +SKIP 37937 [] 37938 """ 37939 return object() 37940 def cholesky(self, a): 37941 """ 37942 Cholesky decomposition. 37943 37944 Return the Cholesky decomposition, `L * L.H`, of the square matrix `a`, 37945 where `L` is lower-triangular and .H is the conjugate transpose operator 37946 (which is the ordinary transpose if `a` is real-valued). `a` must be 37947 Hermitian (symmetric if real-valued) and positive-definite. Only `L` is 37948 actually returned. 37949 37950 Parameters 37951 ---------- 37952 a : (..., M, M) array_like 37953 Hermitian (symmetric if all elements are real), positive-definite 37954 input matrix. 37955 37956 Returns 37957 ------- 37958 L : (..., M, M) array_like 37959 Upper or lower-triangular Cholesky factor of `a`. Returns a 37960 matrix object if `a` is a matrix object. 37961 37962 Raises 37963 ------ 37964 LinAlgError 37965 If the decomposition fails, for example, if `a` is not 37966 positive-definite. 37967 37968 Notes 37969 ----- 37970 Broadcasting rules apply, see the `numpy.linalg` documentation for 37971 details. 37972 37973 The Cholesky decomposition is often used as a fast way of solving 37974 37975 .. math:: A \mathbf{x} = \mathbf{b} 37976 37977 (when `A` is both Hermitian/symmetric and positive-definite). 37978 37979 First, we solve for :math:`\mathbf{y}` in 37980 37981 .. math:: L \mathbf{y} = \mathbf{b}, 37982 37983 and then for :math:`\mathbf{x}` in 37984 37985 .. math:: L.H \mathbf{x} = \mathbf{y}. 37986 37987 Examples 37988 -------- 37989 >>> A = np.array([[1,-2j],[2j,5]]) 37990 >>> A 37991 array([[ 1.+0.j, 0.-2.j], 37992 [ 0.+2.j, 5.+0.j]]) 37993 >>> L = np.linalg.cholesky(A) 37994 >>> L 37995 array([[ 1.+0.j, 0.+0.j], 37996 [ 0.+2.j, 1.+0.j]]) 37997 >>> np.dot(L, L.T.conj()) # verify that L * L.H = A 37998 array([[ 1.+0.j, 0.-2.j], 37999 [ 0.+2.j, 5.+0.j]]) 38000 >>> A = [[1,-2j],[2j,5]] # what happens if A is only array_like? 38001 >>> np.linalg.cholesky(A) # an ndarray object is returned 38002 array([[ 1.+0.j, 0.+0.j], 38003 [ 0.+2.j, 1.+0.j]]) 38004 >>> # But a matrix object is returned if A is a matrix object 38005 >>> LA.cholesky(np.matrix(A)) 38006 matrix([[ 1.+0.j, 0.+0.j], 38007 [ 0.+2.j, 1.+0.j]]) 38008 38009 """ 38010 return more_args() 38011 def cond(self, x=None, p=None): 38012 """ 38013 Compute the condition number of a matrix. 38014 38015 This function is capable of returning the condition number using 38016 one of seven different norms, depending on the value of `p` (see 38017 Parameters below). 38018 38019 Parameters 38020 ---------- 38021 x : (M, N) array_like 38022 The matrix whose condition number is sought. 38023 p : {None, 1, -1, 2, -2, inf, -inf, 'fro'}, optional 38024 Order of the norm: 38025 38026 ===== ============================ 38027 p norm for matrices 38028 ===== ============================ 38029 None 2-norm, computed directly using the ``SVD`` 38030 'fro' Frobenius norm 38031 inf max(sum(abs(x), axis=1)) 38032 -inf min(sum(abs(x), axis=1)) 38033 1 max(sum(abs(x), axis=0)) 38034 -1 min(sum(abs(x), axis=0)) 38035 2 2-norm (largest sing. value) 38036 -2 smallest singular value 38037 ===== ============================ 38038 38039 inf means the numpy.inf object, and the Frobenius norm is 38040 the root-of-sum-of-squares norm. 38041 38042 Returns 38043 ------- 38044 c : {float, inf} 38045 The condition number of the matrix. May be infinite. 38046 38047 See Also 38048 -------- 38049 numpy.linalg.norm 38050 38051 Notes 38052 ----- 38053 The condition number of `x` is defined as the norm of `x` times the 38054 norm of the inverse of `x` [1]_; the norm can be the usual L2-norm 38055 (root-of-sum-of-squares) or one of a number of other matrix norms. 38056 38057 References 38058 ---------- 38059 .. [1] G. Strang, *Linear Algebra and Its Applications*, Orlando, FL, 38060 Academic Press, Inc., 1980, pg. 285. 38061 38062 Examples 38063 -------- 38064 >>> from numpy import linalg as LA 38065 >>> a = np.array([[1, 0, -1], [0, 1, 0], [1, 0, 1]]) 38066 >>> a 38067 array([[ 1, 0, -1], 38068 [ 0, 1, 0], 38069 [ 1, 0, 1]]) 38070 >>> LA.cond(a) 38071 1.4142135623730951 38072 >>> LA.cond(a, 'fro') 38073 3.1622776601683795 38074 >>> LA.cond(a, np.inf) 38075 2.0 38076 >>> LA.cond(a, -np.inf) 38077 1.0 38078 >>> LA.cond(a, 1) 38079 2.0 38080 >>> LA.cond(a, -1) 38081 1.0 38082 >>> LA.cond(a, 2) 38083 1.4142135623730951 38084 >>> LA.cond(a, -2) 38085 0.70710678118654746 38086 >>> min(LA.svd(a, compute_uv=0))*min(LA.svd(LA.inv(a), compute_uv=0)) 38087 0.70710678118654746 38088 38089 """ 38090 return None 38091 def det(self, a): 38092 """ 38093 Compute the determinant of an array. 38094 38095 Parameters 38096 ---------- 38097 a : (..., M, M) array_like 38098 Input array to compute determinants for. 38099 38100 Returns 38101 ------- 38102 det : (...) array_like 38103 Determinant of `a`. 38104 38105 See Also 38106 -------- 38107 slogdet : Another way to representing the determinant, more suitable 38108 for large matrices where underflow/overflow may occur. 38109 38110 Notes 38111 ----- 38112 Broadcasting rules apply, see the `numpy.linalg` documentation for 38113 details. 38114 38115 The determinant is computed via LU factorization using the LAPACK 38116 routine z/dgetrf. 38117 38118 Examples 38119 -------- 38120 The determinant of a 2-D array [[a, b], [c, d]] is ad - bc: 38121 38122 >>> a = np.array([[1, 2], [3, 4]]) 38123 >>> np.linalg.det(a) 38124 -2.0 38125 38126 Computing determinants for a stack of matrices: 38127 38128 >>> a = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]] ]) 38129 >>> a.shape 38130 (2, 2, 2 38131 >>> np.linalg.det(a) 38132 array([-2., -3., -8.]) 38133 38134 """ 38135 return more_args() 38136 division = instance() 38137 def eig(self, a): 38138 """ 38139 Compute the eigenvalues and right eigenvectors of a square array. 38140 38141 Parameters 38142 ---------- 38143 a : (..., M, M) array 38144 Matrices for which the eigenvalues and right eigenvectors will 38145 be computed 38146 38147 Returns 38148 ------- 38149 w : (..., M) array 38150 The eigenvalues, each repeated according to its multiplicity. 38151 The eigenvalues are not necessarily ordered. The resulting 38152 array will be always be of complex type. When `a` is real 38153 the resulting eigenvalues will be real (0 imaginary part) or 38154 occur in conjugate pairs 38155 38156 v : (..., M, M) array 38157 The normalized (unit "length") eigenvectors, such that the 38158 column ``v[:,i]`` is the eigenvector corresponding to the 38159 eigenvalue ``w[i]``. 38160 38161 Raises 38162 ------ 38163 LinAlgError 38164 If the eigenvalue computation does not converge. 38165 38166 See Also 38167 -------- 38168 eigvalsh : eigenvalues of a symmetric or Hermitian (conjugate symmetric) 38169 array. 38170 38171 eigvals : eigenvalues of a non-symmetric array. 38172 38173 Notes 38174 ----- 38175 Broadcasting rules apply, see the `numpy.linalg` documentation for 38176 details. 38177 38178 This is implemented using the _geev LAPACK routines which compute 38179 the eigenvalues and eigenvectors of general square arrays. 38180 38181 The number `w` is an eigenvalue of `a` if there exists a vector 38182 `v` such that ``dot(a,v) = w * v``. Thus, the arrays `a`, `w`, and 38183 `v` satisfy the equations ``dot(a[:,:], v[:,i]) = w[i] * v[:,i]`` 38184 for :math:`i \in \{0,...,M-1\}`. 38185 38186 The array `v` of eigenvectors may not be of maximum rank, that is, some 38187 of the columns may be linearly dependent, although round-off error may 38188 obscure that fact. If the eigenvalues are all different, then theoretically 38189 the eigenvectors are linearly independent. Likewise, the (complex-valued) 38190 matrix of eigenvectors `v` is unitary if the matrix `a` is normal, i.e., 38191 if ``dot(a, a.H) = dot(a.H, a)``, where `a.H` denotes the conjugate 38192 transpose of `a`. 38193 38194 Finally, it is emphasized that `v` consists of the *right* (as in 38195 right-hand side) eigenvectors of `a`. A vector `y` satisfying 38196 ``dot(y.T, a) = z * y.T`` for some number `z` is called a *left* 38197 eigenvector of `a`, and, in general, the left and right eigenvectors 38198 of a matrix are not necessarily the (perhaps conjugate) transposes 38199 of each other. 38200 38201 References 38202 ---------- 38203 G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, FL, 38204 Academic Press, Inc., 1980, Various pp. 38205 38206 Examples 38207 -------- 38208 >>> from numpy import linalg as LA 38209 38210 (Almost) trivial example with real e-values and e-vectors. 38211 38212 >>> w, v = LA.eig(np.diag((1, 2, 3))) 38213 >>> w; v 38214 array([ 1., 2., 3.]) 38215 array([[ 1., 0., 0.], 38216 [ 0., 1., 0.], 38217 [ 0., 0., 1.]]) 38218 38219 Real matrix possessing complex e-values and e-vectors; note that the 38220 e-values are complex conjugates of each other. 38221 38222 >>> w, v = LA.eig(np.array([[1, -1], [1, 1]])) 38223 >>> w; v 38224 array([ 1. + 1.j, 1. - 1.j]) 38225 array([[ 0.70710678+0.j , 0.70710678+0.j ], 38226 [ 0.00000000-0.70710678j, 0.00000000+0.70710678j]]) 38227 38228 Complex-valued matrix with real e-values (but complex-valued e-vectors); 38229 note that a.conj().T = a, i.e., a is Hermitian. 38230 38231 >>> a = np.array([[1, 1j], [-1j, 1]]) 38232 >>> w, v = LA.eig(a) 38233 >>> w; v 38234 array([ 2.00000000e+00+0.j, 5.98651912e-36+0.j]) # i.e., {2, 0} 38235 array([[ 0.00000000+0.70710678j, 0.70710678+0.j ], 38236 [ 0.70710678+0.j , 0.00000000+0.70710678j]]) 38237 38238 Be careful about round-off error! 38239 38240 >>> a = np.array([[1 + 1e-9, 0], [0, 1 - 1e-9]]) 38241 >>> # Theor. e-values are 1 +/- 1e-9 38242 >>> w, v = LA.eig(a) 38243 >>> w; v 38244 array([ 1., 1.]) 38245 array([[ 1., 0.], 38246 [ 0., 1.]]) 38247 38248 """ 38249 return None 38250 def eigh(self, a="L", UPLO="L"): 38251 """ 38252 Return the eigenvalues and eigenvectors of a Hermitian or symmetric matrix. 38253 38254 Returns two objects, a 1-D array containing the eigenvalues of `a`, and 38255 a 2-D square array or matrix (depending on the input type) of the 38256 corresponding eigenvectors (in columns). 38257 38258 Parameters 38259 ---------- 38260 A : (..., M, M) array 38261 Hermitian/Symmetric matrices whose eigenvalues and 38262 eigenvectors are to be computed. 38263 UPLO : {'L', 'U'}, optional 38264 Specifies whether the calculation is done with the lower triangular 38265 part of `a` ('L', default) or the upper triangular part ('U'). 38266 38267 Returns 38268 ------- 38269 w : (..., M) ndarray 38270 The eigenvalues, not necessarily ordered. 38271 v : {(..., M, M) ndarray, (..., M, M) matrix} 38272 The column ``v[:, i]`` is the normalized eigenvector corresponding 38273 to the eigenvalue ``w[i]``. Will return a matrix object if `a` is 38274 a matrix object. 38275 38276 Raises 38277 ------ 38278 LinAlgError 38279 If the eigenvalue computation does not converge. 38280 38281 See Also 38282 -------- 38283 eigvalsh : eigenvalues of symmetric or Hermitian arrays. 38284 eig : eigenvalues and right eigenvectors for non-symmetric arrays. 38285 eigvals : eigenvalues of non-symmetric arrays. 38286 38287 Notes 38288 ----- 38289 Broadcasting rules apply, see the `numpy.linalg` documentation for 38290 details. 38291 38292 The eigenvalues/eigenvectors are computed using LAPACK routines _ssyevd, 38293 _heevd 38294 38295 The eigenvalues of real symmetric or complex Hermitian matrices are 38296 always real. [1]_ The array `v` of (column) eigenvectors is unitary 38297 and `a`, `w`, and `v` satisfy the equations 38298 ``dot(a, v[:, i]) = w[i] * v[:, i]``. 38299 38300 References 38301 ---------- 38302 .. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, 38303 FL, Academic Press, Inc., 1980, pg. 222. 38304 38305 Examples 38306 -------- 38307 >>> from numpy import linalg as LA 38308 >>> a = np.array([[1, -2j], [2j, 5]]) 38309 >>> a 38310 array([[ 1.+0.j, 0.-2.j], 38311 [ 0.+2.j, 5.+0.j]]) 38312 >>> w, v = LA.eigh(a) 38313 >>> w; v 38314 array([ 0.17157288, 5.82842712]) 38315 array([[-0.92387953+0.j , -0.38268343+0.j ], 38316 [ 0.00000000+0.38268343j, 0.00000000-0.92387953j]]) 38317 38318 >>> np.dot(a, v[:, 0]) - w[0] * v[:, 0] # verify 1st e-val/vec pair 38319 array([2.77555756e-17 + 0.j, 0. + 1.38777878e-16j]) 38320 >>> np.dot(a, v[:, 1]) - w[1] * v[:, 1] # verify 2nd e-val/vec pair 38321 array([ 0.+0.j, 0.+0.j]) 38322 38323 >>> A = np.matrix(a) # what happens if input is a matrix object 38324 >>> A 38325 matrix([[ 1.+0.j, 0.-2.j], 38326 [ 0.+2.j, 5.+0.j]]) 38327 >>> w, v = LA.eigh(A) 38328 >>> w; v 38329 array([ 0.17157288, 5.82842712]) 38330 matrix([[-0.92387953+0.j , -0.38268343+0.j ], 38331 [ 0.00000000+0.38268343j, 0.00000000-0.92387953j]]) 38332 38333 """ 38334 return more_args() 38335 def eigvals(self, a): 38336 """ 38337 Compute the eigenvalues of a general matrix. 38338 38339 Main difference between `eigvals` and `eig`: the eigenvectors aren't 38340 returned. 38341 38342 Parameters 38343 ---------- 38344 a : (..., M, M) array_like 38345 A complex- or real-valued matrix whose eigenvalues will be computed. 38346 38347 Returns 38348 ------- 38349 w : (..., M,) ndarray 38350 The eigenvalues, each repeated according to its multiplicity. 38351 They are not necessarily ordered, nor are they necessarily 38352 real for real matrices. 38353 38354 Raises 38355 ------ 38356 LinAlgError 38357 If the eigenvalue computation does not converge. 38358 38359 See Also 38360 -------- 38361 eig : eigenvalues and right eigenvectors of general arrays 38362 eigvalsh : eigenvalues of symmetric or Hermitian arrays. 38363 eigh : eigenvalues and eigenvectors of symmetric/Hermitian arrays. 38364 38365 Notes 38366 ----- 38367 Broadcasting rules apply, see the `numpy.linalg` documentation for 38368 details. 38369 38370 This is implemented using the _geev LAPACK routines which compute 38371 the eigenvalues and eigenvectors of general square arrays. 38372 38373 Examples 38374 -------- 38375 Illustration, using the fact that the eigenvalues of a diagonal matrix 38376 are its diagonal elements, that multiplying a matrix on the left 38377 by an orthogonal matrix, `Q`, and on the right by `Q.T` (the transpose 38378 of `Q`), preserves the eigenvalues of the "middle" matrix. In other words, 38379 if `Q` is orthogonal, then ``Q * A * Q.T`` has the same eigenvalues as 38380 ``A``: 38381 38382 >>> from numpy import linalg as LA 38383 >>> x = np.random.random() 38384 >>> Q = np.array([[np.cos(x), -np.sin(x)], [np.sin(x), np.cos(x)]]) 38385 >>> LA.norm(Q[0, :]), LA.norm(Q[1, :]), np.dot(Q[0, :],Q[1, :]) 38386 (1.0, 1.0, 0.0) 38387 38388 Now multiply a diagonal matrix by Q on one side and by Q.T on the other: 38389 38390 >>> D = np.diag((-1,1)) 38391 >>> LA.eigvals(D) 38392 array([-1., 1.]) 38393 >>> A = np.dot(Q, D) 38394 >>> A = np.dot(A, Q.T) 38395 >>> LA.eigvals(A) 38396 array([ 1., -1.]) 38397 38398 """ 38399 return more_args() 38400 def eigvalsh(self, a="L", UPLO="L"): 38401 """ 38402 Compute the eigenvalues of a Hermitian or real symmetric matrix. 38403 38404 Main difference from eigh: the eigenvectors are not computed. 38405 38406 Parameters 38407 ---------- 38408 a : (..., M, M) array_like 38409 A complex- or real-valued matrix whose eigenvalues are to be 38410 computed. 38411 UPLO : {'L', 'U'}, optional 38412 Same as `lower`, with 'L' for lower and 'U' for upper triangular. 38413 Deprecated. 38414 38415 Returns 38416 ------- 38417 w : (..., M,) ndarray 38418 The eigenvalues, not necessarily ordered, each repeated according to 38419 its multiplicity. 38420 38421 Raises 38422 ------ 38423 LinAlgError 38424 If the eigenvalue computation does not converge. 38425 38426 See Also 38427 -------- 38428 eigh : eigenvalues and eigenvectors of symmetric/Hermitian arrays. 38429 eigvals : eigenvalues of general real or complex arrays. 38430 eig : eigenvalues and right eigenvectors of general real or complex 38431 arrays. 38432 38433 Notes 38434 ----- 38435 Broadcasting rules apply, see the `numpy.linalg` documentation for 38436 details. 38437 38438 The eigenvalues are computed using LAPACK routines _ssyevd, _heevd 38439 38440 Examples 38441 -------- 38442 >>> from numpy import linalg as LA 38443 >>> a = np.array([[1, -2j], [2j, 5]]) 38444 >>> LA.eigvalsh(a) 38445 array([ 0.17157288+0.j, 5.82842712+0.j]) 38446 38447 """ 38448 return more_args() 38449 def inv(self, a): 38450 """ 38451 Compute the (multiplicative) inverse of a matrix. 38452 38453 Given a square matrix `a`, return the matrix `ainv` satisfying 38454 ``dot(a, ainv) = dot(ainv, a) = eye(a.shape[0])``. 38455 38456 Parameters 38457 ---------- 38458 a : (..., M, M) array_like 38459 Matrix to be inverted. 38460 38461 Returns 38462 ------- 38463 ainv : (..., M, M) ndarray or matrix 38464 (Multiplicative) inverse of the matrix `a`. 38465 38466 Raises 38467 ------ 38468 LinAlgError 38469 If `a` is not square or inversion fails. 38470 38471 Notes 38472 ----- 38473 Broadcasting rules apply, see the `numpy.linalg` documentation for 38474 details. 38475 38476 Examples 38477 -------- 38478 >>> from numpy.linalg import inv 38479 >>> a = np.array([[1., 2.], [3., 4.]]) 38480 >>> ainv = inv(a) 38481 >>> np.allclose(np.dot(a, ainv), np.eye(2)) 38482 True 38483 >>> np.allclose(np.dot(ainv, a), np.eye(2)) 38484 True 38485 38486 If a is a matrix object, then the return value is a matrix as well: 38487 38488 >>> ainv = inv(np.matrix(a)) 38489 >>> ainv 38490 matrix([[-2. , 1. ], 38491 [ 1.5, -0.5]]) 38492 38493 Inverses of several matrices can be computed at once: 38494 38495 >>> a = np.array([[[1., 2.], [3., 4.]], [[1, 3], [3, 5]]]) 38496 >>> inv(a) 38497 array([[[-2. , 1. ], 38498 [ 1.5, -0.5]], 38499 [[-5. , 2. ], 38500 [ 3. , -1. ]]]) 38501 38502 """ 38503 return more_args() if False else matrix() 38504 def lstsq(self, a, b=-1, rcond=-1): 38505 """ 38506 Return the least-squares solution to a linear matrix equation. 38507 38508 Solves the equation `a x = b` by computing a vector `x` that 38509 minimizes the Euclidean 2-norm `|| b - a x ||^2`. The equation may 38510 be under-, well-, or over- determined (i.e., the number of 38511 linearly independent rows of `a` can be less than, equal to, or 38512 greater than its number of linearly independent columns). If `a` 38513 is square and of full rank, then `x` (but for round-off error) is 38514 the "exact" solution of the equation. 38515 38516 Parameters 38517 ---------- 38518 a : (M, N) array_like 38519 "Coefficient" matrix. 38520 b : {(M,), (M, K)} array_like 38521 Ordinate or "dependent variable" values. If `b` is two-dimensional, 38522 the least-squares solution is calculated for each of the `K` columns 38523 of `b`. 38524 rcond : float, optional 38525 Cut-off ratio for small singular values of `a`. 38526 Singular values are set to zero if they are smaller than `rcond` 38527 times the largest singular value of `a`. 38528 38529 Returns 38530 ------- 38531 x : {(N,), (N, K)} ndarray 38532 Least-squares solution. If `b` is two-dimensional, 38533 the solutions are in the `K` columns of `x`. 38534 residuals : {(), (1,), (K,)} ndarray 38535 Sums of residuals; squared Euclidean 2-norm for each column in 38536 ``b - a*x``. 38537 If the rank of `a` is < N or > M, this is an empty array. 38538 If `b` is 1-dimensional, this is a (1,) shape array. 38539 Otherwise the shape is (K,). 38540 rank : int 38541 Rank of matrix `a`. 38542 s : (min(M, N),) ndarray 38543 Singular values of `a`. 38544 38545 Raises 38546 ------ 38547 LinAlgError 38548 If computation does not converge. 38549 38550 Notes 38551 ----- 38552 If `b` is a matrix, then all array results are returned as matrices. 38553 38554 Examples 38555 -------- 38556 Fit a line, ``y = mx + c``, through some noisy data-points: 38557 38558 >>> x = np.array([0, 1, 2, 3]) 38559 >>> y = np.array([-1, 0.2, 0.9, 2.1]) 38560 38561 By examining the coefficients, we see that the line should have a 38562 gradient of roughly 1 and cut the y-axis at, more or less, -1. 38563 38564 We can rewrite the line equation as ``y = Ap``, where ``A = [[x 1]]`` 38565 and ``p = [[m], [c]]``. Now use `lstsq` to solve for `p`: 38566 38567 >>> A = np.vstack([x, np.ones(len(x))]).T 38568 >>> A 38569 array([[ 0., 1.], 38570 [ 1., 1.], 38571 [ 2., 1.], 38572 [ 3., 1.]]) 38573 38574 >>> m, c = np.linalg.lstsq(A, y)[0] 38575 >>> print m, c 38576 1.0 -0.95 38577 38578 Plot the data along with the fitted line: 38579 38580 >>> import matplotlib.pyplot as plt 38581 >>> plt.plot(x, y, 'o', label='Original data', markersize=10) 38582 >>> plt.plot(x, m*x + c, 'r', label='Fitted line') 38583 >>> plt.legend() 38584 >>> plt.show() 38585 38586 """ 38587 return N() 38588 def matrix_power(self, M, n): 38589 """ 38590 Raise a square matrix to the (integer) power `n`. 38591 38592 For positive integers `n`, the power is computed by repeated matrix 38593 squarings and matrix multiplications. If ``n == 0``, the identity matrix 38594 of the same shape as M is returned. If ``n < 0``, the inverse 38595 is computed and then raised to the ``abs(n)``. 38596 38597 Parameters 38598 ---------- 38599 M : ndarray or matrix object 38600 Matrix to be "powered." Must be square, i.e. ``M.shape == (m, m)``, 38601 with `m` a positive integer. 38602 n : int 38603 The exponent can be any integer or long integer, positive, 38604 negative, or zero. 38605 38606 Returns 38607 ------- 38608 M**n : ndarray or matrix object 38609 The return value is the same shape and type as `M`; 38610 if the exponent is positive or zero then the type of the 38611 elements is the same as those of `M`. If the exponent is 38612 negative the elements are floating-point. 38613 38614 Raises 38615 ------ 38616 LinAlgError 38617 If the matrix is not numerically invertible. 38618 38619 See Also 38620 -------- 38621 matrix 38622 Provides an equivalent function as the exponentiation operator 38623 (``**``, not ``^``). 38624 38625 Examples 38626 -------- 38627 >>> from numpy import linalg as LA 38628 >>> i = np.array([[0, 1], [-1, 0]]) # matrix equiv. of the imaginary unit 38629 >>> LA.matrix_power(i, 3) # should = -i 38630 array([[ 0, -1], 38631 [ 1, 0]]) 38632 >>> LA.matrix_power(np.matrix(i), 3) # matrix arg returns matrix 38633 matrix([[ 0, -1], 38634 [ 1, 0]]) 38635 >>> LA.matrix_power(i, 0) 38636 array([[1, 0], 38637 [0, 1]]) 38638 >>> LA.matrix_power(i, -3) # should = 1/(-i) = i, but w/ f.p. elements 38639 array([[ 0., 1.], 38640 [-1., 0.]]) 38641 38642 Somewhat more sophisticated example 38643 38644 >>> q = np.zeros((4, 4)) 38645 >>> q[0:2, 0:2] = -i 38646 >>> q[2:4, 2:4] = i 38647 >>> q # one of the three quarternion units not equal to 1 38648 array([[ 0., -1., 0., 0.], 38649 [ 1., 0., 0., 0.], 38650 [ 0., 0., 0., 1.], 38651 [ 0., 0., -1., 0.]]) 38652 >>> LA.matrix_power(q, 2) # = -np.eye(4) 38653 array([[-1., 0., 0., 0.], 38654 [ 0., -1., 0., 0.], 38655 [ 0., 0., -1., 0.], 38656 [ 0., 0., 0., -1.]]) 38657 38658 """ 38659 return ndarray() if False else matrix() 38660 def matrix_rank(self, M=None, tol=None): 38661 """ 38662 Return matrix rank of array using SVD method 38663 38664 Rank of the array is the number of SVD singular values of the array that are 38665 greater than `tol`. 38666 38667 Parameters 38668 ---------- 38669 M : {(M,), (M, N)} array_like 38670 array of <=2 dimensions 38671 tol : {None, float}, optional 38672 threshold below which SVD values are considered zero. If `tol` is 38673 None, and ``S`` is an array with singular values for `M`, and 38674 ``eps`` is the epsilon value for datatype of ``S``, then `tol` is 38675 set to ``S.max() * max(M.shape) * eps``. 38676 38677 Notes 38678 ----- 38679 The default threshold to detect rank deficiency is a test on the magnitude 38680 of the singular values of `M`. By default, we identify singular values less 38681 than ``S.max() * max(M.shape) * eps`` as indicating rank deficiency (with 38682 the symbols defined above). This is the algorithm MATLAB uses [1]. It also 38683 appears in *Numerical recipes* in the discussion of SVD solutions for linear 38684 least squares [2]. 38685 38686 This default threshold is designed to detect rank deficiency accounting for 38687 the numerical errors of the SVD computation. Imagine that there is a column 38688 in `M` that is an exact (in floating point) linear combination of other 38689 columns in `M`. Computing the SVD on `M` will not produce a singular value 38690 exactly equal to 0 in general: any difference of the smallest SVD value from 38691 0 will be caused by numerical imprecision in the calculation of the SVD. 38692 Our threshold for small SVD values takes this numerical imprecision into 38693 account, and the default threshold will detect such numerical rank 38694 deficiency. The threshold may declare a matrix `M` rank deficient even if 38695 the linear combination of some columns of `M` is not exactly equal to 38696 another column of `M` but only numerically very close to another column of 38697 `M`. 38698 38699 We chose our default threshold because it is in wide use. Other thresholds 38700 are possible. For example, elsewhere in the 2007 edition of *Numerical 38701 recipes* there is an alternative threshold of ``S.max() * 38702 np.finfo(M.dtype).eps / 2. * np.sqrt(m + n + 1.)``. The authors describe 38703 this threshold as being based on "expected roundoff error" (p 71). 38704 38705 The thresholds above deal with floating point roundoff error in the 38706 calculation of the SVD. However, you may have more information about the 38707 sources of error in `M` that would make you consider other tolerance values 38708 to detect *effective* rank deficiency. The most useful measure of the 38709 tolerance depends on the operations you intend to use on your matrix. For 38710 example, if your data come from uncertain measurements with uncertainties 38711 greater than floating point epsilon, choosing a tolerance near that 38712 uncertainty may be preferable. The tolerance may be absolute if the 38713 uncertainties are absolute rather than relative. 38714 38715 References 38716 ---------- 38717 .. [1] MATLAB reference documention, "Rank" 38718 http://www.mathworks.com/help/techdoc/ref/rank.html 38719 .. [2] W. H. Press, S. A. Teukolsky, W. T. Vetterling and B. P. Flannery, 38720 "Numerical Recipes (3rd edition)", Cambridge University Press, 2007, 38721 page 795. 38722 38723 Examples 38724 -------- 38725 >>> from numpy.linalg import matrix_rank 38726 >>> matrix_rank(np.eye(4)) # Full rank matrix 38727 4 38728 >>> I=np.eye(4); I[-1,-1] = 0. # rank deficient matrix 38729 >>> matrix_rank(I) 38730 3 38731 >>> matrix_rank(np.ones((4,))) # 1 dimension - rank 1 unless all 0 38732 1 38733 >>> matrix_rank(np.zeros((4,))) 38734 0 38735 """ 38736 return None 38737 def norm(self, x=None, ord=None, axis=None): 38738 """ 38739 Matrix or vector norm. 38740 38741 This function is able to return one of seven different matrix norms, 38742 or one of an infinite number of vector norms (described below), depending 38743 on the value of the ``ord`` parameter. 38744 38745 Parameters 38746 ---------- 38747 x : array_like 38748 Input array. If `axis` is None, `x` must be 1-D or 2-D. 38749 ord : {non-zero int, inf, -inf, 'fro'}, optional 38750 Order of the norm (see table under ``Notes``). inf means numpy's 38751 `inf` object. 38752 axis : {int, 2-tuple of ints, None}, optional 38753 If `axis` is an integer, it specifies the axis of `x` along which to 38754 compute the vector norms. If `axis` is a 2-tuple, it specifies the 38755 axes that hold 2-D matrices, and the matrix norms of these matrices 38756 are computed. If `axis` is None then either a vector norm (when `x` 38757 is 1-D) or a matrix norm (when `x` is 2-D) is returned. 38758 38759 Returns 38760 ------- 38761 n : float or ndarray 38762 Norm of the matrix or vector(s). 38763 38764 Notes 38765 ----- 38766 For values of ``ord <= 0``, the result is, strictly speaking, not a 38767 mathematical 'norm', but it may still be useful for various numerical 38768 purposes. 38769 38770 The following norms can be calculated: 38771 38772 ===== ============================ ========================== 38773 ord norm for matrices norm for vectors 38774 ===== ============================ ========================== 38775 None Frobenius norm 2-norm 38776 'fro' Frobenius norm -- 38777 inf max(sum(abs(x), axis=1)) max(abs(x)) 38778 -inf min(sum(abs(x), axis=1)) min(abs(x)) 38779 0 -- sum(x != 0) 38780 1 max(sum(abs(x), axis=0)) as below 38781 -1 min(sum(abs(x), axis=0)) as below 38782 2 2-norm (largest sing. value) as below 38783 -2 smallest singular value as below 38784 other -- sum(abs(x)**ord)**(1./ord) 38785 ===== ============================ ========================== 38786 38787 The Frobenius norm is given by [1]_: 38788 38789 :math:`||A||_F = [\sum_{i,j} abs(a_{i,j})^2]^{1/2}` 38790 38791 References 38792 ---------- 38793 .. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*, 38794 Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15 38795 38796 Examples 38797 -------- 38798 >>> from numpy import linalg as LA 38799 >>> a = np.arange(9) - 4 38800 >>> a 38801 array([-4, -3, -2, -1, 0, 1, 2, 3, 4]) 38802 >>> b = a.reshape((3, 3)) 38803 >>> b 38804 array([[-4, -3, -2], 38805 [-1, 0, 1], 38806 [ 2, 3, 4]]) 38807 38808 >>> LA.norm(a) 38809 7.745966692414834 38810 >>> LA.norm(b) 38811 7.745966692414834 38812 >>> LA.norm(b, 'fro') 38813 7.745966692414834 38814 >>> LA.norm(a, np.inf) 38815 4 38816 >>> LA.norm(b, np.inf) 38817 9 38818 >>> LA.norm(a, -np.inf) 38819 0 38820 >>> LA.norm(b, -np.inf) 38821 2 38822 38823 >>> LA.norm(a, 1) 38824 20 38825 >>> LA.norm(b, 1) 38826 7 38827 >>> LA.norm(a, -1) 38828 -4.6566128774142013e-010 38829 >>> LA.norm(b, -1) 38830 6 38831 >>> LA.norm(a, 2) 38832 7.745966692414834 38833 >>> LA.norm(b, 2) 38834 7.3484692283495345 38835 38836 >>> LA.norm(a, -2) 38837 nan 38838 >>> LA.norm(b, -2) 38839 1.8570331885190563e-016 38840 >>> LA.norm(a, 3) 38841 5.8480354764257312 38842 >>> LA.norm(a, -3) 38843 nan 38844 38845 Using the `axis` argument to compute vector norms: 38846 38847 >>> c = np.array([[ 1, 2, 3], 38848 ... [-1, 1, 4]]) 38849 >>> LA.norm(c, axis=0) 38850 array([ 1.41421356, 2.23606798, 5. ]) 38851 >>> LA.norm(c, axis=1) 38852 array([ 3.74165739, 4.24264069]) 38853 >>> LA.norm(c, ord=1, axis=1) 38854 array([6, 6]) 38855 38856 Using the `axis` argument to compute matrix norms: 38857 38858 >>> m = np.arange(8).reshape(2,2,2) 38859 >>> LA.norm(m, axis=(1,2)) 38860 array([ 3.74165739, 11.22497216]) 38861 >>> LA.norm(m[0, :, :]), LA.norm(m[1, :, :]) 38862 (3.7416573867739413, 11.224972160321824) 38863 38864 """ 38865 return float() if False else ndarray() 38866 def pinv(self, a=1e-15, rcond=1e-15): 38867 """ 38868 Compute the (Moore-Penrose) pseudo-inverse of a matrix. 38869 38870 Calculate the generalized inverse of a matrix using its 38871 singular-value decomposition (SVD) and including all 38872 *large* singular values. 38873 38874 Parameters 38875 ---------- 38876 a : (M, N) array_like 38877 Matrix to be pseudo-inverted. 38878 rcond : float 38879 Cutoff for small singular values. 38880 Singular values smaller (in modulus) than 38881 `rcond` * largest_singular_value (again, in modulus) 38882 are set to zero. 38883 38884 Returns 38885 ------- 38886 B : (N, M) ndarray 38887 The pseudo-inverse of `a`. If `a` is a `matrix` instance, then so 38888 is `B`. 38889 38890 Raises 38891 ------ 38892 LinAlgError 38893 If the SVD computation does not converge. 38894 38895 Notes 38896 ----- 38897 The pseudo-inverse of a matrix A, denoted :math:`A^+`, is 38898 defined as: "the matrix that 'solves' [the least-squares problem] 38899 :math:`Ax = b`," i.e., if :math:`\bar{x}` is said solution, then 38900 :math:`A^+` is that matrix such that :math:`\bar{x} = A^+b`. 38901 38902 It can be shown that if :math:`Q_1 \Sigma Q_2^T = A` is the singular 38903 value decomposition of A, then 38904 :math:`A^+ = Q_2 \Sigma^+ Q_1^T`, where :math:`Q_{1,2}` are 38905 orthogonal matrices, :math:`\Sigma` is a diagonal matrix consisting 38906 of A's so-called singular values, (followed, typically, by 38907 zeros), and then :math:`\Sigma^+` is simply the diagonal matrix 38908 consisting of the reciprocals of A's singular values 38909 (again, followed by zeros). [1]_ 38910 38911 References 38912 ---------- 38913 .. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, 38914 FL, Academic Press, Inc., 1980, pp. 139-142. 38915 38916 Examples 38917 -------- 38918 The following example checks that ``a * a+ * a == a`` and 38919 ``a+ * a * a+ == a+``: 38920 38921 >>> a = np.random.randn(9, 6) 38922 >>> B = np.linalg.pinv(a) 38923 >>> np.allclose(a, np.dot(a, np.dot(B, a))) 38924 True 38925 >>> np.allclose(B, np.dot(B, np.dot(a, B))) 38926 True 38927 38928 """ 38929 return N() 38930 print_function = instance() 38931 def qr(self, a="reduced", mode="reduced"): 38932 """ 38933 Compute the qr factorization of a matrix. 38934 38935 Factor the matrix `a` as *qr*, where `q` is orthonormal and `r` is 38936 upper-triangular. 38937 38938 Parameters 38939 ---------- 38940 a : array_like, shape (M, N) 38941 Matrix to be factored. 38942 mode : {'reduced', 'complete', 'r', 'raw', 'full', 'economic'}, optional 38943 If K = min(M, N), then 38944 38945 'reduced' : returns q, r with dimensions (M, K), (K, N) (default) 38946 'complete' : returns q, r with dimensions (M, M), (M, N) 38947 'r' : returns r only with dimensions (K, N) 38948 'raw' : returns h, tau with dimensions (N, M), (K,) 38949 'full' : alias of 'reduced', deprecated 38950 'economic' : returns h from 'raw', deprecated. 38951 38952 The options 'reduced', 'complete, and 'raw' are new in numpy 1.8, 38953 see the notes for more information. The default is 'reduced' and to 38954 maintain backward compatibility with earlier versions of numpy both 38955 it and the old default 'full' can be omitted. Note that array h 38956 returned in 'raw' mode is transposed for calling Fortran. The 38957 'economic' mode is deprecated. The modes 'full' and 'economic' may 38958 be passed using only the first letter for backwards compatibility, 38959 but all others must be spelled out. See the Notes for more 38960 explanation. 38961 38962 38963 Returns 38964 ------- 38965 q : ndarray of float or complex, optional 38966 A matrix with orthonormal columns. When mode = 'complete' the 38967 result is an orthogonal/unitary matrix depending on whether or not 38968 a is real/complex. The determinant may be either +/- 1 in that 38969 case. 38970 r : ndarray of float or complex, optional 38971 The upper-triangular matrix. 38972 (h, tau) : ndarrays of np.double or np.cdouble, optional 38973 The array h contains the Householder reflectors that generate q 38974 along with r. The tau array contains scaling factors for the 38975 reflectors. In the deprecated 'economic' mode only h is returned. 38976 38977 Raises 38978 ------ 38979 LinAlgError 38980 If factoring fails. 38981 38982 Notes 38983 ----- 38984 This is an interface to the LAPACK routines dgeqrf, zgeqrf, 38985 dorgqr, and zungqr. 38986 38987 For more information on the qr factorization, see for example: 38988 http://en.wikipedia.org/wiki/QR_factorization 38989 38990 Subclasses of `ndarray` are preserved except for the 'raw' mode. So if 38991 `a` is of type `matrix`, all the return values will be matrices too. 38992 38993 New 'reduced', 'complete', and 'raw' options for mode were added in 38994 Numpy 1.8 and the old option 'full' was made an alias of 'reduced'. In 38995 addition the options 'full' and 'economic' were deprecated. Because 38996 'full' was the previous default and 'reduced' is the new default, 38997 backward compatibility can be maintained by letting `mode` default. 38998 The 'raw' option was added so that LAPACK routines that can multiply 38999 arrays by q using the Householder reflectors can be used. Note that in 39000 this case the returned arrays are of type np.double or np.cdouble and 39001 the h array is transposed to be FORTRAN compatible. No routines using 39002 the 'raw' return are currently exposed by numpy, but some are available 39003 in lapack_lite and just await the necessary work. 39004 39005 Examples 39006 -------- 39007 >>> a = np.random.randn(9, 6) 39008 >>> q, r = np.linalg.qr(a) 39009 >>> np.allclose(a, np.dot(q, r)) # a does equal qr 39010 True 39011 >>> r2 = np.linalg.qr(a, mode='r') 39012 >>> r3 = np.linalg.qr(a, mode='economic') 39013 >>> np.allclose(r, r2) # mode='r' returns the same r as mode='full' 39014 True 39015 >>> # But only triu parts are guaranteed equal when mode='economic' 39016 >>> np.allclose(r, np.triu(r3[:6,:6], k=0)) 39017 True 39018 39019 Example illustrating a common use of `qr`: solving of least squares 39020 problems 39021 39022 What are the least-squares-best `m` and `y0` in ``y = y0 + mx`` for 39023 the following data: {(0,1), (1,0), (1,2), (2,1)}. (Graph the points 39024 and you'll see that it should be y0 = 0, m = 1.) The answer is provided 39025 by solving the over-determined matrix equation ``Ax = b``, where:: 39026 39027 A = array([[0, 1], [1, 1], [1, 1], [2, 1]]) 39028 x = array([[y0], [m]]) 39029 b = array([[1], [0], [2], [1]]) 39030 39031 If A = qr such that q is orthonormal (which is always possible via 39032 Gram-Schmidt), then ``x = inv(r) * (q.T) * b``. (In numpy practice, 39033 however, we simply use `lstsq`.) 39034 39035 >>> A = np.array([[0, 1], [1, 1], [1, 1], [2, 1]]) 39036 >>> A 39037 array([[0, 1], 39038 [1, 1], 39039 [1, 1], 39040 [2, 1]]) 39041 >>> b = np.array([1, 0, 2, 1]) 39042 >>> q, r = LA.qr(A) 39043 >>> p = np.dot(q.T, b) 39044 >>> np.dot(LA.inv(r), p) 39045 array([ 1.1e-16, 1.0e+00]) 39046 39047 """ 39048 return ndarray() if False else complex() 39049 def slogdet(self, a): 39050 """ 39051 Compute the sign and (natural) logarithm of the determinant of an array. 39052 39053 If an array has a very small or very large determinant, than a call to 39054 `det` may overflow or underflow. This routine is more robust against such 39055 issues, because it computes the logarithm of the determinant rather than 39056 the determinant itself. 39057 39058 Parameters 39059 ---------- 39060 a : (..., M, M) array_like 39061 Input array, has to be a square 2-D array. 39062 39063 Returns 39064 ------- 39065 sign : (...) array_like 39066 A number representing the sign of the determinant. For a real matrix, 39067 this is 1, 0, or -1. For a complex matrix, this is a complex number 39068 with absolute value 1 (i.e., it is on the unit circle), or else 0. 39069 logdet : (...) array_like 39070 The natural log of the absolute value of the determinant. 39071 39072 If the determinant is zero, then `sign` will be 0 and `logdet` will be 39073 -Inf. In all cases, the determinant is equal to ``sign * np.exp(logdet)``. 39074 39075 See Also 39076 -------- 39077 det 39078 39079 Notes 39080 ----- 39081 Broadcasting rules apply, see the `numpy.linalg` documentation for 39082 details. 39083 39084 The determinant is computed via LU factorization using the LAPACK 39085 routine z/dgetrf. 39086 39087 .. versionadded:: 1.6.0. 39088 39089 Examples 39090 -------- 39091 The determinant of a 2-D array ``[[a, b], [c, d]]`` is ``ad - bc``: 39092 39093 >>> a = np.array([[1, 2], [3, 4]]) 39094 >>> (sign, logdet) = np.linalg.slogdet(a) 39095 >>> (sign, logdet) 39096 (-1, 0.69314718055994529) 39097 >>> sign * np.exp(logdet) 39098 -2.0 39099 39100 Computing log-determinants for a stack of matrices: 39101 39102 >>> a = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]] ]) 39103 >>> a.shape 39104 (3, 2, 2) 39105 >>> sign, logdet = np.linalg.slogdet(a) 39106 >>> (sign, logdet) 39107 (array([-1., -1., -1.]), array([ 0.69314718, 1.09861229, 2.07944154])) 39108 >>> sign * np.exp(logdet) 39109 array([-2., -3., -8.]) 39110 39111 This routine succeeds where ordinary `det` does not: 39112 39113 >>> np.linalg.det(np.eye(500) * 0.1) 39114 0.0 39115 >>> np.linalg.slogdet(np.eye(500) * 0.1) 39116 (1, -1151.2925464970228) 39117 39118 """ 39119 return more_args() 39120 def solve(self, a, b): 39121 """ 39122 Solve a linear matrix equation, or system of linear scalar equations. 39123 39124 Computes the "exact" solution, `x`, of the well-determined, i.e., full 39125 rank, linear matrix equation `ax = b`. 39126 39127 Parameters 39128 ---------- 39129 a : (..., M, M) array_like 39130 Coefficient matrix. 39131 b : {(..., M,), (..., M, K)}, array_like 39132 Ordinate or "dependent variable" values. 39133 39134 Returns 39135 ------- 39136 x : {(..., M,), (..., M, K)} ndarray 39137 Solution to the system a x = b. Returned shape is identical to `b`. 39138 39139 Raises 39140 ------ 39141 LinAlgError 39142 If `a` is singular or not square. 39143 39144 Notes 39145 ----- 39146 Broadcasting rules apply, see the `numpy.linalg` documentation for 39147 details. 39148 39149 The solutions are computed using LAPACK routine _gesv 39150 39151 `a` must be square and of full-rank, i.e., all rows (or, equivalently, 39152 columns) must be linearly independent; if either is not true, use 39153 `lstsq` for the least-squares best "solution" of the 39154 system/equation. 39155 39156 References 39157 ---------- 39158 .. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando, 39159 FL, Academic Press, Inc., 1980, pg. 22. 39160 39161 Examples 39162 -------- 39163 Solve the system of equations ``3 * x0 + x1 = 9`` and ``x0 + 2 * x1 = 8``: 39164 39165 >>> a = np.array([[3,1], [1,2]]) 39166 >>> b = np.array([9,8]) 39167 >>> x = np.linalg.solve(a, b) 39168 >>> x 39169 array([ 2., 3.]) 39170 39171 Check that the solution is correct: 39172 39173 >>> np.allclose(np.dot(a, x), b) 39174 True 39175 39176 """ 39177 return more_args() 39178 def svd(self, a=1, full_matrices=1, compute_uv=1): 39179 """ 39180 Singular Value Decomposition. 39181 39182 Factors the matrix `a` as ``u * np.diag(s) * v``, where `u` and `v` 39183 are unitary and `s` is a 1-d array of `a`'s singular values. 39184 39185 Parameters 39186 ---------- 39187 a : (..., M, N) array_like 39188 A real or complex matrix of shape (`M`, `N`) . 39189 full_matrices : bool, optional 39190 If True (default), `u` and `v` have the shapes (`M`, `M`) and 39191 (`N`, `N`), respectively. Otherwise, the shapes are (`M`, `K`) 39192 and (`K`, `N`), respectively, where `K` = min(`M`, `N`). 39193 compute_uv : bool, optional 39194 Whether or not to compute `u` and `v` in addition to `s`. True 39195 by default. 39196 39197 Returns 39198 ------- 39199 u : { (..., M, M), (..., M, K) } array 39200 Unitary matrices. The actual shape depends on the value of 39201 ``full_matrices``. Only returned when ``compute_uv`` is True. 39202 s : (..., K) array 39203 The singular values for every matrix, sorted in descending order. 39204 v : { (..., N, N), (..., K, N) } array 39205 Unitary matrices. The actual shape depends on the value of 39206 ``full_matrices``. Only returned when ``compute_uv`` is True. 39207 39208 Raises 39209 ------ 39210 LinAlgError 39211 If SVD computation does not converge. 39212 39213 Notes 39214 ----- 39215 Broadcasting rules apply, see the `numpy.linalg` documentation for 39216 details. 39217 39218 The decomposition is performed using LAPACK routine _gesdd 39219 39220 The SVD is commonly written as ``a = U S V.H``. The `v` returned 39221 by this function is ``V.H`` and ``u = U``. 39222 39223 If ``U`` is a unitary matrix, it means that it 39224 satisfies ``U.H = inv(U)``. 39225 39226 The rows of `v` are the eigenvectors of ``a.H a``. The columns 39227 of `u` are the eigenvectors of ``a a.H``. For row ``i`` in 39228 `v` and column ``i`` in `u`, the corresponding eigenvalue is 39229 ``s[i]**2``. 39230 39231 If `a` is a `matrix` object (as opposed to an `ndarray`), then so 39232 are all the return values. 39233 39234 Examples 39235 -------- 39236 >>> a = np.random.randn(9, 6) + 1j*np.random.randn(9, 6) 39237 39238 Reconstruction based on full SVD: 39239 39240 >>> U, s, V = np.linalg.svd(a, full_matrices=True) 39241 >>> U.shape, V.shape, s.shape 39242 ((9, 9), (6, 6), (6,)) 39243 >>> S = np.zeros((9, 6), dtype=complex) 39244 >>> S[:6, :6] = np.diag(s) 39245 >>> np.allclose(a, np.dot(U, np.dot(S, V))) 39246 True 39247 39248 Reconstruction based on reduced SVD: 39249 39250 >>> U, s, V = np.linalg.svd(a, full_matrices=False) 39251 >>> U.shape, V.shape, s.shape 39252 ((9, 6), (6, 6), (6,)) 39253 >>> S = np.diag(s) 39254 >>> np.allclose(a, np.dot(U, np.dot(S, V))) 39255 True 39256 39257 """ 39258 return None 39259 def tensorinv(self, a=2, ind=2): 39260 """ 39261 Compute the 'inverse' of an N-dimensional array. 39262 39263 The result is an inverse for `a` relative to the tensordot operation 39264 ``tensordot(a, b, ind)``, i. e., up to floating-point accuracy, 39265 ``tensordot(tensorinv(a), a, ind)`` is the "identity" tensor for the 39266 tensordot operation. 39267 39268 Parameters 39269 ---------- 39270 a : array_like 39271 Tensor to 'invert'. Its shape must be 'square', i. e., 39272 ``prod(a.shape[:ind]) == prod(a.shape[ind:])``. 39273 ind : int, optional 39274 Number of first indices that are involved in the inverse sum. 39275 Must be a positive integer, default is 2. 39276 39277 Returns 39278 ------- 39279 b : ndarray 39280 `a`'s tensordot inverse, shape ``a.shape[:ind] + a.shape[ind:]``. 39281 39282 Raises 39283 ------ 39284 LinAlgError 39285 If `a` is singular or not 'square' (in the above sense). 39286 39287 See Also 39288 -------- 39289 tensordot, tensorsolve 39290 39291 Examples 39292 -------- 39293 >>> a = np.eye(4*6) 39294 >>> a.shape = (4, 6, 8, 3) 39295 >>> ainv = np.linalg.tensorinv(a, ind=2) 39296 >>> ainv.shape 39297 (8, 3, 4, 6) 39298 >>> b = np.random.randn(4, 6) 39299 >>> np.allclose(np.tensordot(ainv, b), np.linalg.tensorsolve(a, b)) 39300 True 39301 39302 >>> a = np.eye(4*6) 39303 >>> a.shape = (24, 8, 3) 39304 >>> ainv = np.linalg.tensorinv(a, ind=1) 39305 >>> ainv.shape 39306 (8, 3, 24) 39307 >>> b = np.random.randn(24) 39308 >>> np.allclose(np.tensordot(ainv, b, 1), np.linalg.tensorsolve(a, b)) 39309 True 39310 39311 """ 39312 return ndarray() 39313 def tensorsolve(self, a, b=None, axes=None): 39314 """ 39315 Solve the tensor equation ``a x = b`` for x. 39316 39317 It is assumed that all indices of `x` are summed over in the product, 39318 together with the rightmost indices of `a`, as is done in, for example, 39319 ``tensordot(a, x, axes=len(b.shape))``. 39320 39321 Parameters 39322 ---------- 39323 a : array_like 39324 Coefficient tensor, of shape ``b.shape + Q``. `Q`, a tuple, equals 39325 the shape of that sub-tensor of `a` consisting of the appropriate 39326 number of its rightmost indices, and must be such that 39327 ``prod(Q) == prod(b.shape)`` (in which sense `a` is said to be 39328 'square'). 39329 b : array_like 39330 Right-hand tensor, which can be of any shape. 39331 axes : tuple of ints, optional 39332 Axes in `a` to reorder to the right, before inversion. 39333 If None (default), no reordering is done. 39334 39335 Returns 39336 ------- 39337 x : ndarray, shape Q 39338 39339 Raises 39340 ------ 39341 LinAlgError 39342 If `a` is singular or not 'square' (in the above sense). 39343 39344 See Also 39345 -------- 39346 tensordot, tensorinv, einsum 39347 39348 Examples 39349 -------- 39350 >>> a = np.eye(2*3*4) 39351 >>> a.shape = (2*3, 4, 2, 3, 4) 39352 >>> b = np.random.randn(2*3, 4) 39353 >>> x = np.linalg.tensorsolve(a, b) 39354 >>> x.shape 39355 (2, 3, 4) 39356 >>> np.allclose(np.tensordot(a, x, axes=3), b) 39357 True 39358 39359 """ 39360 return None 39361 def test(self=None, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None): 39362 """ 39363 Run tests for module using nose. 39364 39365 Parameters 39366 ---------- 39367 label : {'fast', 'full', '', attribute identifier}, optional 39368 Identifies the tests to run. This can be a string to pass to 39369 the nosetests executable with the '-A' option, or one of several 39370 special values. Special values are: 39371 * 'fast' - the default - which corresponds to the ``nosetests -A`` 39372 option of 'not slow'. 39373 * 'full' - fast (as above) and slow tests as in the 39374 'no -A' option to nosetests - this is the same as ''. 39375 * None or '' - run all tests. 39376 attribute_identifier - string passed directly to nosetests as '-A'. 39377 verbose : int, optional 39378 Verbosity value for test outputs, in the range 1-10. Default is 1. 39379 extra_argv : list, optional 39380 List with any extra arguments to pass to nosetests. 39381 doctests : bool, optional 39382 If True, run doctests in module. Default is False. 39383 coverage : bool, optional 39384 If True, report coverage of NumPy code. Default is False. 39385 (This requires the `coverage module: 39386 <http://nedbatchelder.com/code/modules/coverage.html>`_). 39387 raise_warnings : str or sequence of warnings, optional 39388 This specifies which warnings to configure as 'raise' instead 39389 of 'warn' during the test execution. Valid strings are: 39390 39391 - "develop" : equals ``(DeprecationWarning, RuntimeWarning)`` 39392 - "release" : equals ``()``, don't raise on any warnings. 39393 39394 Returns 39395 ------- 39396 result : object 39397 Returns the result of running the tests as a 39398 ``nose.result.TextTestResult`` object. 39399 39400 Notes 39401 ----- 39402 Each NumPy module exposes `test` in its namespace to run all tests for it. 39403 For example, to run all tests for numpy.lib: 39404 39405 >>> np.lib.test() #doctest: +SKIP 39406 39407 Examples 39408 -------- 39409 >>> result = np.lib.test() #doctest: +SKIP 39410 Running unit tests for numpy.lib 39411 ... 39412 Ran 976 tests in 3.933s 39413 39414 OK 39415 39416 >>> result.errors #doctest: +SKIP 39417 [] 39418 >>> result.knownfail #doctest: +SKIP 39419 [] 39420 """ 39421 return object() 39422 class testing: 39423 class IgnoreException: 39424 __dict__ = dictproxy() 39425 __doc__ = str() 39426 __module__ = str() 39427 __weakref__ = getset_descriptor() 39428 args = getset_descriptor() 39429 message = getset_descriptor() 39430 class TestCase: 39431 __dict__ = dictproxy() 39432 __doc__ = str() 39433 __module__ = str() 39434 __weakref__ = getset_descriptor() 39435 def _addSkip(self, _): 39436 """None""" 39437 return None 39438 def _baseAssertEqual(self, first, second=None, msg=None): 39439 """The default assertEqual implementation, not type specific.""" 39440 return None 39441 _classSetupFailed = bool() 39442 def _deprecate(self, _): 39443 """None""" 39444 return None 39445 _diffThreshold = int() 39446 def _formatMessage(self, _): 39447 """Honour the longMessage attribute when generating failure messages. 39448 If longMessage is False this means: 39449 * Use only an explicit message if it is provided 39450 * Otherwise use the standard message for the assert 39451 39452 If longMessage is True: 39453 * Use the standard message 39454 * If an explicit message is provided, plus ' : ' and the explicit message 39455 """ 39456 return None 39457 def _getAssertEqualityFunc(self, _): 39458 """Get a detailed comparison function for the types of the two args. 39459 39460 Returns: A callable accepting (first, second, msg=None) that will 39461 raise a failure exception if first != second with a useful human 39462 readable error message for those types. 39463 """ 39464 return None 39465 def _truncateMessage(self, _): 39466 """None""" 39467 return None 39468 def addCleanup(self, _): 39469 """Add a function, with arguments, to be called when the test is 39470 completed. Functions added are called on a LIFO basis and are 39471 called after tearDown on test failure or success. 39472 39473 Cleanup items are called even if setUp fails (unlike tearDown).""" 39474 return None 39475 def addTypeEqualityFunc(self, _): 39476 """Add a type specific assertEqual style function to compare a type. 39477 39478 This method is for use by TestCase subclasses that need to register 39479 their own type equality functions to provide nicer error messages. 39480 39481 Args: 39482 typeobj: The data type to call this function on when both values 39483 are of the same type in assertEqual(). 39484 function: The callable taking two arguments and an optional 39485 msg= argument that raises self.failureException with a 39486 useful error message when the two arguments are not equal. 39487 """ 39488 return None 39489 def assertAlmostEqual(self, first, second=None, places=None, msg=None, delta=None): 39490 """Fail if the two objects are unequal as determined by their 39491 difference rounded to the given number of decimal places 39492 (default 7) and comparing to zero, or by comparing that the 39493 between the two objects is more than the given delta. 39494 39495 Note that decimal places (from zero) are usually not the same 39496 as significant digits (measured from the most signficant digit). 39497 39498 If the two objects compare equal then they will automatically 39499 compare almost equal. 39500 """ 39501 return None 39502 def assertAlmostEqual(self, first, second=None, places=None, msg=None, delta=None): 39503 """Fail if the two objects are unequal as determined by their 39504 difference rounded to the given number of decimal places 39505 (default 7) and comparing to zero, or by comparing that the 39506 between the two objects is more than the given delta. 39507 39508 Note that decimal places (from zero) are usually not the same 39509 as significant digits (measured from the most signficant digit). 39510 39511 If the two objects compare equal then they will automatically 39512 compare almost equal. 39513 """ 39514 return None 39515 def assertDictContainsSubset(self, expected, actual=None, msg=None): 39516 """Checks whether actual is a superset of expected.""" 39517 return None 39518 def assertDictEqual(self, d1, d2=None, msg=None): 39519 """None""" 39520 return None 39521 def assertEqual(self, first, second=None, msg=None): 39522 """Fail if the two objects are unequal as determined by the '==' 39523 operator. 39524 """ 39525 return None 39526 def assertEqual(self, first, second=None, msg=None): 39527 """Fail if the two objects are unequal as determined by the '==' 39528 operator. 39529 """ 39530 return None 39531 def assertFalse(self, expr=None, msg=None): 39532 """Check that the expression is false.""" 39533 return None 39534 def assertGreater(self, a, b=None, msg=None): 39535 """Just like self.assertTrue(a > b), but with a nicer default message.""" 39536 return None 39537 def assertGreaterEqual(self, a, b=None, msg=None): 39538 """Just like self.assertTrue(a >= b), but with a nicer default message.""" 39539 return None 39540 def assertIn(self, member, container=None, msg=None): 39541 """Just like self.assertTrue(a in b), but with a nicer default message.""" 39542 return None 39543 def assertIs(self, expr1, expr2=None, msg=None): 39544 """Just like self.assertTrue(a is b), but with a nicer default message.""" 39545 return None 39546 def assertIsInstance(self, obj, cls=None, msg=None): 39547 """Same as self.assertTrue(isinstance(obj, cls)), with a nicer 39548 default message.""" 39549 return None 39550 def assertIsNone(self, obj=None, msg=None): 39551 """Same as self.assertTrue(obj is None), with a nicer default message.""" 39552 return None 39553 def assertIsNot(self, expr1, expr2=None, msg=None): 39554 """Just like self.assertTrue(a is not b), but with a nicer default message.""" 39555 return None 39556 def assertIsNotNone(self, obj=None, msg=None): 39557 """Included for symmetry with assertIsNone.""" 39558 return None 39559 def assertItemsEqual(self, expected_seq, actual_seq=None, msg=None): 39560 """An unordered sequence specific comparison. It asserts that 39561 actual_seq and expected_seq have the same element counts. 39562 Equivalent to:: 39563 39564 self.assertEqual(Counter(iter(actual_seq)), 39565 Counter(iter(expected_seq))) 39566 39567 Asserts that each element has the same count in both sequences. 39568 Example: 39569 - [0, 1, 1] and [1, 0, 1] compare equal. 39570 - [0, 0, 1] and [0, 1] compare unequal. 39571 """ 39572 return None 39573 def assertLess(self, a, b=None, msg=None): 39574 """Just like self.assertTrue(a < b), but with a nicer default message.""" 39575 return None 39576 def assertLessEqual(self, a, b=None, msg=None): 39577 """Just like self.assertTrue(a <= b), but with a nicer default message.""" 39578 return None 39579 def assertListEqual(self, list1, list2=None, msg=None): 39580 """A list-specific equality assertion. 39581 39582 Args: 39583 list1: The first list to compare. 39584 list2: The second list to compare. 39585 msg: Optional message to use on failure instead of a list of 39586 differences. 39587 39588 """ 39589 return None 39590 def assertMultiLineEqual(self, first, second=None, msg=None): 39591 """Assert that two multi-line strings are equal.""" 39592 return None 39593 def assertNotAlmostEqual(self, first, second=None, places=None, msg=None, delta=None): 39594 """Fail if the two objects are equal as determined by their 39595 difference rounded to the given number of decimal places 39596 (default 7) and comparing to zero, or by comparing that the 39597 between the two objects is less than the given delta. 39598 39599 Note that decimal places (from zero) are usually not the same 39600 as significant digits (measured from the most signficant digit). 39601 39602 Objects that are equal automatically fail. 39603 """ 39604 return None 39605 def assertNotAlmostEqual(self, first, second=None, places=None, msg=None, delta=None): 39606 """Fail if the two objects are equal as determined by their 39607 difference rounded to the given number of decimal places 39608 (default 7) and comparing to zero, or by comparing that the 39609 between the two objects is less than the given delta. 39610 39611 Note that decimal places (from zero) are usually not the same 39612 as significant digits (measured from the most signficant digit). 39613 39614 Objects that are equal automatically fail. 39615 """ 39616 return None 39617 def assertNotEqual(self, first, second=None, msg=None): 39618 """Fail if the two objects are equal as determined by the '!=' 39619 operator. 39620 """ 39621 return None 39622 def assertNotEqual(self, first, second=None, msg=None): 39623 """Fail if the two objects are equal as determined by the '!=' 39624 operator. 39625 """ 39626 return None 39627 def assertNotIn(self, member, container=None, msg=None): 39628 """Just like self.assertTrue(a not in b), but with a nicer default message.""" 39629 return None 39630 def assertNotIsInstance(self, obj, cls=None, msg=None): 39631 """Included for symmetry with assertIsInstance.""" 39632 return None 39633 def assertNotRegexpMatches(self, text, unexpected_regexp=None, msg=None): 39634 """Fail the test if the text matches the regular expression.""" 39635 return None 39636 def assertRaises(self, excClass=None, callableObj=None): 39637 """Fail unless an exception of class excClass is raised 39638 by callableObj when invoked with arguments args and keyword 39639 arguments kwargs. If a different type of exception is 39640 raised, it will not be caught, and the test case will be 39641 deemed to have suffered an error, exactly as for an 39642 unexpected exception. 39643 39644 If called with callableObj omitted or None, will return a 39645 context object used like this:: 39646 39647 with self.assertRaises(SomeException): 39648 do_something() 39649 39650 The context manager keeps a reference to the exception as 39651 the 'exception' attribute. This allows you to inspect the 39652 exception after the assertion:: 39653 39654 with self.assertRaises(SomeException) as cm: 39655 do_something() 39656 the_exception = cm.exception 39657 self.assertEqual(the_exception.error_code, 3) 39658 """ 39659 return None 39660 def assertRaisesRegexp(self, expected_exception, expected_regexp=None, callable_obj=None): 39661 """Asserts that the message in a raised exception matches a regexp. 39662 39663 Args: 39664 expected_exception: Exception class expected to be raised. 39665 expected_regexp: Regexp (re pattern object or string) expected 39666 to be found in error message. 39667 callable_obj: Function to be called. 39668 args: Extra args. 39669 kwargs: Extra kwargs. 39670 """ 39671 return None 39672 def assertRegexpMatches(self, text, expected_regexp=None, msg=None): 39673 """Fail the test unless the text matches the regular expression.""" 39674 return None 39675 def assertSequenceEqual(self, seq1, seq2=None, msg=None, seq_type=None): 39676 """An equality assertion for ordered sequences (like lists and tuples). 39677 39678 For the purposes of this function, a valid ordered sequence type is one 39679 which can be indexed, has a length, and has an equality operator. 39680 39681 Args: 39682 seq1: The first sequence to compare. 39683 seq2: The second sequence to compare. 39684 seq_type: The expected datatype of the sequences, or None if no 39685 datatype should be enforced. 39686 msg: Optional message to use on failure instead of a list of 39687 differences. 39688 """ 39689 return None 39690 def assertSetEqual(self, set1, set2=None, msg=None): 39691 """A set-specific equality assertion. 39692 39693 Args: 39694 set1: The first set to compare. 39695 set2: The second set to compare. 39696 msg: Optional message to use on failure instead of a list of 39697 differences. 39698 39699 assertSetEqual uses ducktyping to support different types of sets, and 39700 is optimized for sets specifically (parameters must support a 39701 difference method). 39702 """ 39703 return None 39704 def assertTrue(self, expr=None, msg=None): 39705 """Check that the expression is true.""" 39706 return None 39707 def assertTupleEqual(self, tuple1, tuple2=None, msg=None): 39708 """A tuple-specific equality assertion. 39709 39710 Args: 39711 tuple1: The first tuple to compare. 39712 tuple2: The second tuple to compare. 39713 msg: Optional message to use on failure instead of a list of 39714 differences. 39715 """ 39716 return None 39717 def assertTrue(self, expr=None, msg=None): 39718 """Check that the expression is true.""" 39719 return None 39720 def countTestCases(self, _): 39721 """None""" 39722 return None 39723 def debug(self, _): 39724 """Run the test without collecting errors in a TestResult""" 39725 return None 39726 def defaultTestResult(self, _): 39727 """None""" 39728 return None 39729 def doCleanups(self, _): 39730 """Execute all cleanup functions. Normally called for you after 39731 tearDown.""" 39732 return None 39733 def fail(self=None, msg=None): 39734 """Fail immediately, with the given message.""" 39735 return None 39736 def deprecated_func(self): 39737 """None""" 39738 return None 39739 def deprecated_func(self): 39740 """None""" 39741 return None 39742 def deprecated_func(self): 39743 """None""" 39744 return None 39745 def deprecated_func(self): 39746 """None""" 39747 return None 39748 def deprecated_func(self): 39749 """None""" 39750 return None 39751 def deprecated_func(self): 39752 """None""" 39753 return None 39754 def deprecated_func(self): 39755 """None""" 39756 return None 39757 def id(self, _): 39758 """None""" 39759 return None 39760 longMessage = bool() 39761 maxDiff = int() 39762 def run(self=None, result=None): 39763 """None""" 39764 return None 39765 def setUp(self, _): 39766 """Hook method for setting up the test fixture before exercising it.""" 39767 return None 39768 def setUpClass(self, _): 39769 """Hook method for setting up class fixture before running tests in the class.""" 39770 return None 39771 def shortDescription(self, _): 39772 """Returns a one-line description of the test, or None if no 39773 description has been provided. 39774 39775 The default implementation of this method returns the first line of 39776 the specified test method's docstring. 39777 """ 39778 return None 39779 def skipTest(self, _): 39780 """Skip this test.""" 39781 return None 39782 def tearDown(self, _): 39783 """Hook method for deconstructing the test fixture after testing it.""" 39784 return None 39785 def tearDownClass(self, _): 39786 """Hook method for deconstructing the class fixture after running all tests in the class.""" 39787 return None 39788 class NoseTester: 39789 __dict__ = dictproxy() 39790 __doc__ = str() 39791 __module__ = str() 39792 __weakref__ = getset_descriptor() 39793 def _get_custom_doctester(self, _): 39794 """ Return instantiated plugin for doctests 39795 39796 Allows subclassing of this class to override doctester 39797 39798 A return value of None means use the nose builtin doctest plugin 39799 """ 39800 return None 39801 def _show_system_info(self, _): 39802 """None""" 39803 return None 39804 def _test_argv(self, label, verbose, extra_argv): 39805 """ Generate argv for nosetest command 39806 39807 Parameters 39808 ---------- 39809 label : {'fast', 'full', '', attribute identifier}, optional 39810 see ``test`` docstring 39811 verbose : int, optional 39812 Verbosity value for test outputs, in the range 1-10. Default is 1. 39813 extra_argv : list, optional 39814 List with any extra arguments to pass to nosetests. 39815 39816 Returns 39817 ------- 39818 argv : list 39819 command line arguments that will be passed to nose 39820 """ 39821 return list() 39822 def bench(self=None, label="fast", verbose=1, extra_argv=None): 39823 """ 39824 Run benchmarks for module using nose. 39825 39826 Parameters 39827 ---------- 39828 label : {'fast', 'full', '', attribute identifier}, optional 39829 Identifies the benchmarks to run. This can be a string to pass to 39830 the nosetests executable with the '-A' option, or one of several 39831 special values. Special values are: 39832 * 'fast' - the default - which corresponds to the ``nosetests -A`` 39833 option of 'not slow'. 39834 * 'full' - fast (as above) and slow benchmarks as in the 39835 'no -A' option to nosetests - this is the same as ''. 39836 * None or '' - run all tests. 39837 attribute_identifier - string passed directly to nosetests as '-A'. 39838 verbose : int, optional 39839 Verbosity value for benchmark outputs, in the range 1-10. Default is 1. 39840 extra_argv : list, optional 39841 List with any extra arguments to pass to nosetests. 39842 39843 Returns 39844 ------- 39845 success : bool 39846 Returns True if running the benchmarks works, False if an error 39847 occurred. 39848 39849 Notes 39850 ----- 39851 Benchmarks are like tests, but have names starting with "bench" instead 39852 of "test", and can be found under the "benchmarks" sub-directory of the 39853 module. 39854 39855 Each NumPy module exposes `bench` in its namespace to run all benchmarks 39856 for it. 39857 39858 Examples 39859 -------- 39860 >>> success = np.lib.bench() #doctest: +SKIP 39861 Running benchmarks for numpy.lib 39862 ... 39863 using 562341 items: 39864 unique: 39865 0.11 39866 unique1d: 39867 0.11 39868 ratio: 1.0 39869 nUnique: 56230 == 56230 39870 ... 39871 OK 39872 39873 >>> success #doctest: +SKIP 39874 True 39875 39876 """ 39877 return bool() 39878 excludes = list() 39879 def prepare_test_args(self=False, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False): 39880 """ 39881 Run tests for module using nose. 39882 39883 This method does the heavy lifting for the `test` method. It takes all 39884 the same arguments, for details see `test`. 39885 39886 See Also 39887 -------- 39888 test 39889 39890 """ 39891 return None 39892 def test(self=None, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None): 39893 """ 39894 Run tests for module using nose. 39895 39896 Parameters 39897 ---------- 39898 label : {'fast', 'full', '', attribute identifier}, optional 39899 Identifies the tests to run. This can be a string to pass to 39900 the nosetests executable with the '-A' option, or one of several 39901 special values. Special values are: 39902 * 'fast' - the default - which corresponds to the ``nosetests -A`` 39903 option of 'not slow'. 39904 * 'full' - fast (as above) and slow tests as in the 39905 'no -A' option to nosetests - this is the same as ''. 39906 * None or '' - run all tests. 39907 attribute_identifier - string passed directly to nosetests as '-A'. 39908 verbose : int, optional 39909 Verbosity value for test outputs, in the range 1-10. Default is 1. 39910 extra_argv : list, optional 39911 List with any extra arguments to pass to nosetests. 39912 doctests : bool, optional 39913 If True, run doctests in module. Default is False. 39914 coverage : bool, optional 39915 If True, report coverage of NumPy code. Default is False. 39916 (This requires the `coverage module: 39917 <http://nedbatchelder.com/code/modules/coverage.html>`_). 39918 raise_warnings : str or sequence of warnings, optional 39919 This specifies which warnings to configure as 'raise' instead 39920 of 'warn' during the test execution. Valid strings are: 39921 39922 - "develop" : equals ``(DeprecationWarning, RuntimeWarning)`` 39923 - "release" : equals ``()``, don't raise on any warnings. 39924 39925 Returns 39926 ------- 39927 result : object 39928 Returns the result of running the tests as a 39929 ``nose.result.TextTestResult`` object. 39930 39931 Notes 39932 ----- 39933 Each NumPy module exposes `test` in its namespace to run all tests for it. 39934 For example, to run all tests for numpy.lib: 39935 39936 >>> np.lib.test() #doctest: +SKIP 39937 39938 Examples 39939 -------- 39940 >>> result = np.lib.test() #doctest: +SKIP 39941 Running unit tests for numpy.lib 39942 ... 39943 Ran 976 tests in 3.933s 39944 39945 OK 39946 39947 >>> result.errors #doctest: +SKIP 39948 [] 39949 >>> result.knownfail #doctest: +SKIP 39950 [] 39951 """ 39952 return object() 39953 __builtins__ = dict() 39954 __doc__ = str() 39955 __file__ = str() 39956 __name__ = str() 39957 __package__ = str() 39958 __path__ = list() 39959 absolute_import = instance() 39960 def assert_(self, val="", msg=""): 39961 """ 39962 Assert that works in release mode. 39963 39964 The Python built-in ``assert`` does not work when executing code in 39965 optimized mode (the ``-O`` flag) - no byte-code is generated for it. 39966 39967 For documentation on usage, refer to the Python documentation. 39968 39969 """ 39970 return None 39971 def assert_allclose(self, actual, desired=True, rtol=1e-07, atol=0, err_msg="", verbose=True): 39972 """ 39973 Raise an assertion if two objects are not equal up to desired tolerance. 39974 39975 The test is equivalent to ``allclose(actual, desired, rtol, atol)``. 39976 It compares the difference between `actual` and `desired` to 39977 ``atol + rtol * abs(desired)``. 39978 39979 Parameters 39980 ---------- 39981 actual : array_like 39982 Array obtained. 39983 desired : array_like 39984 Array desired. 39985 rtol : float, optional 39986 Relative tolerance. 39987 atol : float, optional 39988 Absolute tolerance. 39989 err_msg : str, optional 39990 The error message to be printed in case of failure. 39991 verbose : bool, optional 39992 If True, the conflicting values are appended to the error message. 39993 39994 Raises 39995 ------ 39996 AssertionError 39997 If actual and desired are not equal up to specified precision. 39998 39999 See Also 40000 -------- 40001 assert_array_almost_equal_nulp, assert_array_max_ulp 40002 40003 Examples 40004 -------- 40005 >>> x = [1e-5, 1e-3, 1e-1] 40006 >>> y = np.arccos(np.cos(x)) 40007 >>> assert_allclose(x, y, rtol=1e-5, atol=0) 40008 40009 """ 40010 return None 40011 def assert_almost_equal(self, actual, desired=True, decimal=7, err_msg="", verbose=True): 40012 """ 40013 Raise an assertion if two items are not equal up to desired precision. 40014 40015 .. note:: It is recommended to use one of `assert_allclose`, 40016 `assert_array_almost_equal_nulp` or `assert_array_max_ulp` 40017 instead of this function for more consistent floating point 40018 comparisons. 40019 40020 The test is equivalent to ``abs(desired-actual) < 0.5 * 10**(-decimal)``. 40021 40022 Given two objects (numbers or ndarrays), check that all elements of these 40023 objects are almost equal. An exception is raised at conflicting values. 40024 For ndarrays this delegates to assert_array_almost_equal 40025 40026 Parameters 40027 ---------- 40028 actual : array_like 40029 The object to check. 40030 desired : array_like 40031 The expected object. 40032 decimal : int, optional 40033 Desired precision, default is 7. 40034 err_msg : str, optional 40035 The error message to be printed in case of failure. 40036 verbose : bool, optional 40037 If True, the conflicting values are appended to the error message. 40038 40039 Raises 40040 ------ 40041 AssertionError 40042 If actual and desired are not equal up to specified precision. 40043 40044 See Also 40045 -------- 40046 assert_allclose: Compare two array_like objects for equality with desired 40047 relative and/or absolute precision. 40048 assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal 40049 40050 Examples 40051 -------- 40052 >>> import numpy.testing as npt 40053 >>> npt.assert_almost_equal(2.3333333333333, 2.33333334) 40054 >>> npt.assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) 40055 ... 40056 <type 'exceptions.AssertionError'>: 40057 Items are not equal: 40058 ACTUAL: 2.3333333333333002 40059 DESIRED: 2.3333333399999998 40060 40061 >>> npt.assert_almost_equal(np.array([1.0,2.3333333333333]), 40062 ... np.array([1.0,2.33333334]), decimal=9) 40063 ... 40064 <type 'exceptions.AssertionError'>: 40065 Arrays are not almost equal 40066 <BLANKLINE> 40067 (mismatch 50.0%) 40068 x: array([ 1. , 2.33333333]) 40069 y: array([ 1. , 2.33333334]) 40070 40071 """ 40072 return None 40073 def assert_approx_equal(self, actual, desired=True, significant=7, err_msg="", verbose=True): 40074 """ 40075 Raise an assertion if two items are not equal up to significant digits. 40076 40077 .. note:: It is recommended to use one of `assert_allclose`, 40078 `assert_array_almost_equal_nulp` or `assert_array_max_ulp` 40079 instead of this function for more consistent floating point 40080 comparisons. 40081 40082 Given two numbers, check that they are approximately equal. 40083 Approximately equal is defined as the number of significant digits 40084 that agree. 40085 40086 Parameters 40087 ---------- 40088 actual : scalar 40089 The object to check. 40090 desired : scalar 40091 The expected object. 40092 significant : int, optional 40093 Desired precision, default is 7. 40094 err_msg : str, optional 40095 The error message to be printed in case of failure. 40096 verbose : bool, optional 40097 If True, the conflicting values are appended to the error message. 40098 40099 Raises 40100 ------ 40101 AssertionError 40102 If actual and desired are not equal up to specified precision. 40103 40104 See Also 40105 -------- 40106 assert_allclose: Compare two array_like objects for equality with desired 40107 relative and/or absolute precision. 40108 assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal 40109 40110 Examples 40111 -------- 40112 >>> np.testing.assert_approx_equal(0.12345677777777e-20, 0.1234567e-20) 40113 >>> np.testing.assert_approx_equal(0.12345670e-20, 0.12345671e-20, 40114 significant=8) 40115 >>> np.testing.assert_approx_equal(0.12345670e-20, 0.12345672e-20, 40116 significant=8) 40117 ... 40118 <type 'exceptions.AssertionError'>: 40119 Items are not equal to 8 significant digits: 40120 ACTUAL: 1.234567e-021 40121 DESIRED: 1.2345672000000001e-021 40122 40123 the evaluated condition that raises the exception is 40124 40125 >>> abs(0.12345670e-20/1e-21 - 0.12345672e-20/1e-21) >= 10**-(8-1) 40126 True 40127 40128 """ 40129 return None 40130 def assert_array_almost_equal(self, x, y=True, decimal=6, err_msg="", verbose=True): 40131 """ 40132 Raise an assertion if two objects are not equal up to desired precision. 40133 40134 .. note:: It is recommended to use one of `assert_allclose`, 40135 `assert_array_almost_equal_nulp` or `assert_array_max_ulp` 40136 instead of this function for more consistent floating point 40137 comparisons. 40138 40139 The test verifies identical shapes and verifies values with 40140 ``abs(desired-actual) < 0.5 * 10**(-decimal)``. 40141 40142 Given two array_like objects, check that the shape is equal and all 40143 elements of these objects are almost equal. An exception is raised at 40144 shape mismatch or conflicting values. In contrast to the standard usage 40145 in numpy, NaNs are compared like numbers, no assertion is raised if 40146 both objects have NaNs in the same positions. 40147 40148 Parameters 40149 ---------- 40150 x : array_like 40151 The actual object to check. 40152 y : array_like 40153 The desired, expected object. 40154 decimal : int, optional 40155 Desired precision, default is 6. 40156 err_msg : str, optional 40157 The error message to be printed in case of failure. 40158 verbose : bool, optional 40159 If True, the conflicting values are appended to the error message. 40160 40161 Raises 40162 ------ 40163 AssertionError 40164 If actual and desired are not equal up to specified precision. 40165 40166 See Also 40167 -------- 40168 assert_allclose: Compare two array_like objects for equality with desired 40169 relative and/or absolute precision. 40170 assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal 40171 40172 Examples 40173 -------- 40174 the first assert does not raise an exception 40175 40176 >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], 40177 [1.0,2.333,np.nan]) 40178 40179 >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], 40180 ... [1.0,2.33339,np.nan], decimal=5) 40181 ... 40182 <type 'exceptions.AssertionError'>: 40183 AssertionError: 40184 Arrays are not almost equal 40185 <BLANKLINE> 40186 (mismatch 50.0%) 40187 x: array([ 1. , 2.33333, NaN]) 40188 y: array([ 1. , 2.33339, NaN]) 40189 40190 >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], 40191 ... [1.0,2.33333, 5], decimal=5) 40192 <type 'exceptions.ValueError'>: 40193 ValueError: 40194 Arrays are not almost equal 40195 x: array([ 1. , 2.33333, NaN]) 40196 y: array([ 1. , 2.33333, 5. ]) 40197 40198 """ 40199 return None 40200 def assert_array_almost_equal_nulp(self, x, y=1, nulp=1): 40201 """ 40202 Compare two arrays relatively to their spacing. 40203 40204 This is a relatively robust method to compare two arrays whose amplitude 40205 is variable. 40206 40207 Parameters 40208 ---------- 40209 x, y : array_like 40210 Input arrays. 40211 nulp : int, optional 40212 The maximum number of unit in the last place for tolerance (see Notes). 40213 Default is 1. 40214 40215 Returns 40216 ------- 40217 None 40218 40219 Raises 40220 ------ 40221 AssertionError 40222 If the spacing between `x` and `y` for one or more elements is larger 40223 than `nulp`. 40224 40225 See Also 40226 -------- 40227 assert_array_max_ulp : Check that all items of arrays differ in at most 40228 N Units in the Last Place. 40229 spacing : Return the distance between x and the nearest adjacent number. 40230 40231 Notes 40232 ----- 40233 An assertion is raised if the following condition is not met:: 40234 40235 abs(x - y) <= nulps * spacing(max(abs(x), abs(y))) 40236 40237 Examples 40238 -------- 40239 >>> x = np.array([1., 1e-10, 1e-20]) 40240 >>> eps = np.finfo(x.dtype).eps 40241 >>> np.testing.assert_array_almost_equal_nulp(x, x*eps/2 + x) 40242 40243 >>> np.testing.assert_array_almost_equal_nulp(x, x*eps + x) 40244 ------------------------------------------------------------ 40245 Traceback (most recent call last): 40246 ... 40247 AssertionError: X and Y are not equal to 1 ULP (max is 2) 40248 40249 """ 40250 return None 40251 def assert_array_equal(self, x, y=True, err_msg="", verbose=True): 40252 """ 40253 Raise an assertion if two array_like objects are not equal. 40254 40255 Given two array_like objects, check that the shape is equal and all 40256 elements of these objects are equal. An exception is raised at 40257 shape mismatch or conflicting values. In contrast to the standard usage 40258 in numpy, NaNs are compared like numbers, no assertion is raised if 40259 both objects have NaNs in the same positions. 40260 40261 The usual caution for verifying equality with floating point numbers is 40262 advised. 40263 40264 Parameters 40265 ---------- 40266 x : array_like 40267 The actual object to check. 40268 y : array_like 40269 The desired, expected object. 40270 err_msg : str, optional 40271 The error message to be printed in case of failure. 40272 verbose : bool, optional 40273 If True, the conflicting values are appended to the error message. 40274 40275 Raises 40276 ------ 40277 AssertionError 40278 If actual and desired objects are not equal. 40279 40280 See Also 40281 -------- 40282 assert_allclose: Compare two array_like objects for equality with desired 40283 relative and/or absolute precision. 40284 assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal 40285 40286 Examples 40287 -------- 40288 The first assert does not raise an exception: 40289 40290 >>> np.testing.assert_array_equal([1.0,2.33333,np.nan], 40291 ... [np.exp(0),2.33333, np.nan]) 40292 40293 Assert fails with numerical inprecision with floats: 40294 40295 >>> np.testing.assert_array_equal([1.0,np.pi,np.nan], 40296 ... [1, np.sqrt(np.pi)**2, np.nan]) 40297 ... 40298 <type 'exceptions.ValueError'>: 40299 AssertionError: 40300 Arrays are not equal 40301 <BLANKLINE> 40302 (mismatch 50.0%) 40303 x: array([ 1. , 3.14159265, NaN]) 40304 y: array([ 1. , 3.14159265, NaN]) 40305 40306 Use `assert_allclose` or one of the nulp (number of floating point values) 40307 functions for these cases instead: 40308 40309 >>> np.testing.assert_allclose([1.0,np.pi,np.nan], 40310 ... [1, np.sqrt(np.pi)**2, np.nan], 40311 ... rtol=1e-10, atol=0) 40312 40313 """ 40314 return None 40315 def assert_array_less(self, x, y=True, err_msg="", verbose=True): 40316 """ 40317 Raise an assertion if two array_like objects are not ordered by less than. 40318 40319 Given two array_like objects, check that the shape is equal and all 40320 elements of the first object are strictly smaller than those of the 40321 second object. An exception is raised at shape mismatch or incorrectly 40322 ordered values. Shape mismatch does not raise if an object has zero 40323 dimension. In contrast to the standard usage in numpy, NaNs are 40324 compared, no assertion is raised if both objects have NaNs in the same 40325 positions. 40326 40327 40328 40329 Parameters 40330 ---------- 40331 x : array_like 40332 The smaller object to check. 40333 y : array_like 40334 The larger object to compare. 40335 err_msg : string 40336 The error message to be printed in case of failure. 40337 verbose : bool 40338 If True, the conflicting values are appended to the error message. 40339 40340 Raises 40341 ------ 40342 AssertionError 40343 If actual and desired objects are not equal. 40344 40345 See Also 40346 -------- 40347 assert_array_equal: tests objects for equality 40348 assert_array_almost_equal: test objects for equality up to precision 40349 40350 40351 40352 Examples 40353 -------- 40354 >>> np.testing.assert_array_less([1.0, 1.0, np.nan], [1.1, 2.0, np.nan]) 40355 >>> np.testing.assert_array_less([1.0, 1.0, np.nan], [1, 2.0, np.nan]) 40356 ... 40357 <type 'exceptions.ValueError'>: 40358 Arrays are not less-ordered 40359 (mismatch 50.0%) 40360 x: array([ 1., 1., NaN]) 40361 y: array([ 1., 2., NaN]) 40362 40363 >>> np.testing.assert_array_less([1.0, 4.0], 3) 40364 ... 40365 <type 'exceptions.ValueError'>: 40366 Arrays are not less-ordered 40367 (mismatch 50.0%) 40368 x: array([ 1., 4.]) 40369 y: array(3) 40370 40371 >>> np.testing.assert_array_less([1.0, 2.0, 3.0], [4]) 40372 ... 40373 <type 'exceptions.ValueError'>: 40374 Arrays are not less-ordered 40375 (shapes (3,), (1,) mismatch) 40376 x: array([ 1., 2., 3.]) 40377 y: array([4]) 40378 40379 """ 40380 return None 40381 def assert_array_max_ulp(self, a, b=None, maxulp=1, dtype=None): 40382 """ 40383 Check that all items of arrays differ in at most N Units in the Last Place. 40384 40385 Parameters 40386 ---------- 40387 a, b : array_like 40388 Input arrays to be compared. 40389 maxulp : int, optional 40390 The maximum number of units in the last place that elements of `a` and 40391 `b` can differ. Default is 1. 40392 dtype : dtype, optional 40393 Data-type to convert `a` and `b` to if given. Default is None. 40394 40395 Returns 40396 ------- 40397 ret : ndarray 40398 Array containing number of representable floating point numbers between 40399 items in `a` and `b`. 40400 40401 Raises 40402 ------ 40403 AssertionError 40404 If one or more elements differ by more than `maxulp`. 40405 40406 See Also 40407 -------- 40408 assert_array_almost_equal_nulp : Compare two arrays relatively to their 40409 spacing. 40410 40411 Examples 40412 -------- 40413 >>> a = np.linspace(0., 1., 100) 40414 >>> res = np.testing.assert_array_max_ulp(a, np.arcsin(np.sin(a))) 40415 40416 """ 40417 return ndarray() 40418 def assert_equal(self, actual, desired=True, err_msg="", verbose=True): 40419 """ 40420 Raise an assertion if two objects are not equal. 40421 40422 Given two objects (scalars, lists, tuples, dictionaries or numpy arrays), 40423 check that all elements of these objects are equal. An exception is raised 40424 at the first conflicting values. 40425 40426 Parameters 40427 ---------- 40428 actual : array_like 40429 The object to check. 40430 desired : array_like 40431 The expected object. 40432 err_msg : str, optional 40433 The error message to be printed in case of failure. 40434 verbose : bool, optional 40435 If True, the conflicting values are appended to the error message. 40436 40437 Raises 40438 ------ 40439 AssertionError 40440 If actual and desired are not equal. 40441 40442 Examples 40443 -------- 40444 >>> np.testing.assert_equal([4,5], [4,6]) 40445 ... 40446 <type 'exceptions.AssertionError'>: 40447 Items are not equal: 40448 item=1 40449 ACTUAL: 5 40450 DESIRED: 6 40451 40452 """ 40453 return None 40454 def assert_no_warnings(self, func, ESCargs, ESCESCkwargs): 40455 """ 40456 Fail if the given callable produces any warnings. 40457 40458 Parameters 40459 ---------- 40460 func : callable 40461 The callable to test. 40462 \*args : Arguments 40463 Arguments passed to `func`. 40464 \*\*kwargs : Kwargs 40465 Keyword arguments passed to `func`. 40466 40467 Returns 40468 ------- 40469 The value returned by `func`. 40470 40471 """ 40472 return None 40473 def assert__raises(self): 40474 """ 40475 assert_raises(exception_class, callable, *args, **kwargs) 40476 40477 Fail unless an exception of class exception_class is thrown 40478 by callable when invoked with arguments args and keyword 40479 arguments kwargs. If a different type of exception is 40480 thrown, it will not be caught, and the test case will be 40481 deemed to have suffered an error, exactly as for an 40482 unexpected exception. 40483 40484 """ 40485 return None 40486 def assert_string_equal(self, actual, desired): 40487 """ 40488 Test if two strings are equal. 40489 40490 If the given strings are equal, `assert_string_equal` does nothing. 40491 If they are not equal, an AssertionError is raised, and the diff 40492 between the strings is shown. 40493 40494 Parameters 40495 ---------- 40496 actual : str 40497 The string to test for equality against the expected string. 40498 desired : str 40499 The expected string. 40500 40501 Examples 40502 -------- 40503 >>> np.testing.assert_string_equal('abc', 'abc') 40504 >>> np.testing.assert_string_equal('abc', 'abcd') 40505 Traceback (most recent call last): 40506 File "<stdin>", line 1, in <module> 40507 ... 40508 AssertionError: Differences in strings: 40509 - abc+ abcd? + 40510 40511 """ 40512 return None 40513 def assert_warns(self, warning__class, func, ESCargs, ESCESCkwargs): 40514 """ 40515 Fail unless the given callable throws the specified warning. 40516 40517 A warning of class warning_class should be thrown by the callable when 40518 invoked with arguments args and keyword arguments kwargs. 40519 If a different type of warning is thrown, it will not be caught, and the 40520 test case will be deemed to have suffered an error. 40521 40522 Parameters 40523 ---------- 40524 warning_class : class 40525 The class defining the warning that `func` is expected to throw. 40526 func : callable 40527 The callable to test. 40528 \*args : Arguments 40529 Arguments passed to `func`. 40530 \*\*kwargs : Kwargs 40531 Keyword arguments passed to `func`. 40532 40533 Returns 40534 ------- 40535 The value returned by `func`. 40536 40537 """ 40538 return None 40539 def build_err_msg(self, arrays, err_msg="('ACTUAL', 'DESIRED')", header="Items are not equal:", verbose=True, names="('ACTUAL', 'DESIRED')"): 40540 """None""" 40541 return None 40542 def decorate_methods(cls, decorator=None, testmatch=None): 40543 """ 40544 Apply a decorator to all methods in a class matching a regular expression. 40545 40546 The given decorator is applied to all public methods of `cls` that are 40547 matched by the regular expression `testmatch` 40548 (``testmatch.search(methodname)``). Methods that are private, i.e. start 40549 with an underscore, are ignored. 40550 40551 Parameters 40552 ---------- 40553 cls : class 40554 Class whose methods to decorate. 40555 decorator : function 40556 Decorator to apply to methods 40557 testmatch : compiled regexp or str, optional 40558 The regular expression. Default value is None, in which case the 40559 nose default (``re.compile(r'(?:^|[\b_\.%s-])[Tt]est' % os.sep)``) 40560 is used. 40561 If `testmatch` is a string, it is compiled to a regular expression 40562 first. 40563 40564 """ 40565 return None 40566 division = instance() 40567 def importall(self, _): 40568 """ 40569 `importall` is DEPRECATED and will be removed in numpy 1.9.0 40570 40571 Try recursively to import all subpackages under package. 40572 """ 40573 return None 40574 def jiffies(self, _proc_pid_stat="/proc/405/stat", _load_time="[]"): 40575 """ Return number of jiffies (1/100ths of a second) that this 40576 process has been scheduled in user mode. See man 5 proc. """ 40577 return None 40578 def measure(self, code_str=None, times=1, label=None): 40579 """ 40580 Return elapsed time for executing code in the namespace of the caller. 40581 40582 The supplied code string is compiled with the Python builtin ``compile``. 40583 The precision of the timing is 10 milli-seconds. If the code will execute 40584 fast on this timescale, it can be executed many times to get reasonable 40585 timing accuracy. 40586 40587 Parameters 40588 ---------- 40589 code_str : str 40590 The code to be timed. 40591 times : int, optional 40592 The number of times the code is executed. Default is 1. The code is 40593 only compiled once. 40594 label : str, optional 40595 A label to identify `code_str` with. This is passed into ``compile`` 40596 as the second argument (for run-time error messages). 40597 40598 Returns 40599 ------- 40600 elapsed : float 40601 Total elapsed time in seconds for executing `code_str` `times` times. 40602 40603 Examples 40604 -------- 40605 >>> etime = np.testing.measure('for i in range(1000): np.sqrt(i**2)', 40606 ... times=times) 40607 >>> print "Time for a single execution : ", etime / times, "s" 40608 Time for a single execution : 0.005 s 40609 40610 """ 40611 return float() 40612 def memusage(self, _proc_pid_stat="/proc/405/stat"): 40613 """ Return virtual memory size in bytes of the running python. 40614 """ 40615 return None 40616 def print_assert_equal(self, test_string, actual, desired): 40617 """ 40618 Test if two objects are equal, and print an error message if test fails. 40619 40620 The test is performed with ``actual == desired``. 40621 40622 Parameters 40623 ---------- 40624 test_string : str 40625 The message supplied to AssertionError. 40626 actual : object 40627 The object to test for equality against `desired`. 40628 desired : object 40629 The expected result. 40630 40631 Examples 40632 -------- 40633 >>> np.testing.print_assert_equal('Test XYZ of func xyz', [0, 1], [0, 1]) 40634 >>> np.testing.print_assert_equal('Test XYZ of func xyz', [0, 1], [0, 2]) 40635 Traceback (most recent call last): 40636 ... 40637 AssertionError: Test XYZ of func xyz failed 40638 ACTUAL: 40639 [0, 1] 40640 DESIRED: 40641 [0, 2] 40642 40643 """ 40644 return None 40645 print_function = instance() 40646 def _raises(self): 40647 """None""" 40648 return None 40649 def rand(self): 40650 """Returns an array of random numbers with the given shape. 40651 40652 This only uses the standard library, so it is useful for testing purposes. 40653 """ 40654 return None 40655 def run_module_suite(self, file_to_run=None): 40656 """None""" 40657 return None 40658 def rundocs(self, filename=None, raise_on_error=True): 40659 """ 40660 Run doctests found in the given file. 40661 40662 By default `rundocs` raises an AssertionError on failure. 40663 40664 Parameters 40665 ---------- 40666 filename : str 40667 The path to the file for which the doctests are run. 40668 raise_on_error : bool 40669 Whether to raise an AssertionError when a doctest fails. Default is 40670 True. 40671 40672 Notes 40673 ----- 40674 The doctests can be run by the user/developer by adding the ``doctests`` 40675 argument to the ``test()`` call. For example, to run all tests (including 40676 doctests) for `numpy.lib`: 40677 40678 >>> np.lib.test(doctests=True) #doctest: +SKIP 40679 """ 40680 return None 40681 def runstring(self, _): 40682 """None""" 40683 return None 40684 def test(self=None, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None): 40685 """ 40686 Run tests for module using nose. 40687 40688 Parameters 40689 ---------- 40690 label : {'fast', 'full', '', attribute identifier}, optional 40691 Identifies the tests to run. This can be a string to pass to 40692 the nosetests executable with the '-A' option, or one of several 40693 special values. Special values are: 40694 * 'fast' - the default - which corresponds to the ``nosetests -A`` 40695 option of 'not slow'. 40696 * 'full' - fast (as above) and slow tests as in the 40697 'no -A' option to nosetests - this is the same as ''. 40698 * None or '' - run all tests. 40699 attribute_identifier - string passed directly to nosetests as '-A'. 40700 verbose : int, optional 40701 Verbosity value for test outputs, in the range 1-10. Default is 1. 40702 extra_argv : list, optional 40703 List with any extra arguments to pass to nosetests. 40704 doctests : bool, optional 40705 If True, run doctests in module. Default is False. 40706 coverage : bool, optional 40707 If True, report coverage of NumPy code. Default is False. 40708 (This requires the `coverage module: 40709 <http://nedbatchelder.com/code/modules/coverage.html>`_). 40710 raise_warnings : str or sequence of warnings, optional 40711 This specifies which warnings to configure as 'raise' instead 40712 of 'warn' during the test execution. Valid strings are: 40713 40714 - "develop" : equals ``(DeprecationWarning, RuntimeWarning)`` 40715 - "release" : equals ``()``, don't raise on any warnings. 40716 40717 Returns 40718 ------- 40719 result : object 40720 Returns the result of running the tests as a 40721 ``nose.result.TextTestResult`` object. 40722 40723 Notes 40724 ----- 40725 Each NumPy module exposes `test` in its namespace to run all tests for it. 40726 For example, to run all tests for numpy.lib: 40727 40728 >>> np.lib.test() #doctest: +SKIP 40729 40730 Examples 40731 -------- 40732 >>> result = np.lib.test() #doctest: +SKIP 40733 Running unit tests for numpy.lib 40734 ... 40735 Ran 976 tests in 3.933s 40736 40737 OK 40738 40739 >>> result.errors #doctest: +SKIP 40740 [] 40741 >>> result.knownfail #doctest: +SKIP 40742 [] 40743 """ 40744 return object() 40745 verbose = int() 40746 class random: 40747 class RandomState: 40748 __doc__ = str() 40749 def beta(self, a, b, size): 40750 """ 40751 beta(a, b, size=None) 40752 40753 The Beta distribution over ``[0, 1]``. 40754 40755 The Beta distribution is a special case of the Dirichlet distribution, 40756 and is related to the Gamma distribution. It has the probability 40757 distribution function 40758 40759 .. math:: f(x; a,b) = \frac{1}{B(\alpha, \beta)} x^{\alpha - 1} 40760 (1 - x)^{\beta - 1}, 40761 40762 where the normalisation, B, is the beta function, 40763 40764 .. math:: B(\alpha, \beta) = \int_0^1 t^{\alpha - 1} 40765 (1 - t)^{\beta - 1} dt. 40766 40767 It is often seen in Bayesian inference and order statistics. 40768 40769 Parameters 40770 ---------- 40771 a : float 40772 Alpha, non-negative. 40773 b : float 40774 Beta, non-negative. 40775 size : tuple of ints, optional 40776 The number of samples to draw. The output is packed according to 40777 the size given. 40778 40779 Returns 40780 ------- 40781 out : ndarray 40782 Array of the given shape, containing values drawn from a 40783 Beta distribution. 40784 40785 """ 40786 return ndarray() 40787 def binomial(self, n, p, size): 40788 """ 40789 binomial(n, p, size=None) 40790 40791 Draw samples from a binomial distribution. 40792 40793 Samples are drawn from a Binomial distribution with specified 40794 parameters, n trials and p probability of success where 40795 n an integer >= 0 and p is in the interval [0,1]. (n may be 40796 input as a float, but it is truncated to an integer in use) 40797 40798 Parameters 40799 ---------- 40800 n : float (but truncated to an integer) 40801 parameter, >= 0. 40802 p : float 40803 parameter, >= 0 and <=1. 40804 size : {tuple, int} 40805 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 40806 ``m * n * k`` samples are drawn. 40807 40808 Returns 40809 ------- 40810 samples : {ndarray, scalar} 40811 where the values are all integers in [0, n]. 40812 40813 See Also 40814 -------- 40815 scipy.stats.distributions.binom : probability density function, 40816 distribution or cumulative density function, etc. 40817 40818 Notes 40819 ----- 40820 The probability density for the Binomial distribution is 40821 40822 .. math:: P(N) = \binom{n}{N}p^N(1-p)^{n-N}, 40823 40824 where :math:`n` is the number of trials, :math:`p` is the probability 40825 of success, and :math:`N` is the number of successes. 40826 40827 When estimating the standard error of a proportion in a population by 40828 using a random sample, the normal distribution works well unless the 40829 product p*n <=5, where p = population proportion estimate, and n = 40830 number of samples, in which case the binomial distribution is used 40831 instead. For example, a sample of 15 people shows 4 who are left 40832 handed, and 11 who are right handed. Then p = 4/15 = 27%. 0.27*15 = 4, 40833 so the binomial distribution should be used in this case. 40834 40835 References 40836 ---------- 40837 .. [1] Dalgaard, Peter, "Introductory Statistics with R", 40838 Springer-Verlag, 2002. 40839 .. [2] Glantz, Stanton A. "Primer of Biostatistics.", McGraw-Hill, 40840 Fifth Edition, 2002. 40841 .. [3] Lentner, Marvin, "Elementary Applied Statistics", Bogden 40842 and Quigley, 1972. 40843 .. [4] Weisstein, Eric W. "Binomial Distribution." From MathWorld--A 40844 Wolfram Web Resource. 40845 http://mathworld.wolfram.com/BinomialDistribution.html 40846 .. [5] Wikipedia, "Binomial-distribution", 40847 http://en.wikipedia.org/wiki/Binomial_distribution 40848 40849 Examples 40850 -------- 40851 Draw samples from the distribution: 40852 40853 >>> n, p = 10, .5 # number of trials, probability of each trial 40854 >>> s = np.random.binomial(n, p, 1000) 40855 # result of flipping a coin 10 times, tested 1000 times. 40856 40857 A real world example. A company drills 9 wild-cat oil exploration 40858 wells, each with an estimated probability of success of 0.1. All nine 40859 wells fail. What is the probability of that happening? 40860 40861 Let's do 20,000 trials of the model, and count the number that 40862 generate zero positive results. 40863 40864 >>> sum(np.random.binomial(9,0.1,20000)==0)/20000. 40865 answer = 0.38885, or 38%. 40866 40867 """ 40868 return ndarray() 40869 def bytes(self, length): 40870 """ 40871 bytes(length) 40872 40873 Return random bytes. 40874 40875 Parameters 40876 ---------- 40877 length : int 40878 Number of random bytes. 40879 40880 Returns 40881 ------- 40882 out : str 40883 String of length `length`. 40884 40885 Examples 40886 -------- 40887 >>> np.random.bytes(10) 40888 ' eh\x85\x022SZ\xbf\xa4' #random 40889 40890 """ 40891 return str() 40892 def chisquare(self, df, size): 40893 """ 40894 chisquare(df, size=None) 40895 40896 Draw samples from a chi-square distribution. 40897 40898 When `df` independent random variables, each with standard normal 40899 distributions (mean 0, variance 1), are squared and summed, the 40900 resulting distribution is chi-square (see Notes). This distribution 40901 is often used in hypothesis testing. 40902 40903 Parameters 40904 ---------- 40905 df : int 40906 Number of degrees of freedom. 40907 size : tuple of ints, int, optional 40908 Size of the returned array. By default, a scalar is 40909 returned. 40910 40911 Returns 40912 ------- 40913 output : ndarray 40914 Samples drawn from the distribution, packed in a `size`-shaped 40915 array. 40916 40917 Raises 40918 ------ 40919 ValueError 40920 When `df` <= 0 or when an inappropriate `size` (e.g. ``size=-1``) 40921 is given. 40922 40923 Notes 40924 ----- 40925 The variable obtained by summing the squares of `df` independent, 40926 standard normally distributed random variables: 40927 40928 .. math:: Q = \sum_{i=0}^{\mathtt{df}} X^2_i 40929 40930 is chi-square distributed, denoted 40931 40932 .. math:: Q \sim \chi^2_k. 40933 40934 The probability density function of the chi-squared distribution is 40935 40936 .. math:: p(x) = \frac{(1/2)^{k/2}}{\Gamma(k/2)} 40937 x^{k/2 - 1} e^{-x/2}, 40938 40939 where :math:`\Gamma` is the gamma function, 40940 40941 .. math:: \Gamma(x) = \int_0^{-\infty} t^{x - 1} e^{-t} dt. 40942 40943 References 40944 ---------- 40945 `NIST/SEMATECH e-Handbook of Statistical Methods 40946 <http://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm>`_ 40947 40948 Examples 40949 -------- 40950 >>> np.random.chisquare(2,4) 40951 array([ 1.89920014, 9.00867716, 3.13710533, 5.62318272]) 40952 40953 """ 40954 return ndarray() 40955 def choice(self, a, size, replace, p): 40956 """ 40957 choice(a, size=None, replace=True, p=None) 40958 40959 Generates a random sample from a given 1-D array 40960 40961 .. versionadded:: 1.7.0 40962 40963 Parameters 40964 ----------- 40965 a : 1-D array-like or int 40966 If an ndarray, a random sample is generated from its elements. 40967 If an int, the random sample is generated as if a was np.arange(n) 40968 size : int or tuple of ints, optional 40969 Output shape. Default is None, in which case a single value is 40970 returned. 40971 replace : boolean, optional 40972 Whether the sample is with or without replacement 40973 p : 1-D array-like, optional 40974 The probabilities associated with each entry in a. 40975 If not given the sample assumes a uniform distribtion over all 40976 entries in a. 40977 40978 Returns 40979 -------- 40980 samples : 1-D ndarray, shape (size,) 40981 The generated random samples 40982 40983 Raises 40984 ------- 40985 ValueError 40986 If a is an int and less than zero, if a or p are not 1-dimensional, 40987 if a is an array-like of size 0, if p is not a vector of 40988 probabilities, if a and p have different lengths, or if 40989 replace=False and the sample size is greater than the population 40990 size 40991 40992 See Also 40993 --------- 40994 randint, shuffle, permutation 40995 40996 Examples 40997 --------- 40998 Generate a uniform random sample from np.arange(5) of size 3: 40999 41000 >>> np.random.choice(5, 3) 41001 array([0, 3, 4]) 41002 >>> #This is equivalent to np.random.randint(0,5,3) 41003 41004 Generate a non-uniform random sample from np.arange(5) of size 3: 41005 41006 >>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0]) 41007 array([3, 3, 0]) 41008 41009 Generate a uniform random sample from np.arange(5) of size 3 without 41010 replacement: 41011 41012 >>> np.random.choice(5, 3, replace=False) 41013 array([3,1,0]) 41014 >>> #This is equivalent to np.random.shuffle(np.arange(5))[:3] 41015 41016 Generate a non-uniform random sample from np.arange(5) of size 41017 3 without replacement: 41018 41019 >>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0]) 41020 array([2, 3, 0]) 41021 41022 Any of the above can be repeated with an arbitrary array-like 41023 instead of just integers. For instance: 41024 41025 >>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher'] 41026 >>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3]) 41027 array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'], 41028 dtype='|S11') 41029 41030 """ 41031 return _1_D() 41032 def dirichlet(self, alpha, size): 41033 """ 41034 dirichlet(alpha, size=None) 41035 41036 Draw samples from the Dirichlet distribution. 41037 41038 Draw `size` samples of dimension k from a Dirichlet distribution. A 41039 Dirichlet-distributed random variable can be seen as a multivariate 41040 generalization of a Beta distribution. Dirichlet pdf is the conjugate 41041 prior of a multinomial in Bayesian inference. 41042 41043 Parameters 41044 ---------- 41045 alpha : array 41046 Parameter of the distribution (k dimension for sample of 41047 dimension k). 41048 size : array 41049 Number of samples to draw. 41050 41051 Returns 41052 ------- 41053 samples : ndarray, 41054 The drawn samples, of shape (alpha.ndim, size). 41055 41056 Notes 41057 ----- 41058 .. math:: X \approx \prod_{i=1}^{k}{x^{\alpha_i-1}_i} 41059 41060 Uses the following property for computation: for each dimension, 41061 draw a random sample y_i from a standard gamma generator of shape 41062 `alpha_i`, then 41063 :math:`X = \frac{1}{\sum_{i=1}^k{y_i}} (y_1, \ldots, y_n)` is 41064 Dirichlet distributed. 41065 41066 References 41067 ---------- 41068 .. [1] David McKay, "Information Theory, Inference and Learning 41069 Algorithms," chapter 23, 41070 http://www.inference.phy.cam.ac.uk/mackay/ 41071 .. [2] Wikipedia, "Dirichlet distribution", 41072 http://en.wikipedia.org/wiki/Dirichlet_distribution 41073 41074 Examples 41075 -------- 41076 Taking an example cited in Wikipedia, this distribution can be used if 41077 one wanted to cut strings (each of initial length 1.0) into K pieces 41078 with different lengths, where each piece had, on average, a designated 41079 average length, but allowing some variation in the relative sizes of the 41080 pieces. 41081 41082 >>> s = np.random.dirichlet((10, 5, 3), 20).transpose() 41083 41084 >>> plt.barh(range(20), s[0]) 41085 >>> plt.barh(range(20), s[1], left=s[0], color='g') 41086 >>> plt.barh(range(20), s[2], left=s[0]+s[1], color='r') 41087 >>> plt.title("Lengths of Strings") 41088 41089 """ 41090 return ndarray() 41091 def exponential(self, scale, size): 41092 """ 41093 exponential(scale=1.0, size=None) 41094 41095 Exponential distribution. 41096 41097 Its probability density function is 41098 41099 .. math:: f(x; \frac{1}{\beta}) = \frac{1}{\beta} \exp(-\frac{x}{\beta}), 41100 41101 for ``x > 0`` and 0 elsewhere. :math:`\beta` is the scale parameter, 41102 which is the inverse of the rate parameter :math:`\lambda = 1/\beta`. 41103 The rate parameter is an alternative, widely used parameterization 41104 of the exponential distribution [3]_. 41105 41106 The exponential distribution is a continuous analogue of the 41107 geometric distribution. It describes many common situations, such as 41108 the size of raindrops measured over many rainstorms [1]_, or the time 41109 between page requests to Wikipedia [2]_. 41110 41111 Parameters 41112 ---------- 41113 scale : float 41114 The scale parameter, :math:`\beta = 1/\lambda`. 41115 size : tuple of ints 41116 Number of samples to draw. The output is shaped 41117 according to `size`. 41118 41119 References 41120 ---------- 41121 .. [1] Peyton Z. Peebles Jr., "Probability, Random Variables and 41122 Random Signal Principles", 4th ed, 2001, p. 57. 41123 .. [2] "Poisson Process", Wikipedia, 41124 http://en.wikipedia.org/wiki/Poisson_process 41125 .. [3] "Exponential Distribution, Wikipedia, 41126 http://en.wikipedia.org/wiki/Exponential_distribution 41127 41128 """ 41129 return None 41130 def f(self, dfnum, dfden, size): 41131 """ 41132 f(dfnum, dfden, size=None) 41133 41134 Draw samples from a F distribution. 41135 41136 Samples are drawn from an F distribution with specified parameters, 41137 `dfnum` (degrees of freedom in numerator) and `dfden` (degrees of freedom 41138 in denominator), where both parameters should be greater than zero. 41139 41140 The random variate of the F distribution (also known as the 41141 Fisher distribution) is a continuous probability distribution 41142 that arises in ANOVA tests, and is the ratio of two chi-square 41143 variates. 41144 41145 Parameters 41146 ---------- 41147 dfnum : float 41148 Degrees of freedom in numerator. Should be greater than zero. 41149 dfden : float 41150 Degrees of freedom in denominator. Should be greater than zero. 41151 size : {tuple, int}, optional 41152 Output shape. If the given shape is, e.g., ``(m, n, k)``, 41153 then ``m * n * k`` samples are drawn. By default only one sample 41154 is returned. 41155 41156 Returns 41157 ------- 41158 samples : {ndarray, scalar} 41159 Samples from the Fisher distribution. 41160 41161 See Also 41162 -------- 41163 scipy.stats.distributions.f : probability density function, 41164 distribution or cumulative density function, etc. 41165 41166 Notes 41167 ----- 41168 The F statistic is used to compare in-group variances to between-group 41169 variances. Calculating the distribution depends on the sampling, and 41170 so it is a function of the respective degrees of freedom in the 41171 problem. The variable `dfnum` is the number of samples minus one, the 41172 between-groups degrees of freedom, while `dfden` is the within-groups 41173 degrees of freedom, the sum of the number of samples in each group 41174 minus the number of groups. 41175 41176 References 41177 ---------- 41178 .. [1] Glantz, Stanton A. "Primer of Biostatistics.", McGraw-Hill, 41179 Fifth Edition, 2002. 41180 .. [2] Wikipedia, "F-distribution", 41181 http://en.wikipedia.org/wiki/F-distribution 41182 41183 Examples 41184 -------- 41185 An example from Glantz[1], pp 47-40. 41186 Two groups, children of diabetics (25 people) and children from people 41187 without diabetes (25 controls). Fasting blood glucose was measured, 41188 case group had a mean value of 86.1, controls had a mean value of 41189 82.2. Standard deviations were 2.09 and 2.49 respectively. Are these 41190 data consistent with the null hypothesis that the parents diabetic 41191 status does not affect their children's blood glucose levels? 41192 Calculating the F statistic from the data gives a value of 36.01. 41193 41194 Draw samples from the distribution: 41195 41196 >>> dfnum = 1. # between group degrees of freedom 41197 >>> dfden = 48. # within groups degrees of freedom 41198 >>> s = np.random.f(dfnum, dfden, 1000) 41199 41200 The lower bound for the top 1% of the samples is : 41201 41202 >>> sort(s)[-10] 41203 7.61988120985 41204 41205 So there is about a 1% chance that the F statistic will exceed 7.62, 41206 the measured value is 36, so the null hypothesis is rejected at the 1% 41207 level. 41208 41209 """ 41210 return ndarray() 41211 def gamma(self, shape, scale, size): 41212 """ 41213 gamma(shape, scale=1.0, size=None) 41214 41215 Draw samples from a Gamma distribution. 41216 41217 Samples are drawn from a Gamma distribution with specified parameters, 41218 `shape` (sometimes designated "k") and `scale` (sometimes designated 41219 "theta"), where both parameters are > 0. 41220 41221 Parameters 41222 ---------- 41223 shape : scalar > 0 41224 The shape of the gamma distribution. 41225 scale : scalar > 0, optional 41226 The scale of the gamma distribution. Default is equal to 1. 41227 size : shape_tuple, optional 41228 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 41229 ``m * n * k`` samples are drawn. 41230 41231 Returns 41232 ------- 41233 out : ndarray, float 41234 Returns one sample unless `size` parameter is specified. 41235 41236 See Also 41237 -------- 41238 scipy.stats.distributions.gamma : probability density function, 41239 distribution or cumulative density function, etc. 41240 41241 Notes 41242 ----- 41243 The probability density for the Gamma distribution is 41244 41245 .. math:: p(x) = x^{k-1}\frac{e^{-x/\theta}}{\theta^k\Gamma(k)}, 41246 41247 where :math:`k` is the shape and :math:`\theta` the scale, 41248 and :math:`\Gamma` is the Gamma function. 41249 41250 The Gamma distribution is often used to model the times to failure of 41251 electronic components, and arises naturally in processes for which the 41252 waiting times between Poisson distributed events are relevant. 41253 41254 References 41255 ---------- 41256 .. [1] Weisstein, Eric W. "Gamma Distribution." From MathWorld--A 41257 Wolfram Web Resource. 41258 http://mathworld.wolfram.com/GammaDistribution.html 41259 .. [2] Wikipedia, "Gamma-distribution", 41260 http://en.wikipedia.org/wiki/Gamma-distribution 41261 41262 Examples 41263 -------- 41264 Draw samples from the distribution: 41265 41266 >>> shape, scale = 2., 2. # mean and dispersion 41267 >>> s = np.random.gamma(shape, scale, 1000) 41268 41269 Display the histogram of the samples, along with 41270 the probability density function: 41271 41272 >>> import matplotlib.pyplot as plt 41273 >>> import scipy.special as sps 41274 >>> count, bins, ignored = plt.hist(s, 50, normed=True) 41275 >>> y = bins**(shape-1)*(np.exp(-bins/scale) / 41276 ... (sps.gamma(shape)*scale**shape)) 41277 >>> plt.plot(bins, y, linewidth=2, color='r') 41278 >>> plt.show() 41279 41280 """ 41281 return ndarray() 41282 def geometric(self, p, size): 41283 """ 41284 geometric(p, size=None) 41285 41286 Draw samples from the geometric distribution. 41287 41288 Bernoulli trials are experiments with one of two outcomes: 41289 success or failure (an example of such an experiment is flipping 41290 a coin). The geometric distribution models the number of trials 41291 that must be run in order to achieve success. It is therefore 41292 supported on the positive integers, ``k = 1, 2, ...``. 41293 41294 The probability mass function of the geometric distribution is 41295 41296 .. math:: f(k) = (1 - p)^{k - 1} p 41297 41298 where `p` is the probability of success of an individual trial. 41299 41300 Parameters 41301 ---------- 41302 p : float 41303 The probability of success of an individual trial. 41304 size : tuple of ints 41305 Number of values to draw from the distribution. The output 41306 is shaped according to `size`. 41307 41308 Returns 41309 ------- 41310 out : ndarray 41311 Samples from the geometric distribution, shaped according to 41312 `size`. 41313 41314 Examples 41315 -------- 41316 Draw ten thousand values from the geometric distribution, 41317 with the probability of an individual success equal to 0.35: 41318 41319 >>> z = np.random.geometric(p=0.35, size=10000) 41320 41321 How many trials succeeded after a single run? 41322 41323 >>> (z == 1).sum() / 10000. 41324 0.34889999999999999 #random 41325 41326 """ 41327 return ndarray() 41328 def get_state(self, _): 41329 """ 41330 get_state() 41331 41332 Return a tuple representing the internal state of the generator. 41333 41334 For more details, see `set_state`. 41335 41336 Returns 41337 ------- 41338 out : tuple(str, ndarray of 624 uints, int, int, float) 41339 The returned tuple has the following items: 41340 41341 1. the string 'MT19937'. 41342 2. a 1-D array of 624 unsigned integer keys. 41343 3. an integer ``pos``. 41344 4. an integer ``has_gauss``. 41345 5. a float ``cached_gaussian``. 41346 41347 See Also 41348 -------- 41349 set_state 41350 41351 Notes 41352 ----- 41353 `set_state` and `get_state` are not needed to work with any of the 41354 random distributions in NumPy. If the internal state is manually altered, 41355 the user should know exactly what he/she is doing. 41356 41357 """ 41358 return None 41359 def gumbel(self, loc, scale, size): 41360 """ 41361 gumbel(loc=0.0, scale=1.0, size=None) 41362 41363 Gumbel distribution. 41364 41365 Draw samples from a Gumbel distribution with specified location and scale. 41366 For more information on the Gumbel distribution, see Notes and References 41367 below. 41368 41369 Parameters 41370 ---------- 41371 loc : float 41372 The location of the mode of the distribution. 41373 scale : float 41374 The scale parameter of the distribution. 41375 size : tuple of ints 41376 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 41377 ``m * n * k`` samples are drawn. 41378 41379 Returns 41380 ------- 41381 out : ndarray 41382 The samples 41383 41384 See Also 41385 -------- 41386 scipy.stats.gumbel_l 41387 scipy.stats.gumbel_r 41388 scipy.stats.genextreme 41389 probability density function, distribution, or cumulative density 41390 function, etc. for each of the above 41391 weibull 41392 41393 Notes 41394 ----- 41395 The Gumbel (or Smallest Extreme Value (SEV) or the Smallest Extreme Value 41396 Type I) distribution is one of a class of Generalized Extreme Value (GEV) 41397 distributions used in modeling extreme value problems. The Gumbel is a 41398 special case of the Extreme Value Type I distribution for maximums from 41399 distributions with "exponential-like" tails. 41400 41401 The probability density for the Gumbel distribution is 41402 41403 .. math:: p(x) = \frac{e^{-(x - \mu)/ \beta}}{\beta} e^{ -e^{-(x - \mu)/ 41404 \beta}}, 41405 41406 where :math:`\mu` is the mode, a location parameter, and :math:`\beta` is 41407 the scale parameter. 41408 41409 The Gumbel (named for German mathematician Emil Julius Gumbel) was used 41410 very early in the hydrology literature, for modeling the occurrence of 41411 flood events. It is also used for modeling maximum wind speed and rainfall 41412 rates. It is a "fat-tailed" distribution - the probability of an event in 41413 the tail of the distribution is larger than if one used a Gaussian, hence 41414 the surprisingly frequent occurrence of 100-year floods. Floods were 41415 initially modeled as a Gaussian process, which underestimated the frequency 41416 of extreme events. 41417 41418 41419 It is one of a class of extreme value distributions, the Generalized 41420 Extreme Value (GEV) distributions, which also includes the Weibull and 41421 Frechet. 41422 41423 The function has a mean of :math:`\mu + 0.57721\beta` and a variance of 41424 :math:`\frac{\pi^2}{6}\beta^2`. 41425 41426 References 41427 ---------- 41428 Gumbel, E. J., *Statistics of Extremes*, New York: Columbia University 41429 Press, 1958. 41430 41431 Reiss, R.-D. and Thomas, M., *Statistical Analysis of Extreme Values from 41432 Insurance, Finance, Hydrology and Other Fields*, Basel: Birkhauser Verlag, 41433 2001. 41434 41435 Examples 41436 -------- 41437 Draw samples from the distribution: 41438 41439 >>> mu, beta = 0, 0.1 # location and scale 41440 >>> s = np.random.gumbel(mu, beta, 1000) 41441 41442 Display the histogram of the samples, along with 41443 the probability density function: 41444 41445 >>> import matplotlib.pyplot as plt 41446 >>> count, bins, ignored = plt.hist(s, 30, normed=True) 41447 >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta) 41448 ... * np.exp( -np.exp( -(bins - mu) /beta) ), 41449 ... linewidth=2, color='r') 41450 >>> plt.show() 41451 41452 Show how an extreme value distribution can arise from a Gaussian process 41453 and compare to a Gaussian: 41454 41455 >>> means = [] 41456 >>> maxima = [] 41457 >>> for i in range(0,1000) : 41458 ... a = np.random.normal(mu, beta, 1000) 41459 ... means.append(a.mean()) 41460 ... maxima.append(a.max()) 41461 >>> count, bins, ignored = plt.hist(maxima, 30, normed=True) 41462 >>> beta = np.std(maxima)*np.pi/np.sqrt(6) 41463 >>> mu = np.mean(maxima) - 0.57721*beta 41464 >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta) 41465 ... * np.exp(-np.exp(-(bins - mu)/beta)), 41466 ... linewidth=2, color='r') 41467 >>> plt.plot(bins, 1/(beta * np.sqrt(2 * np.pi)) 41468 ... * np.exp(-(bins - mu)**2 / (2 * beta**2)), 41469 ... linewidth=2, color='g') 41470 >>> plt.show() 41471 41472 """ 41473 return ndarray() 41474 def hypergeometric(self, ngood, nbad, nsample, size): 41475 """ 41476 hypergeometric(ngood, nbad, nsample, size=None) 41477 41478 Draw samples from a Hypergeometric distribution. 41479 41480 Samples are drawn from a Hypergeometric distribution with specified 41481 parameters, ngood (ways to make a good selection), nbad (ways to make 41482 a bad selection), and nsample = number of items sampled, which is less 41483 than or equal to the sum ngood + nbad. 41484 41485 Parameters 41486 ---------- 41487 ngood : int or array_like 41488 Number of ways to make a good selection. Must be nonnegative. 41489 nbad : int or array_like 41490 Number of ways to make a bad selection. Must be nonnegative. 41491 nsample : int or array_like 41492 Number of items sampled. Must be at least 1 and at most 41493 ``ngood + nbad``. 41494 size : int or tuple of int 41495 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 41496 ``m * n * k`` samples are drawn. 41497 41498 Returns 41499 ------- 41500 samples : ndarray or scalar 41501 The values are all integers in [0, n]. 41502 41503 See Also 41504 -------- 41505 scipy.stats.distributions.hypergeom : probability density function, 41506 distribution or cumulative density function, etc. 41507 41508 Notes 41509 ----- 41510 The probability density for the Hypergeometric distribution is 41511 41512 .. math:: P(x) = \frac{\binom{m}{n}\binom{N-m}{n-x}}{\binom{N}{n}}, 41513 41514 where :math:`0 \le x \le m` and :math:`n+m-N \le x \le n` 41515 41516 for P(x) the probability of x successes, n = ngood, m = nbad, and 41517 N = number of samples. 41518 41519 Consider an urn with black and white marbles in it, ngood of them 41520 black and nbad are white. If you draw nsample balls without 41521 replacement, then the Hypergeometric distribution describes the 41522 distribution of black balls in the drawn sample. 41523 41524 Note that this distribution is very similar to the Binomial 41525 distribution, except that in this case, samples are drawn without 41526 replacement, whereas in the Binomial case samples are drawn with 41527 replacement (or the sample space is infinite). As the sample space 41528 becomes large, this distribution approaches the Binomial. 41529 41530 References 41531 ---------- 41532 .. [1] Lentner, Marvin, "Elementary Applied Statistics", Bogden 41533 and Quigley, 1972. 41534 .. [2] Weisstein, Eric W. "Hypergeometric Distribution." From 41535 MathWorld--A Wolfram Web Resource. 41536 http://mathworld.wolfram.com/HypergeometricDistribution.html 41537 .. [3] Wikipedia, "Hypergeometric-distribution", 41538 http://en.wikipedia.org/wiki/Hypergeometric-distribution 41539 41540 Examples 41541 -------- 41542 Draw samples from the distribution: 41543 41544 >>> ngood, nbad, nsamp = 100, 2, 10 41545 # number of good, number of bad, and number of samples 41546 >>> s = np.random.hypergeometric(ngood, nbad, nsamp, 1000) 41547 >>> hist(s) 41548 # note that it is very unlikely to grab both bad items 41549 41550 Suppose you have an urn with 15 white and 15 black marbles. 41551 If you pull 15 marbles at random, how likely is it that 41552 12 or more of them are one color? 41553 41554 >>> s = np.random.hypergeometric(15, 15, 15, 100000) 41555 >>> sum(s>=12)/100000. + sum(s<=3)/100000. 41556 # answer = 0.003 ... pretty unlikely! 41557 41558 """ 41559 return ndarray() if False else float() 41560 def laplace(self, loc, scale): 41561 """ 41562 laplace(loc=0.0, scale=1.0, size=None) 41563 41564 Draw samples from the Laplace or double exponential distribution with 41565 specified location (or mean) and scale (decay). 41566 41567 The Laplace distribution is similar to the Gaussian/normal distribution, 41568 but is sharper at the peak and has fatter tails. It represents the 41569 difference between two independent, identically distributed exponential 41570 random variables. 41571 41572 Parameters 41573 ---------- 41574 loc : float 41575 The position, :math:`\mu`, of the distribution peak. 41576 scale : float 41577 :math:`\lambda`, the exponential decay. 41578 41579 Notes 41580 ----- 41581 It has the probability density function 41582 41583 .. math:: f(x; \mu, \lambda) = \frac{1}{2\lambda} 41584 \exp\left(-\frac{|x - \mu|}{\lambda}\right). 41585 41586 The first law of Laplace, from 1774, states that the frequency of an error 41587 can be expressed as an exponential function of the absolute magnitude of 41588 the error, which leads to the Laplace distribution. For many problems in 41589 Economics and Health sciences, this distribution seems to model the data 41590 better than the standard Gaussian distribution 41591 41592 41593 References 41594 ---------- 41595 .. [1] Abramowitz, M. and Stegun, I. A. (Eds.). Handbook of Mathematical 41596 Functions with Formulas, Graphs, and Mathematical Tables, 9th 41597 printing. New York: Dover, 1972. 41598 41599 .. [2] The Laplace distribution and generalizations 41600 By Samuel Kotz, Tomasz J. Kozubowski, Krzysztof Podgorski, 41601 Birkhauser, 2001. 41602 41603 .. [3] Weisstein, Eric W. "Laplace Distribution." 41604 From MathWorld--A Wolfram Web Resource. 41605 http://mathworld.wolfram.com/LaplaceDistribution.html 41606 41607 .. [4] Wikipedia, "Laplace distribution", 41608 http://en.wikipedia.org/wiki/Laplace_distribution 41609 41610 Examples 41611 -------- 41612 Draw samples from the distribution 41613 41614 >>> loc, scale = 0., 1. 41615 >>> s = np.random.laplace(loc, scale, 1000) 41616 41617 Display the histogram of the samples, along with 41618 the probability density function: 41619 41620 >>> import matplotlib.pyplot as plt 41621 >>> count, bins, ignored = plt.hist(s, 30, normed=True) 41622 >>> x = np.arange(-8., 8., .01) 41623 >>> pdf = np.exp(-abs(x-loc/scale))/(2.*scale) 41624 >>> plt.plot(x, pdf) 41625 41626 Plot Gaussian for comparison: 41627 41628 >>> g = (1/(scale * np.sqrt(2 * np.pi)) * 41629 ... np.exp( - (x - loc)**2 / (2 * scale**2) )) 41630 >>> plt.plot(x,g) 41631 41632 """ 41633 return None 41634 def logistic(self, loc, scale, size): 41635 """ 41636 logistic(loc=0.0, scale=1.0, size=None) 41637 41638 Draw samples from a Logistic distribution. 41639 41640 Samples are drawn from a Logistic distribution with specified 41641 parameters, loc (location or mean, also median), and scale (>0). 41642 41643 Parameters 41644 ---------- 41645 loc : float 41646 41647 scale : float > 0. 41648 41649 size : {tuple, int} 41650 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 41651 ``m * n * k`` samples are drawn. 41652 41653 Returns 41654 ------- 41655 samples : {ndarray, scalar} 41656 where the values are all integers in [0, n]. 41657 41658 See Also 41659 -------- 41660 scipy.stats.distributions.logistic : probability density function, 41661 distribution or cumulative density function, etc. 41662 41663 Notes 41664 ----- 41665 The probability density for the Logistic distribution is 41666 41667 .. math:: P(x) = P(x) = \frac{e^{-(x-\mu)/s}}{s(1+e^{-(x-\mu)/s})^2}, 41668 41669 where :math:`\mu` = location and :math:`s` = scale. 41670 41671 The Logistic distribution is used in Extreme Value problems where it 41672 can act as a mixture of Gumbel distributions, in Epidemiology, and by 41673 the World Chess Federation (FIDE) where it is used in the Elo ranking 41674 system, assuming the performance of each player is a logistically 41675 distributed random variable. 41676 41677 References 41678 ---------- 41679 .. [1] Reiss, R.-D. and Thomas M. (2001), Statistical Analysis of Extreme 41680 Values, from Insurance, Finance, Hydrology and Other Fields, 41681 Birkhauser Verlag, Basel, pp 132-133. 41682 .. [2] Weisstein, Eric W. "Logistic Distribution." From 41683 MathWorld--A Wolfram Web Resource. 41684 http://mathworld.wolfram.com/LogisticDistribution.html 41685 .. [3] Wikipedia, "Logistic-distribution", 41686 http://en.wikipedia.org/wiki/Logistic-distribution 41687 41688 Examples 41689 -------- 41690 Draw samples from the distribution: 41691 41692 >>> loc, scale = 10, 1 41693 >>> s = np.random.logistic(loc, scale, 10000) 41694 >>> count, bins, ignored = plt.hist(s, bins=50) 41695 41696 # plot against distribution 41697 41698 >>> def logist(x, loc, scale): 41699 ... return exp((loc-x)/scale)/(scale*(1+exp((loc-x)/scale))**2) 41700 >>> plt.plot(bins, logist(bins, loc, scale)*count.max()/\ 41701 ... logist(bins, loc, scale).max()) 41702 >>> plt.show() 41703 41704 """ 41705 return ndarray() 41706 def lognormal(self, mean, sigma, size): 41707 """ 41708 lognormal(mean=0.0, sigma=1.0, size=None) 41709 41710 Return samples drawn from a log-normal distribution. 41711 41712 Draw samples from a log-normal distribution with specified mean, 41713 standard deviation, and array shape. Note that the mean and standard 41714 deviation are not the values for the distribution itself, but of the 41715 underlying normal distribution it is derived from. 41716 41717 Parameters 41718 ---------- 41719 mean : float 41720 Mean value of the underlying normal distribution 41721 sigma : float, > 0. 41722 Standard deviation of the underlying normal distribution 41723 size : tuple of ints 41724 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 41725 ``m * n * k`` samples are drawn. 41726 41727 Returns 41728 ------- 41729 samples : ndarray or float 41730 The desired samples. An array of the same shape as `size` if given, 41731 if `size` is None a float is returned. 41732 41733 See Also 41734 -------- 41735 scipy.stats.lognorm : probability density function, distribution, 41736 cumulative density function, etc. 41737 41738 Notes 41739 ----- 41740 A variable `x` has a log-normal distribution if `log(x)` is normally 41741 distributed. The probability density function for the log-normal 41742 distribution is: 41743 41744 .. math:: p(x) = \frac{1}{\sigma x \sqrt{2\pi}} 41745 e^{(-\frac{(ln(x)-\mu)^2}{2\sigma^2})} 41746 41747 where :math:`\mu` is the mean and :math:`\sigma` is the standard 41748 deviation of the normally distributed logarithm of the variable. 41749 A log-normal distribution results if a random variable is the *product* 41750 of a large number of independent, identically-distributed variables in 41751 the same way that a normal distribution results if the variable is the 41752 *sum* of a large number of independent, identically-distributed 41753 variables. 41754 41755 References 41756 ---------- 41757 Limpert, E., Stahel, W. A., and Abbt, M., "Log-normal Distributions 41758 across the Sciences: Keys and Clues," *BioScience*, Vol. 51, No. 5, 41759 May, 2001. http://stat.ethz.ch/~stahel/lognormal/bioscience.pdf 41760 41761 Reiss, R.D. and Thomas, M., *Statistical Analysis of Extreme Values*, 41762 Basel: Birkhauser Verlag, 2001, pp. 31-32. 41763 41764 Examples 41765 -------- 41766 Draw samples from the distribution: 41767 41768 >>> mu, sigma = 3., 1. # mean and standard deviation 41769 >>> s = np.random.lognormal(mu, sigma, 1000) 41770 41771 Display the histogram of the samples, along with 41772 the probability density function: 41773 41774 >>> import matplotlib.pyplot as plt 41775 >>> count, bins, ignored = plt.hist(s, 100, normed=True, align='mid') 41776 41777 >>> x = np.linspace(min(bins), max(bins), 10000) 41778 >>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)) 41779 ... / (x * sigma * np.sqrt(2 * np.pi))) 41780 41781 >>> plt.plot(x, pdf, linewidth=2, color='r') 41782 >>> plt.axis('tight') 41783 >>> plt.show() 41784 41785 Demonstrate that taking the products of random samples from a uniform 41786 distribution can be fit well by a log-normal probability density function. 41787 41788 >>> # Generate a thousand samples: each is the product of 100 random 41789 >>> # values, drawn from a normal distribution. 41790 >>> b = [] 41791 >>> for i in range(1000): 41792 ... a = 10. + np.random.random(100) 41793 ... b.append(np.product(a)) 41794 41795 >>> b = np.array(b) / np.min(b) # scale values to be positive 41796 >>> count, bins, ignored = plt.hist(b, 100, normed=True, align='center') 41797 >>> sigma = np.std(np.log(b)) 41798 >>> mu = np.mean(np.log(b)) 41799 41800 >>> x = np.linspace(min(bins), max(bins), 10000) 41801 >>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)) 41802 ... / (x * sigma * np.sqrt(2 * np.pi))) 41803 41804 >>> plt.plot(x, pdf, color='r', linewidth=2) 41805 >>> plt.show() 41806 41807 """ 41808 return ndarray() if False else float() 41809 def logseries(self, loc, scale, size): 41810 """ 41811 logseries(p, size=None) 41812 41813 Draw samples from a Logarithmic Series distribution. 41814 41815 Samples are drawn from a Log Series distribution with specified 41816 parameter, p (probability, 0 < p < 1). 41817 41818 Parameters 41819 ---------- 41820 loc : float 41821 41822 scale : float > 0. 41823 41824 size : {tuple, int} 41825 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 41826 ``m * n * k`` samples are drawn. 41827 41828 Returns 41829 ------- 41830 samples : {ndarray, scalar} 41831 where the values are all integers in [0, n]. 41832 41833 See Also 41834 -------- 41835 scipy.stats.distributions.logser : probability density function, 41836 distribution or cumulative density function, etc. 41837 41838 Notes 41839 ----- 41840 The probability density for the Log Series distribution is 41841 41842 .. math:: P(k) = \frac{-p^k}{k \ln(1-p)}, 41843 41844 where p = probability. 41845 41846 The Log Series distribution is frequently used to represent species 41847 richness and occurrence, first proposed by Fisher, Corbet, and 41848 Williams in 1943 [2]. It may also be used to model the numbers of 41849 occupants seen in cars [3]. 41850 41851 References 41852 ---------- 41853 .. [1] Buzas, Martin A.; Culver, Stephen J., Understanding regional 41854 species diversity through the log series distribution of 41855 occurrences: BIODIVERSITY RESEARCH Diversity & Distributions, 41856 Volume 5, Number 5, September 1999 , pp. 187-195(9). 41857 .. [2] Fisher, R.A,, A.S. Corbet, and C.B. Williams. 1943. The 41858 relation between the number of species and the number of 41859 individuals in a random sample of an animal population. 41860 Journal of Animal Ecology, 12:42-58. 41861 .. [3] D. J. Hand, F. Daly, D. Lunn, E. Ostrowski, A Handbook of Small 41862 Data Sets, CRC Press, 1994. 41863 .. [4] Wikipedia, "Logarithmic-distribution", 41864 http://en.wikipedia.org/wiki/Logarithmic-distribution 41865 41866 Examples 41867 -------- 41868 Draw samples from the distribution: 41869 41870 >>> a = .6 41871 >>> s = np.random.logseries(a, 10000) 41872 >>> count, bins, ignored = plt.hist(s) 41873 41874 # plot against distribution 41875 41876 >>> def logseries(k, p): 41877 ... return -p**k/(k*log(1-p)) 41878 >>> plt.plot(bins, logseries(bins, a)*count.max()/ 41879 logseries(bins, a).max(), 'r') 41880 >>> plt.show() 41881 41882 """ 41883 return ndarray() 41884 def multinomial(self, n, pvals, size): 41885 """ 41886 multinomial(n, pvals, size=None) 41887 41888 Draw samples from a multinomial distribution. 41889 41890 The multinomial distribution is a multivariate generalisation of the 41891 binomial distribution. Take an experiment with one of ``p`` 41892 possible outcomes. An example of such an experiment is throwing a dice, 41893 where the outcome can be 1 through 6. Each sample drawn from the 41894 distribution represents `n` such experiments. Its values, 41895 ``X_i = [X_0, X_1, ..., X_p]``, represent the number of times the outcome 41896 was ``i``. 41897 41898 Parameters 41899 ---------- 41900 n : int 41901 Number of experiments. 41902 pvals : sequence of floats, length p 41903 Probabilities of each of the ``p`` different outcomes. These 41904 should sum to 1 (however, the last element is always assumed to 41905 account for the remaining probability, as long as 41906 ``sum(pvals[:-1]) <= 1)``. 41907 size : tuple of ints 41908 Given a `size` of ``(M, N, K)``, then ``M*N*K`` samples are drawn, 41909 and the output shape becomes ``(M, N, K, p)``, since each sample 41910 has shape ``(p,)``. 41911 41912 Examples 41913 -------- 41914 Throw a dice 20 times: 41915 41916 >>> np.random.multinomial(20, [1/6.]*6, size=1) 41917 array([[4, 1, 7, 5, 2, 1]]) 41918 41919 It landed 4 times on 1, once on 2, etc. 41920 41921 Now, throw the dice 20 times, and 20 times again: 41922 41923 >>> np.random.multinomial(20, [1/6.]*6, size=2) 41924 array([[3, 4, 3, 3, 4, 3], 41925 [2, 4, 3, 4, 0, 7]]) 41926 41927 For the first run, we threw 3 times 1, 4 times 2, etc. For the second, 41928 we threw 2 times 1, 4 times 2, etc. 41929 41930 A loaded dice is more likely to land on number 6: 41931 41932 >>> np.random.multinomial(100, [1/7.]*5) 41933 array([13, 16, 13, 16, 42]) 41934 41935 """ 41936 return None 41937 def multivariate_normal(self, mean, cov, size): 41938 """ 41939 multivariate_normal(mean, cov[, size]) 41940 41941 Draw random samples from a multivariate normal distribution. 41942 41943 The multivariate normal, multinormal or Gaussian distribution is a 41944 generalization of the one-dimensional normal distribution to higher 41945 dimensions. Such a distribution is specified by its mean and 41946 covariance matrix. These parameters are analogous to the mean 41947 (average or "center") and variance (standard deviation, or "width," 41948 squared) of the one-dimensional normal distribution. 41949 41950 Parameters 41951 ---------- 41952 mean : 1-D array_like, of length N 41953 Mean of the N-dimensional distribution. 41954 cov : 2-D array_like, of shape (N, N) 41955 Covariance matrix of the distribution. Must be symmetric and 41956 positive semi-definite for "physically meaningful" results. 41957 size : int or tuple of ints, optional 41958 Given a shape of, for example, ``(m,n,k)``, ``m*n*k`` samples are 41959 generated, and packed in an `m`-by-`n`-by-`k` arrangement. Because 41960 each sample is `N`-dimensional, the output shape is ``(m,n,k,N)``. 41961 If no shape is specified, a single (`N`-D) sample is returned. 41962 41963 Returns 41964 ------- 41965 out : ndarray 41966 The drawn samples, of shape *size*, if that was provided. If not, 41967 the shape is ``(N,)``. 41968 41969 In other words, each entry ``out[i,j,...,:]`` is an N-dimensional 41970 value drawn from the distribution. 41971 41972 Notes 41973 ----- 41974 The mean is a coordinate in N-dimensional space, which represents the 41975 location where samples are most likely to be generated. This is 41976 analogous to the peak of the bell curve for the one-dimensional or 41977 univariate normal distribution. 41978 41979 Covariance indicates the level to which two variables vary together. 41980 From the multivariate normal distribution, we draw N-dimensional 41981 samples, :math:`X = [x_1, x_2, ... x_N]`. The covariance matrix 41982 element :math:`C_{ij}` is the covariance of :math:`x_i` and :math:`x_j`. 41983 The element :math:`C_{ii}` is the variance of :math:`x_i` (i.e. its 41984 "spread"). 41985 41986 Instead of specifying the full covariance matrix, popular 41987 approximations include: 41988 41989 - Spherical covariance (*cov* is a multiple of the identity matrix) 41990 - Diagonal covariance (*cov* has non-negative elements, and only on 41991 the diagonal) 41992 41993 This geometrical property can be seen in two dimensions by plotting 41994 generated data-points: 41995 41996 >>> mean = [0,0] 41997 >>> cov = [[1,0],[0,100]] # diagonal covariance, points lie on x or y-axis 41998 41999 >>> import matplotlib.pyplot as plt 42000 >>> x,y = np.random.multivariate_normal(mean,cov,5000).T 42001 >>> plt.plot(x,y,'x'); plt.axis('equal'); plt.show() 42002 42003 Note that the covariance matrix must be non-negative definite. 42004 42005 References 42006 ---------- 42007 Papoulis, A., *Probability, Random Variables, and Stochastic Processes*, 42008 3rd ed., New York: McGraw-Hill, 1991. 42009 42010 Duda, R. O., Hart, P. E., and Stork, D. G., *Pattern Classification*, 42011 2nd ed., New York: Wiley, 2001. 42012 42013 Examples 42014 -------- 42015 >>> mean = (1,2) 42016 >>> cov = [[1,0],[1,0]] 42017 >>> x = np.random.multivariate_normal(mean,cov,(3,3)) 42018 >>> x.shape 42019 (3, 3, 2) 42020 42021 The following is probably true, given that 0.6 is roughly twice the 42022 standard deviation: 42023 42024 >>> print list( (x[0,0,:] - mean) < 0.6 ) 42025 [True, True] 42026 42027 """ 42028 return ndarray() 42029 def negative_binomial(self, n, p, size): 42030 """ 42031 negative_binomial(n, p, size=None) 42032 42033 Draw samples from a negative_binomial distribution. 42034 42035 Samples are drawn from a negative_Binomial distribution with specified 42036 parameters, `n` trials and `p` probability of success where `n` is an 42037 integer > 0 and `p` is in the interval [0, 1]. 42038 42039 Parameters 42040 ---------- 42041 n : int 42042 Parameter, > 0. 42043 p : float 42044 Parameter, >= 0 and <=1. 42045 size : int or tuple of ints 42046 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 42047 ``m * n * k`` samples are drawn. 42048 42049 Returns 42050 ------- 42051 samples : int or ndarray of ints 42052 Drawn samples. 42053 42054 Notes 42055 ----- 42056 The probability density for the Negative Binomial distribution is 42057 42058 .. math:: P(N;n,p) = \binom{N+n-1}{n-1}p^{n}(1-p)^{N}, 42059 42060 where :math:`n-1` is the number of successes, :math:`p` is the probability 42061 of success, and :math:`N+n-1` is the number of trials. 42062 42063 The negative binomial distribution gives the probability of n-1 successes 42064 and N failures in N+n-1 trials, and success on the (N+n)th trial. 42065 42066 If one throws a die repeatedly until the third time a "1" appears, then the 42067 probability distribution of the number of non-"1"s that appear before the 42068 third "1" is a negative binomial distribution. 42069 42070 References 42071 ---------- 42072 .. [1] Weisstein, Eric W. "Negative Binomial Distribution." From 42073 MathWorld--A Wolfram Web Resource. 42074 http://mathworld.wolfram.com/NegativeBinomialDistribution.html 42075 .. [2] Wikipedia, "Negative binomial distribution", 42076 http://en.wikipedia.org/wiki/Negative_binomial_distribution 42077 42078 Examples 42079 -------- 42080 Draw samples from the distribution: 42081 42082 A real world example. A company drills wild-cat oil exploration wells, each 42083 with an estimated probability of success of 0.1. What is the probability 42084 of having one success for each successive well, that is what is the 42085 probability of a single success after drilling 5 wells, after 6 wells, 42086 etc.? 42087 42088 >>> s = np.random.negative_binomial(1, 0.1, 100000) 42089 >>> for i in range(1, 11): 42090 ... probability = sum(s<i) / 100000. 42091 ... print i, "wells drilled, probability of one success =", probability 42092 42093 """ 42094 return int() if False else ndarray() 42095 def noncentral_chisquare(self, df, nonc, size): 42096 """ 42097 noncentral_chisquare(df, nonc, size=None) 42098 42099 Draw samples from a noncentral chi-square distribution. 42100 42101 The noncentral :math:`\chi^2` distribution is a generalisation of 42102 the :math:`\chi^2` distribution. 42103 42104 Parameters 42105 ---------- 42106 df : int 42107 Degrees of freedom, should be >= 1. 42108 nonc : float 42109 Non-centrality, should be > 0. 42110 size : int or tuple of ints 42111 Shape of the output. 42112 42113 Notes 42114 ----- 42115 The probability density function for the noncentral Chi-square distribution 42116 is 42117 42118 .. math:: P(x;df,nonc) = \sum^{\infty}_{i=0} 42119 \frac{e^{-nonc/2}(nonc/2)^{i}}{i!}P_{Y_{df+2i}}(x), 42120 42121 where :math:`Y_{q}` is the Chi-square with q degrees of freedom. 42122 42123 In Delhi (2007), it is noted that the noncentral chi-square is useful in 42124 bombing and coverage problems, the probability of killing the point target 42125 given by the noncentral chi-squared distribution. 42126 42127 References 42128 ---------- 42129 .. [1] Delhi, M.S. Holla, "On a noncentral chi-square distribution in the 42130 analysis of weapon systems effectiveness", Metrika, Volume 15, 42131 Number 1 / December, 1970. 42132 .. [2] Wikipedia, "Noncentral chi-square distribution" 42133 http://en.wikipedia.org/wiki/Noncentral_chi-square_distribution 42134 42135 Examples 42136 -------- 42137 Draw values from the distribution and plot the histogram 42138 42139 >>> import matplotlib.pyplot as plt 42140 >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000), 42141 ... bins=200, normed=True) 42142 >>> plt.show() 42143 42144 Draw values from a noncentral chisquare with very small noncentrality, 42145 and compare to a chisquare. 42146 42147 >>> plt.figure() 42148 >>> values = plt.hist(np.random.noncentral_chisquare(3, .0000001, 100000), 42149 ... bins=np.arange(0., 25, .1), normed=True) 42150 >>> values2 = plt.hist(np.random.chisquare(3, 100000), 42151 ... bins=np.arange(0., 25, .1), normed=True) 42152 >>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob') 42153 >>> plt.show() 42154 42155 Demonstrate how large values of non-centrality lead to a more symmetric 42156 distribution. 42157 42158 >>> plt.figure() 42159 >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000), 42160 ... bins=200, normed=True) 42161 >>> plt.show() 42162 42163 """ 42164 return None 42165 def noncentral_f(self, dfnum, dfden, nonc, size): 42166 """ 42167 noncentral_f(dfnum, dfden, nonc, size=None) 42168 42169 Draw samples from the noncentral F distribution. 42170 42171 Samples are drawn from an F distribution with specified parameters, 42172 `dfnum` (degrees of freedom in numerator) and `dfden` (degrees of 42173 freedom in denominator), where both parameters > 1. 42174 `nonc` is the non-centrality parameter. 42175 42176 Parameters 42177 ---------- 42178 dfnum : int 42179 Parameter, should be > 1. 42180 dfden : int 42181 Parameter, should be > 1. 42182 nonc : float 42183 Parameter, should be >= 0. 42184 size : int or tuple of ints 42185 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 42186 ``m * n * k`` samples are drawn. 42187 42188 Returns 42189 ------- 42190 samples : scalar or ndarray 42191 Drawn samples. 42192 42193 Notes 42194 ----- 42195 When calculating the power of an experiment (power = probability of 42196 rejecting the null hypothesis when a specific alternative is true) the 42197 non-central F statistic becomes important. When the null hypothesis is 42198 true, the F statistic follows a central F distribution. When the null 42199 hypothesis is not true, then it follows a non-central F statistic. 42200 42201 References 42202 ---------- 42203 Weisstein, Eric W. "Noncentral F-Distribution." From MathWorld--A Wolfram 42204 Web Resource. http://mathworld.wolfram.com/NoncentralF-Distribution.html 42205 42206 Wikipedia, "Noncentral F distribution", 42207 http://en.wikipedia.org/wiki/Noncentral_F-distribution 42208 42209 Examples 42210 -------- 42211 In a study, testing for a specific alternative to the null hypothesis 42212 requires use of the Noncentral F distribution. We need to calculate the 42213 area in the tail of the distribution that exceeds the value of the F 42214 distribution for the null hypothesis. We'll plot the two probability 42215 distributions for comparison. 42216 42217 >>> dfnum = 3 # between group deg of freedom 42218 >>> dfden = 20 # within groups degrees of freedom 42219 >>> nonc = 3.0 42220 >>> nc_vals = np.random.noncentral_f(dfnum, dfden, nonc, 1000000) 42221 >>> NF = np.histogram(nc_vals, bins=50, normed=True) 42222 >>> c_vals = np.random.f(dfnum, dfden, 1000000) 42223 >>> F = np.histogram(c_vals, bins=50, normed=True) 42224 >>> plt.plot(F[1][1:], F[0]) 42225 >>> plt.plot(NF[1][1:], NF[0]) 42226 >>> plt.show() 42227 42228 """ 42229 return float() if False else ndarray() 42230 def normal(self, loc, scale, size): 42231 """ 42232 normal(loc=0.0, scale=1.0, size=None) 42233 42234 Draw random samples from a normal (Gaussian) distribution. 42235 42236 The probability density function of the normal distribution, first 42237 derived by De Moivre and 200 years later by both Gauss and Laplace 42238 independently [2]_, is often called the bell curve because of 42239 its characteristic shape (see the example below). 42240 42241 The normal distributions occurs often in nature. For example, it 42242 describes the commonly occurring distribution of samples influenced 42243 by a large number of tiny, random disturbances, each with its own 42244 unique distribution [2]_. 42245 42246 Parameters 42247 ---------- 42248 loc : float 42249 Mean ("centre") of the distribution. 42250 scale : float 42251 Standard deviation (spread or "width") of the distribution. 42252 size : tuple of ints 42253 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 42254 ``m * n * k`` samples are drawn. 42255 42256 See Also 42257 -------- 42258 scipy.stats.distributions.norm : probability density function, 42259 distribution or cumulative density function, etc. 42260 42261 Notes 42262 ----- 42263 The probability density for the Gaussian distribution is 42264 42265 .. math:: p(x) = \frac{1}{\sqrt{ 2 \pi \sigma^2 }} 42266 e^{ - \frac{ (x - \mu)^2 } {2 \sigma^2} }, 42267 42268 where :math:`\mu` is the mean and :math:`\sigma` the standard deviation. 42269 The square of the standard deviation, :math:`\sigma^2`, is called the 42270 variance. 42271 42272 The function has its peak at the mean, and its "spread" increases with 42273 the standard deviation (the function reaches 0.607 times its maximum at 42274 :math:`x + \sigma` and :math:`x - \sigma` [2]_). This implies that 42275 `numpy.random.normal` is more likely to return samples lying close to the 42276 mean, rather than those far away. 42277 42278 References 42279 ---------- 42280 .. [1] Wikipedia, "Normal distribution", 42281 http://en.wikipedia.org/wiki/Normal_distribution 42282 .. [2] P. R. Peebles Jr., "Central Limit Theorem" in "Probability, Random 42283 Variables and Random Signal Principles", 4th ed., 2001, 42284 pp. 51, 51, 125. 42285 42286 Examples 42287 -------- 42288 Draw samples from the distribution: 42289 42290 >>> mu, sigma = 0, 0.1 # mean and standard deviation 42291 >>> s = np.random.normal(mu, sigma, 1000) 42292 42293 Verify the mean and the variance: 42294 42295 >>> abs(mu - np.mean(s)) < 0.01 42296 True 42297 42298 >>> abs(sigma - np.std(s, ddof=1)) < 0.01 42299 True 42300 42301 Display the histogram of the samples, along with 42302 the probability density function: 42303 42304 >>> import matplotlib.pyplot as plt 42305 >>> count, bins, ignored = plt.hist(s, 30, normed=True) 42306 >>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * 42307 ... np.exp( - (bins - mu)**2 / (2 * sigma**2) ), 42308 ... linewidth=2, color='r') 42309 >>> plt.show() 42310 42311 """ 42312 return None 42313 def pareto(self, shape, size): 42314 """ 42315 pareto(a, size=None) 42316 42317 Draw samples from a Pareto II or Lomax distribution with specified shape. 42318 42319 The Lomax or Pareto II distribution is a shifted Pareto distribution. The 42320 classical Pareto distribution can be obtained from the Lomax distribution 42321 by adding the location parameter m, see below. The smallest value of the 42322 Lomax distribution is zero while for the classical Pareto distribution it 42323 is m, where the standard Pareto distribution has location m=1. 42324 Lomax can also be considered as a simplified version of the Generalized 42325 Pareto distribution (available in SciPy), with the scale set to one and 42326 the location set to zero. 42327 42328 The Pareto distribution must be greater than zero, and is unbounded above. 42329 It is also known as the "80-20 rule". In this distribution, 80 percent of 42330 the weights are in the lowest 20 percent of the range, while the other 20 42331 percent fill the remaining 80 percent of the range. 42332 42333 Parameters 42334 ---------- 42335 shape : float, > 0. 42336 Shape of the distribution. 42337 size : tuple of ints 42338 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 42339 ``m * n * k`` samples are drawn. 42340 42341 See Also 42342 -------- 42343 scipy.stats.distributions.lomax.pdf : probability density function, 42344 distribution or cumulative density function, etc. 42345 scipy.stats.distributions.genpareto.pdf : probability density function, 42346 distribution or cumulative density function, etc. 42347 42348 Notes 42349 ----- 42350 The probability density for the Pareto distribution is 42351 42352 .. math:: p(x) = \frac{am^a}{x^{a+1}} 42353 42354 where :math:`a` is the shape and :math:`m` the location 42355 42356 The Pareto distribution, named after the Italian economist Vilfredo Pareto, 42357 is a power law probability distribution useful in many real world problems. 42358 Outside the field of economics it is generally referred to as the Bradford 42359 distribution. Pareto developed the distribution to describe the 42360 distribution of wealth in an economy. It has also found use in insurance, 42361 web page access statistics, oil field sizes, and many other problems, 42362 including the download frequency for projects in Sourceforge [1]. It is 42363 one of the so-called "fat-tailed" distributions. 42364 42365 42366 References 42367 ---------- 42368 .. [1] Francis Hunt and Paul Johnson, On the Pareto Distribution of 42369 Sourceforge projects. 42370 .. [2] Pareto, V. (1896). Course of Political Economy. Lausanne. 42371 .. [3] Reiss, R.D., Thomas, M.(2001), Statistical Analysis of Extreme 42372 Values, Birkhauser Verlag, Basel, pp 23-30. 42373 .. [4] Wikipedia, "Pareto distribution", 42374 http://en.wikipedia.org/wiki/Pareto_distribution 42375 42376 Examples 42377 -------- 42378 Draw samples from the distribution: 42379 42380 >>> a, m = 3., 1. # shape and mode 42381 >>> s = np.random.pareto(a, 1000) + m 42382 42383 Display the histogram of the samples, along with 42384 the probability density function: 42385 42386 >>> import matplotlib.pyplot as plt 42387 >>> count, bins, ignored = plt.hist(s, 100, normed=True, align='center') 42388 >>> fit = a*m**a/bins**(a+1) 42389 >>> plt.plot(bins, max(count)*fit/max(fit),linewidth=2, color='r') 42390 >>> plt.show() 42391 42392 """ 42393 return None 42394 def permutation(self, x): 42395 """ 42396 permutation(x) 42397 42398 Randomly permute a sequence, or return a permuted range. 42399 42400 If `x` is a multi-dimensional array, it is only shuffled along its 42401 first index. 42402 42403 Parameters 42404 ---------- 42405 x : int or array_like 42406 If `x` is an integer, randomly permute ``np.arange(x)``. 42407 If `x` is an array, make a copy and shuffle the elements 42408 randomly. 42409 42410 Returns 42411 ------- 42412 out : ndarray 42413 Permuted sequence or array range. 42414 42415 Examples 42416 -------- 42417 >>> np.random.permutation(10) 42418 array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6]) 42419 42420 >>> np.random.permutation([1, 4, 9, 12, 15]) 42421 array([15, 1, 9, 4, 12]) 42422 42423 >>> arr = np.arange(9).reshape((3, 3)) 42424 >>> np.random.permutation(arr) 42425 array([[6, 7, 8], 42426 [0, 1, 2], 42427 [3, 4, 5]]) 42428 42429 """ 42430 return ndarray() 42431 def poisson(self, lam, size): 42432 """ 42433 poisson(lam=1.0, size=None) 42434 42435 Draw samples from a Poisson distribution. 42436 42437 The Poisson distribution is the limit of the Binomial 42438 distribution for large N. 42439 42440 Parameters 42441 ---------- 42442 lam : float 42443 Expectation of interval, should be >= 0. 42444 size : int or tuple of ints, optional 42445 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 42446 ``m * n * k`` samples are drawn. 42447 42448 Notes 42449 ----- 42450 The Poisson distribution 42451 42452 .. math:: f(k; \lambda)=\frac{\lambda^k e^{-\lambda}}{k!} 42453 42454 For events with an expected separation :math:`\lambda` the Poisson 42455 distribution :math:`f(k; \lambda)` describes the probability of 42456 :math:`k` events occurring within the observed interval :math:`\lambda`. 42457 42458 Because the output is limited to the range of the C long type, a 42459 ValueError is raised when `lam` is within 10 sigma of the maximum 42460 representable value. 42461 42462 References 42463 ---------- 42464 .. [1] Weisstein, Eric W. "Poisson Distribution." From MathWorld--A Wolfram 42465 Web Resource. http://mathworld.wolfram.com/PoissonDistribution.html 42466 .. [2] Wikipedia, "Poisson distribution", 42467 http://en.wikipedia.org/wiki/Poisson_distribution 42468 42469 Examples 42470 -------- 42471 Draw samples from the distribution: 42472 42473 >>> import numpy as np 42474 >>> s = np.random.poisson(5, 10000) 42475 42476 Display histogram of the sample: 42477 42478 >>> import matplotlib.pyplot as plt 42479 >>> count, bins, ignored = plt.hist(s, 14, normed=True) 42480 >>> plt.show() 42481 42482 """ 42483 return None 42484 poisson_lam_max = float64() 42485 def power(self, a, size): 42486 """ 42487 power(a, size=None) 42488 42489 Draws samples in [0, 1] from a power distribution with positive 42490 exponent a - 1. 42491 42492 Also known as the power function distribution. 42493 42494 Parameters 42495 ---------- 42496 a : float 42497 parameter, > 0 42498 size : tuple of ints 42499 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 42500 ``m * n * k`` samples are drawn. 42501 42502 Returns 42503 ------- 42504 samples : {ndarray, scalar} 42505 The returned samples lie in [0, 1]. 42506 42507 Raises 42508 ------ 42509 ValueError 42510 If a<1. 42511 42512 Notes 42513 ----- 42514 The probability density function is 42515 42516 .. math:: P(x; a) = ax^{a-1}, 0 \le x \le 1, a>0. 42517 42518 The power function distribution is just the inverse of the Pareto 42519 distribution. It may also be seen as a special case of the Beta 42520 distribution. 42521 42522 It is used, for example, in modeling the over-reporting of insurance 42523 claims. 42524 42525 References 42526 ---------- 42527 .. [1] Christian Kleiber, Samuel Kotz, "Statistical size distributions 42528 in economics and actuarial sciences", Wiley, 2003. 42529 .. [2] Heckert, N. A. and Filliben, James J. (2003). NIST Handbook 148: 42530 Dataplot Reference Manual, Volume 2: Let Subcommands and Library 42531 Functions", National Institute of Standards and Technology Handbook 42532 Series, June 2003. 42533 http://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/powpdf.pdf 42534 42535 Examples 42536 -------- 42537 Draw samples from the distribution: 42538 42539 >>> a = 5. # shape 42540 >>> samples = 1000 42541 >>> s = np.random.power(a, samples) 42542 42543 Display the histogram of the samples, along with 42544 the probability density function: 42545 42546 >>> import matplotlib.pyplot as plt 42547 >>> count, bins, ignored = plt.hist(s, bins=30) 42548 >>> x = np.linspace(0, 1, 100) 42549 >>> y = a*x**(a-1.) 42550 >>> normed_y = samples*np.diff(bins)[0]*y 42551 >>> plt.plot(x, normed_y) 42552 >>> plt.show() 42553 42554 Compare the power function distribution to the inverse of the Pareto. 42555 42556 >>> from scipy import stats 42557 >>> rvs = np.random.power(5, 1000000) 42558 >>> rvsp = np.random.pareto(5, 1000000) 42559 >>> xx = np.linspace(0,1,100) 42560 >>> powpdf = stats.powerlaw.pdf(xx,5) 42561 42562 >>> plt.figure() 42563 >>> plt.hist(rvs, bins=50, normed=True) 42564 >>> plt.plot(xx,powpdf,'r-') 42565 >>> plt.title('np.random.power(5)') 42566 42567 >>> plt.figure() 42568 >>> plt.hist(1./(1.+rvsp), bins=50, normed=True) 42569 >>> plt.plot(xx,powpdf,'r-') 42570 >>> plt.title('inverse of 1 + np.random.pareto(5)') 42571 42572 >>> plt.figure() 42573 >>> plt.hist(1./(1.+rvsp), bins=50, normed=True) 42574 >>> plt.plot(xx,powpdf,'r-') 42575 >>> plt.title('inverse of stats.pareto(5)') 42576 42577 """ 42578 return ndarray() 42579 def rand(self, d0d1more_argsdn): 42580 """ 42581 rand(d0, d1, ..., dn) 42582 42583 Random values in a given shape. 42584 42585 Create an array of the given shape and propagate it with 42586 random samples from a uniform distribution 42587 over ``[0, 1)``. 42588 42589 Parameters 42590 ---------- 42591 d0, d1, ..., dn : int, optional 42592 The dimensions of the returned array, should all be positive. 42593 If no argument is given a single Python float is returned. 42594 42595 Returns 42596 ------- 42597 out : ndarray, shape ``(d0, d1, ..., dn)`` 42598 Random values. 42599 42600 See Also 42601 -------- 42602 random 42603 42604 Notes 42605 ----- 42606 This is a convenience function. If you want an interface that 42607 takes a shape-tuple as the first argument, refer to 42608 np.random.random_sample . 42609 42610 Examples 42611 -------- 42612 >>> np.random.rand(3,2) 42613 array([[ 0.14022471, 0.96360618], #random 42614 [ 0.37601032, 0.25528411], #random 42615 [ 0.49313049, 0.94909878]]) #random 42616 42617 """ 42618 return None 42619 def randint(self, low, high, size): 42620 """ 42621 randint(low, high=None, size=None) 42622 42623 Return random integers from `low` (inclusive) to `high` (exclusive). 42624 42625 Return random integers from the "discrete uniform" distribution in the 42626 "half-open" interval [`low`, `high`). If `high` is None (the default), 42627 then results are from [0, `low`). 42628 42629 Parameters 42630 ---------- 42631 low : int 42632 Lowest (signed) integer to be drawn from the distribution (unless 42633 ``high=None``, in which case this parameter is the *highest* such 42634 integer). 42635 high : int, optional 42636 If provided, one above the largest (signed) integer to be drawn 42637 from the distribution (see above for behavior if ``high=None``). 42638 size : int or tuple of ints, optional 42639 Output shape. Default is None, in which case a single int is 42640 returned. 42641 42642 Returns 42643 ------- 42644 out : int or ndarray of ints 42645 `size`-shaped array of random integers from the appropriate 42646 distribution, or a single such random int if `size` not provided. 42647 42648 See Also 42649 -------- 42650 random.random_integers : similar to `randint`, only for the closed 42651 interval [`low`, `high`], and 1 is the lowest value if `high` is 42652 omitted. In particular, this other one is the one to use to generate 42653 uniformly distributed discrete non-integers. 42654 42655 Examples 42656 -------- 42657 >>> np.random.randint(2, size=10) 42658 array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) 42659 >>> np.random.randint(1, size=10) 42660 array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) 42661 42662 Generate a 2 x 4 array of ints between 0 and 4, inclusive: 42663 42664 >>> np.random.randint(5, size=(2, 4)) 42665 array([[4, 0, 2, 1], 42666 [3, 2, 2, 0]]) 42667 42668 """ 42669 return int() if False else ndarray() 42670 def randn(self, d0d1more_argsdn): 42671 """ 42672 randn(d0, d1, ..., dn) 42673 42674 Return a sample (or samples) from the "standard normal" distribution. 42675 42676 If positive, int_like or int-convertible arguments are provided, 42677 `randn` generates an array of shape ``(d0, d1, ..., dn)``, filled 42678 with random floats sampled from a univariate "normal" (Gaussian) 42679 distribution of mean 0 and variance 1 (if any of the :math:`d_i` are 42680 floats, they are first converted to integers by truncation). A single 42681 float randomly sampled from the distribution is returned if no 42682 argument is provided. 42683 42684 This is a convenience function. If you want an interface that takes a 42685 tuple as the first argument, use `numpy.random.standard_normal` instead. 42686 42687 Parameters 42688 ---------- 42689 d0, d1, ..., dn : int, optional 42690 The dimensions of the returned array, should be all positive. 42691 If no argument is given a single Python float is returned. 42692 42693 Returns 42694 ------- 42695 Z : ndarray or float 42696 A ``(d0, d1, ..., dn)``-shaped array of floating-point samples from 42697 the standard normal distribution, or a single such float if 42698 no parameters were supplied. 42699 42700 See Also 42701 -------- 42702 random.standard_normal : Similar, but takes a tuple as its argument. 42703 42704 Notes 42705 ----- 42706 For random samples from :math:`N(\mu, \sigma^2)`, use: 42707 42708 ``sigma * np.random.randn(...) + mu`` 42709 42710 Examples 42711 -------- 42712 >>> np.random.randn() 42713 2.1923875335537315 #random 42714 42715 Two-by-four array of samples from N(3, 6.25): 42716 42717 >>> 2.5 * np.random.randn(2, 4) + 3 42718 array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], #random 42719 [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) #random 42720 42721 """ 42722 return ndarray() if False else float() 42723 def random_integers(self, low, high, size): 42724 """ 42725 random_integers(low, high=None, size=None) 42726 42727 Return random integers between `low` and `high`, inclusive. 42728 42729 Return random integers from the "discrete uniform" distribution in the 42730 closed interval [`low`, `high`]. If `high` is None (the default), 42731 then results are from [1, `low`]. 42732 42733 Parameters 42734 ---------- 42735 low : int 42736 Lowest (signed) integer to be drawn from the distribution (unless 42737 ``high=None``, in which case this parameter is the *highest* such 42738 integer). 42739 high : int, optional 42740 If provided, the largest (signed) integer to be drawn from the 42741 distribution (see above for behavior if ``high=None``). 42742 size : int or tuple of ints, optional 42743 Output shape. Default is None, in which case a single int is returned. 42744 42745 Returns 42746 ------- 42747 out : int or ndarray of ints 42748 `size`-shaped array of random integers from the appropriate 42749 distribution, or a single such random int if `size` not provided. 42750 42751 See Also 42752 -------- 42753 random.randint : Similar to `random_integers`, only for the half-open 42754 interval [`low`, `high`), and 0 is the lowest value if `high` is 42755 omitted. 42756 42757 Notes 42758 ----- 42759 To sample from N evenly spaced floating-point numbers between a and b, 42760 use:: 42761 42762 a + (b - a) * (np.random.random_integers(N) - 1) / (N - 1.) 42763 42764 Examples 42765 -------- 42766 >>> np.random.random_integers(5) 42767 4 42768 >>> type(np.random.random_integers(5)) 42769 <type 'int'> 42770 >>> np.random.random_integers(5, size=(3.,2.)) 42771 array([[5, 4], 42772 [3, 3], 42773 [4, 5]]) 42774 42775 Choose five random numbers from the set of five evenly-spaced 42776 numbers between 0 and 2.5, inclusive (*i.e.*, from the set 42777 :math:`{0, 5/8, 10/8, 15/8, 20/8}`): 42778 42779 >>> 2.5 * (np.random.random_integers(5, size=(5,)) - 1) / 4. 42780 array([ 0.625, 1.25 , 0.625, 0.625, 2.5 ]) 42781 42782 Roll two six sided dice 1000 times and sum the results: 42783 42784 >>> d1 = np.random.random_integers(1, 6, 1000) 42785 >>> d2 = np.random.random_integers(1, 6, 1000) 42786 >>> dsums = d1 + d2 42787 42788 Display results as a histogram: 42789 42790 >>> import matplotlib.pyplot as plt 42791 >>> count, bins, ignored = plt.hist(dsums, 11, normed=True) 42792 >>> plt.show() 42793 42794 """ 42795 return int() if False else ndarray() 42796 def random_sample(self, size): 42797 """ 42798 random_sample(size=None) 42799 42800 Return random floats in the half-open interval [0.0, 1.0). 42801 42802 Results are from the "continuous uniform" distribution over the 42803 stated interval. To sample :math:`Unif[a, b), b > a` multiply 42804 the output of `random_sample` by `(b-a)` and add `a`:: 42805 42806 (b - a) * random_sample() + a 42807 42808 Parameters 42809 ---------- 42810 size : int or tuple of ints, optional 42811 Defines the shape of the returned array of random floats. If None 42812 (the default), returns a single float. 42813 42814 Returns 42815 ------- 42816 out : float or ndarray of floats 42817 Array of random floats of shape `size` (unless ``size=None``, in which 42818 case a single float is returned). 42819 42820 Examples 42821 -------- 42822 >>> np.random.random_sample() 42823 0.47108547995356098 42824 >>> type(np.random.random_sample()) 42825 <type 'float'> 42826 >>> np.random.random_sample((5,)) 42827 array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428]) 42828 42829 Three-by-two array of random numbers from [-5, 0): 42830 42831 >>> 5 * np.random.random_sample((3, 2)) - 5 42832 array([[-3.99149989, -0.52338984], 42833 [-2.99091858, -0.79479508], 42834 [-1.23204345, -1.75224494]]) 42835 42836 """ 42837 return float() if False else ndarray() 42838 def rayleigh(self, scale, size): 42839 """ 42840 rayleigh(scale=1.0, size=None) 42841 42842 Draw samples from a Rayleigh distribution. 42843 42844 The :math:`\chi` and Weibull distributions are generalizations of the 42845 Rayleigh. 42846 42847 Parameters 42848 ---------- 42849 scale : scalar 42850 Scale, also equals the mode. Should be >= 0. 42851 size : int or tuple of ints, optional 42852 Shape of the output. Default is None, in which case a single 42853 value is returned. 42854 42855 Notes 42856 ----- 42857 The probability density function for the Rayleigh distribution is 42858 42859 .. math:: P(x;scale) = \frac{x}{scale^2}e^{\frac{-x^2}{2 \cdotp scale^2}} 42860 42861 The Rayleigh distribution arises if the wind speed and wind direction are 42862 both gaussian variables, then the vector wind velocity forms a Rayleigh 42863 distribution. The Rayleigh distribution is used to model the expected 42864 output from wind turbines. 42865 42866 References 42867 ---------- 42868 .. [1] Brighton Webs Ltd., Rayleigh Distribution, 42869 http://www.brighton-webs.co.uk/distributions/rayleigh.asp 42870 .. [2] Wikipedia, "Rayleigh distribution" 42871 http://en.wikipedia.org/wiki/Rayleigh_distribution 42872 42873 Examples 42874 -------- 42875 Draw values from the distribution and plot the histogram 42876 42877 >>> values = hist(np.random.rayleigh(3, 100000), bins=200, normed=True) 42878 42879 Wave heights tend to follow a Rayleigh distribution. If the mean wave 42880 height is 1 meter, what fraction of waves are likely to be larger than 3 42881 meters? 42882 42883 >>> meanvalue = 1 42884 >>> modevalue = np.sqrt(2 / np.pi) * meanvalue 42885 >>> s = np.random.rayleigh(modevalue, 1000000) 42886 42887 The percentage of waves larger than 3 meters is: 42888 42889 >>> 100.*sum(s>3)/1000000. 42890 0.087300000000000003 42891 42892 """ 42893 return None 42894 def seed(self, seed): 42895 """ 42896 seed(seed=None) 42897 42898 Seed the generator. 42899 42900 This method is called when `RandomState` is initialized. It can be 42901 called again to re-seed the generator. For details, see `RandomState`. 42902 42903 Parameters 42904 ---------- 42905 seed : int or array_like, optional 42906 Seed for `RandomState`. 42907 42908 See Also 42909 -------- 42910 RandomState 42911 42912 """ 42913 return None 42914 def set_state(self, state): 42915 """ 42916 set_state(state) 42917 42918 Set the internal state of the generator from a tuple. 42919 42920 For use if one has reason to manually (re-)set the internal state of the 42921 "Mersenne Twister"[1]_ pseudo-random number generating algorithm. 42922 42923 Parameters 42924 ---------- 42925 state : tuple(str, ndarray of 624 uints, int, int, float) 42926 The `state` tuple has the following items: 42927 42928 1. the string 'MT19937', specifying the Mersenne Twister algorithm. 42929 2. a 1-D array of 624 unsigned integers ``keys``. 42930 3. an integer ``pos``. 42931 4. an integer ``has_gauss``. 42932 5. a float ``cached_gaussian``. 42933 42934 Returns 42935 ------- 42936 out : None 42937 Returns 'None' on success. 42938 42939 See Also 42940 -------- 42941 get_state 42942 42943 Notes 42944 ----- 42945 `set_state` and `get_state` are not needed to work with any of the 42946 random distributions in NumPy. If the internal state is manually altered, 42947 the user should know exactly what he/she is doing. 42948 42949 For backwards compatibility, the form (str, array of 624 uints, int) is 42950 also accepted although it is missing some information about the cached 42951 Gaussian value: ``state = ('MT19937', keys, pos)``. 42952 42953 References 42954 ---------- 42955 .. [1] M. Matsumoto and T. Nishimura, "Mersenne Twister: A 42956 623-dimensionally equidistributed uniform pseudorandom number 42957 generator," *ACM Trans. on Modeling and Computer Simulation*, 42958 Vol. 8, No. 1, pp. 3-30, Jan. 1998. 42959 42960 """ 42961 return None 42962 def shuffle(self, x): 42963 """ 42964 shuffle(x) 42965 42966 Modify a sequence in-place by shuffling its contents. 42967 42968 Parameters 42969 ---------- 42970 x : array_like 42971 The array or list to be shuffled. 42972 42973 Returns 42974 ------- 42975 None 42976 42977 Examples 42978 -------- 42979 >>> arr = np.arange(10) 42980 >>> np.random.shuffle(arr) 42981 >>> arr 42982 [1 7 5 2 9 4 3 6 0 8] 42983 42984 This function only shuffles the array along the first index of a 42985 multi-dimensional array: 42986 42987 >>> arr = np.arange(9).reshape((3, 3)) 42988 >>> np.random.shuffle(arr) 42989 >>> arr 42990 array([[3, 4, 5], 42991 [6, 7, 8], 42992 [0, 1, 2]]) 42993 42994 """ 42995 return None 42996 def standard_cauchy(self, size): 42997 """ 42998 standard_cauchy(size=None) 42999 43000 Standard Cauchy distribution with mode = 0. 43001 43002 Also known as the Lorentz distribution. 43003 43004 Parameters 43005 ---------- 43006 size : int or tuple of ints 43007 Shape of the output. 43008 43009 Returns 43010 ------- 43011 samples : ndarray or scalar 43012 The drawn samples. 43013 43014 Notes 43015 ----- 43016 The probability density function for the full Cauchy distribution is 43017 43018 .. math:: P(x; x_0, \gamma) = \frac{1}{\pi \gamma \bigl[ 1+ 43019 (\frac{x-x_0}{\gamma})^2 \bigr] } 43020 43021 and the Standard Cauchy distribution just sets :math:`x_0=0` and 43022 :math:`\gamma=1` 43023 43024 The Cauchy distribution arises in the solution to the driven harmonic 43025 oscillator problem, and also describes spectral line broadening. It 43026 also describes the distribution of values at which a line tilted at 43027 a random angle will cut the x axis. 43028 43029 When studying hypothesis tests that assume normality, seeing how the 43030 tests perform on data from a Cauchy distribution is a good indicator of 43031 their sensitivity to a heavy-tailed distribution, since the Cauchy looks 43032 very much like a Gaussian distribution, but with heavier tails. 43033 43034 References 43035 ---------- 43036 .. [1] NIST/SEMATECH e-Handbook of Statistical Methods, "Cauchy 43037 Distribution", 43038 http://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm 43039 .. [2] Weisstein, Eric W. "Cauchy Distribution." From MathWorld--A 43040 Wolfram Web Resource. 43041 http://mathworld.wolfram.com/CauchyDistribution.html 43042 .. [3] Wikipedia, "Cauchy distribution" 43043 http://en.wikipedia.org/wiki/Cauchy_distribution 43044 43045 Examples 43046 -------- 43047 Draw samples and plot the distribution: 43048 43049 >>> s = np.random.standard_cauchy(1000000) 43050 >>> s = s[(s>-25) & (s<25)] # truncate distribution so it plots well 43051 >>> plt.hist(s, bins=100) 43052 >>> plt.show() 43053 43054 """ 43055 return ndarray() if False else float() 43056 def standard_exponential(self, size): 43057 """ 43058 standard_exponential(size=None) 43059 43060 Draw samples from the standard exponential distribution. 43061 43062 `standard_exponential` is identical to the exponential distribution 43063 with a scale parameter of 1. 43064 43065 Parameters 43066 ---------- 43067 size : int or tuple of ints 43068 Shape of the output. 43069 43070 Returns 43071 ------- 43072 out : float or ndarray 43073 Drawn samples. 43074 43075 Examples 43076 -------- 43077 Output a 3x8000 array: 43078 43079 >>> n = np.random.standard_exponential((3, 8000)) 43080 43081 """ 43082 return float() if False else ndarray() 43083 def standard_gamma(self, shape, size): 43084 """ 43085 standard_gamma(shape, size=None) 43086 43087 Draw samples from a Standard Gamma distribution. 43088 43089 Samples are drawn from a Gamma distribution with specified parameters, 43090 shape (sometimes designated "k") and scale=1. 43091 43092 Parameters 43093 ---------- 43094 shape : float 43095 Parameter, should be > 0. 43096 size : int or tuple of ints 43097 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 43098 ``m * n * k`` samples are drawn. 43099 43100 Returns 43101 ------- 43102 samples : ndarray or scalar 43103 The drawn samples. 43104 43105 See Also 43106 -------- 43107 scipy.stats.distributions.gamma : probability density function, 43108 distribution or cumulative density function, etc. 43109 43110 Notes 43111 ----- 43112 The probability density for the Gamma distribution is 43113 43114 .. math:: p(x) = x^{k-1}\frac{e^{-x/\theta}}{\theta^k\Gamma(k)}, 43115 43116 where :math:`k` is the shape and :math:`\theta` the scale, 43117 and :math:`\Gamma` is the Gamma function. 43118 43119 The Gamma distribution is often used to model the times to failure of 43120 electronic components, and arises naturally in processes for which the 43121 waiting times between Poisson distributed events are relevant. 43122 43123 References 43124 ---------- 43125 .. [1] Weisstein, Eric W. "Gamma Distribution." From MathWorld--A 43126 Wolfram Web Resource. 43127 http://mathworld.wolfram.com/GammaDistribution.html 43128 .. [2] Wikipedia, "Gamma-distribution", 43129 http://en.wikipedia.org/wiki/Gamma-distribution 43130 43131 Examples 43132 -------- 43133 Draw samples from the distribution: 43134 43135 >>> shape, scale = 2., 1. # mean and width 43136 >>> s = np.random.standard_gamma(shape, 1000000) 43137 43138 Display the histogram of the samples, along with 43139 the probability density function: 43140 43141 >>> import matplotlib.pyplot as plt 43142 >>> import scipy.special as sps 43143 >>> count, bins, ignored = plt.hist(s, 50, normed=True) 43144 >>> y = bins**(shape-1) * ((np.exp(-bins/scale))/ \ 43145 ... (sps.gamma(shape) * scale**shape)) 43146 >>> plt.plot(bins, y, linewidth=2, color='r') 43147 >>> plt.show() 43148 43149 """ 43150 return ndarray() if False else float() 43151 def standard_normal(self, size): 43152 """ 43153 standard_normal(size=None) 43154 43155 Returns samples from a Standard Normal distribution (mean=0, stdev=1). 43156 43157 Parameters 43158 ---------- 43159 size : int or tuple of ints, optional 43160 Output shape. Default is None, in which case a single value is 43161 returned. 43162 43163 Returns 43164 ------- 43165 out : float or ndarray 43166 Drawn samples. 43167 43168 Examples 43169 -------- 43170 >>> s = np.random.standard_normal(8000) 43171 >>> s 43172 array([ 0.6888893 , 0.78096262, -0.89086505, ..., 0.49876311, #random 43173 -0.38672696, -0.4685006 ]) #random 43174 >>> s.shape 43175 (8000,) 43176 >>> s = np.random.standard_normal(size=(3, 4, 2)) 43177 >>> s.shape 43178 (3, 4, 2) 43179 43180 """ 43181 return float() if False else ndarray() 43182 def standard_t(self, df, size): 43183 """ 43184 standard_t(df, size=None) 43185 43186 Standard Student's t distribution with df degrees of freedom. 43187 43188 A special case of the hyperbolic distribution. 43189 As `df` gets large, the result resembles that of the standard normal 43190 distribution (`standard_normal`). 43191 43192 Parameters 43193 ---------- 43194 df : int 43195 Degrees of freedom, should be > 0. 43196 size : int or tuple of ints, optional 43197 Output shape. Default is None, in which case a single value is 43198 returned. 43199 43200 Returns 43201 ------- 43202 samples : ndarray or scalar 43203 Drawn samples. 43204 43205 Notes 43206 ----- 43207 The probability density function for the t distribution is 43208 43209 .. math:: P(x, df) = \frac{\Gamma(\frac{df+1}{2})}{\sqrt{\pi df} 43210 \Gamma(\frac{df}{2})}\Bigl( 1+\frac{x^2}{df} \Bigr)^{-(df+1)/2} 43211 43212 The t test is based on an assumption that the data come from a Normal 43213 distribution. The t test provides a way to test whether the sample mean 43214 (that is the mean calculated from the data) is a good estimate of the true 43215 mean. 43216 43217 The derivation of the t-distribution was forst published in 1908 by William 43218 Gisset while working for the Guinness Brewery in Dublin. Due to proprietary 43219 issues, he had to publish under a pseudonym, and so he used the name 43220 Student. 43221 43222 References 43223 ---------- 43224 .. [1] Dalgaard, Peter, "Introductory Statistics With R", 43225 Springer, 2002. 43226 .. [2] Wikipedia, "Student's t-distribution" 43227 http://en.wikipedia.org/wiki/Student's_t-distribution 43228 43229 Examples 43230 -------- 43231 From Dalgaard page 83 [1]_, suppose the daily energy intake for 11 43232 women in Kj is: 43233 43234 >>> intake = np.array([5260., 5470, 5640, 6180, 6390, 6515, 6805, 7515, \ 43235 ... 7515, 8230, 8770]) 43236 43237 Does their energy intake deviate systematically from the recommended 43238 value of 7725 kJ? 43239 43240 We have 10 degrees of freedom, so is the sample mean within 95% of the 43241 recommended value? 43242 43243 >>> s = np.random.standard_t(10, size=100000) 43244 >>> np.mean(intake) 43245 6753.636363636364 43246 >>> intake.std(ddof=1) 43247 1142.1232221373727 43248 43249 Calculate the t statistic, setting the ddof parameter to the unbiased 43250 value so the divisor in the standard deviation will be degrees of 43251 freedom, N-1. 43252 43253 >>> t = (np.mean(intake)-7725)/(intake.std(ddof=1)/np.sqrt(len(intake))) 43254 >>> import matplotlib.pyplot as plt 43255 >>> h = plt.hist(s, bins=100, normed=True) 43256 43257 For a one-sided t-test, how far out in the distribution does the t 43258 statistic appear? 43259 43260 >>> >>> np.sum(s<t) / float(len(s)) 43261 0.0090699999999999999 #random 43262 43263 So the p-value is about 0.009, which says the null hypothesis has a 43264 probability of about 99% of being true. 43265 43266 """ 43267 return ndarray() if False else float() 43268 def tomaxint(self, size): 43269 """ 43270 tomaxint(size=None) 43271 43272 Random integers between 0 and ``sys.maxint``, inclusive. 43273 43274 Return a sample of uniformly distributed random integers in the interval 43275 [0, ``sys.maxint``]. 43276 43277 Parameters 43278 ---------- 43279 size : tuple of ints, int, optional 43280 Shape of output. If this is, for example, (m,n,k), m*n*k samples 43281 are generated. If no shape is specified, a single sample is 43282 returned. 43283 43284 Returns 43285 ------- 43286 out : ndarray 43287 Drawn samples, with shape `size`. 43288 43289 See Also 43290 -------- 43291 randint : Uniform sampling over a given half-open interval of integers. 43292 random_integers : Uniform sampling over a given closed interval of 43293 integers. 43294 43295 Examples 43296 -------- 43297 >>> RS = np.random.mtrand.RandomState() # need a RandomState object 43298 >>> RS.tomaxint((2,2,2)) 43299 array([[[1170048599, 1600360186], 43300 [ 739731006, 1947757578]], 43301 [[1871712945, 752307660], 43302 [1601631370, 1479324245]]]) 43303 >>> import sys 43304 >>> sys.maxint 43305 2147483647 43306 >>> RS.tomaxint((2,2,2)) < sys.maxint 43307 array([[[ True, True], 43308 [ True, True]], 43309 [[ True, True], 43310 [ True, True]]], dtype=bool) 43311 43312 """ 43313 return ndarray() 43314 def triangular(self, left, mode, right, size): 43315 """ 43316 triangular(left, mode, right, size=None) 43317 43318 Draw samples from the triangular distribution. 43319 43320 The triangular distribution is a continuous probability distribution with 43321 lower limit left, peak at mode, and upper limit right. Unlike the other 43322 distributions, these parameters directly define the shape of the pdf. 43323 43324 Parameters 43325 ---------- 43326 left : scalar 43327 Lower limit. 43328 mode : scalar 43329 The value where the peak of the distribution occurs. 43330 The value should fulfill the condition ``left <= mode <= right``. 43331 right : scalar 43332 Upper limit, should be larger than `left`. 43333 size : int or tuple of ints, optional 43334 Output shape. Default is None, in which case a single value is 43335 returned. 43336 43337 Returns 43338 ------- 43339 samples : ndarray or scalar 43340 The returned samples all lie in the interval [left, right]. 43341 43342 Notes 43343 ----- 43344 The probability density function for the Triangular distribution is 43345 43346 .. math:: P(x;l, m, r) = \begin{cases} 43347 \frac{2(x-l)}{(r-l)(m-l)}& \text{for $l \leq x \leq m$},\\ 43348 \frac{2(m-x)}{(r-l)(r-m)}& \text{for $m \leq x \leq r$},\\ 43349 0& \text{otherwise}. 43350 \end{cases} 43351 43352 The triangular distribution is often used in ill-defined problems where the 43353 underlying distribution is not known, but some knowledge of the limits and 43354 mode exists. Often it is used in simulations. 43355 43356 References 43357 ---------- 43358 .. [1] Wikipedia, "Triangular distribution" 43359 http://en.wikipedia.org/wiki/Triangular_distribution 43360 43361 Examples 43362 -------- 43363 Draw values from the distribution and plot the histogram: 43364 43365 >>> import matplotlib.pyplot as plt 43366 >>> h = plt.hist(np.random.triangular(-3, 0, 8, 100000), bins=200, 43367 ... normed=True) 43368 >>> plt.show() 43369 43370 """ 43371 return ndarray() if False else float() 43372 def uniform(self, low, high, size): 43373 """ 43374 uniform(low=0.0, high=1.0, size=1) 43375 43376 Draw samples from a uniform distribution. 43377 43378 Samples are uniformly distributed over the half-open interval 43379 ``[low, high)`` (includes low, but excludes high). In other words, 43380 any value within the given interval is equally likely to be drawn 43381 by `uniform`. 43382 43383 Parameters 43384 ---------- 43385 low : float, optional 43386 Lower boundary of the output interval. All values generated will be 43387 greater than or equal to low. The default value is 0. 43388 high : float 43389 Upper boundary of the output interval. All values generated will be 43390 less than high. The default value is 1.0. 43391 size : int or tuple of ints, optional 43392 Shape of output. If the given size is, for example, (m,n,k), 43393 m*n*k samples are generated. If no shape is specified, a single sample 43394 is returned. 43395 43396 Returns 43397 ------- 43398 out : ndarray 43399 Drawn samples, with shape `size`. 43400 43401 See Also 43402 -------- 43403 randint : Discrete uniform distribution, yielding integers. 43404 random_integers : Discrete uniform distribution over the closed 43405 interval ``[low, high]``. 43406 random_sample : Floats uniformly distributed over ``[0, 1)``. 43407 random : Alias for `random_sample`. 43408 rand : Convenience function that accepts dimensions as input, e.g., 43409 ``rand(2,2)`` would generate a 2-by-2 array of floats, 43410 uniformly distributed over ``[0, 1)``. 43411 43412 Notes 43413 ----- 43414 The probability density function of the uniform distribution is 43415 43416 .. math:: p(x) = \frac{1}{b - a} 43417 43418 anywhere within the interval ``[a, b)``, and zero elsewhere. 43419 43420 Examples 43421 -------- 43422 Draw samples from the distribution: 43423 43424 >>> s = np.random.uniform(-1,0,1000) 43425 43426 All values are within the given interval: 43427 43428 >>> np.all(s >= -1) 43429 True 43430 >>> np.all(s < 0) 43431 True 43432 43433 Display the histogram of the samples, along with the 43434 probability density function: 43435 43436 >>> import matplotlib.pyplot as plt 43437 >>> count, bins, ignored = plt.hist(s, 15, normed=True) 43438 >>> plt.plot(bins, np.ones_like(bins), linewidth=2, color='r') 43439 >>> plt.show() 43440 43441 """ 43442 return ndarray() 43443 def vonmises(self, mu, kappa, size): 43444 """ 43445 vonmises(mu, kappa, size=None) 43446 43447 Draw samples from a von Mises distribution. 43448 43449 Samples are drawn from a von Mises distribution with specified mode 43450 (mu) and dispersion (kappa), on the interval [-pi, pi]. 43451 43452 The von Mises distribution (also known as the circular normal 43453 distribution) is a continuous probability distribution on the unit 43454 circle. It may be thought of as the circular analogue of the normal 43455 distribution. 43456 43457 Parameters 43458 ---------- 43459 mu : float 43460 Mode ("center") of the distribution. 43461 kappa : float 43462 Dispersion of the distribution, has to be >=0. 43463 size : int or tuple of int 43464 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 43465 ``m * n * k`` samples are drawn. 43466 43467 Returns 43468 ------- 43469 samples : scalar or ndarray 43470 The returned samples, which are in the interval [-pi, pi]. 43471 43472 See Also 43473 -------- 43474 scipy.stats.distributions.vonmises : probability density function, 43475 distribution, or cumulative density function, etc. 43476 43477 Notes 43478 ----- 43479 The probability density for the von Mises distribution is 43480 43481 .. math:: p(x) = \frac{e^{\kappa cos(x-\mu)}}{2\pi I_0(\kappa)}, 43482 43483 where :math:`\mu` is the mode and :math:`\kappa` the dispersion, 43484 and :math:`I_0(\kappa)` is the modified Bessel function of order 0. 43485 43486 The von Mises is named for Richard Edler von Mises, who was born in 43487 Austria-Hungary, in what is now the Ukraine. He fled to the United 43488 States in 1939 and became a professor at Harvard. He worked in 43489 probability theory, aerodynamics, fluid mechanics, and philosophy of 43490 science. 43491 43492 References 43493 ---------- 43494 Abramowitz, M. and Stegun, I. A. (ed.), *Handbook of Mathematical 43495 Functions*, New York: Dover, 1965. 43496 43497 von Mises, R., *Mathematical Theory of Probability and Statistics*, 43498 New York: Academic Press, 1964. 43499 43500 Examples 43501 -------- 43502 Draw samples from the distribution: 43503 43504 >>> mu, kappa = 0.0, 4.0 # mean and dispersion 43505 >>> s = np.random.vonmises(mu, kappa, 1000) 43506 43507 Display the histogram of the samples, along with 43508 the probability density function: 43509 43510 >>> import matplotlib.pyplot as plt 43511 >>> import scipy.special as sps 43512 >>> count, bins, ignored = plt.hist(s, 50, normed=True) 43513 >>> x = np.arange(-np.pi, np.pi, 2*np.pi/50.) 43514 >>> y = -np.exp(kappa*np.cos(x-mu))/(2*np.pi*sps.jn(0,kappa)) 43515 >>> plt.plot(x, y/max(y), linewidth=2, color='r') 43516 >>> plt.show() 43517 43518 """ 43519 return float() if False else ndarray() 43520 def wald(self, mean, scale, size): 43521 """ 43522 wald(mean, scale, size=None) 43523 43524 Draw samples from a Wald, or Inverse Gaussian, distribution. 43525 43526 As the scale approaches infinity, the distribution becomes more like a 43527 Gaussian. 43528 43529 Some references claim that the Wald is an Inverse Gaussian with mean=1, but 43530 this is by no means universal. 43531 43532 The Inverse Gaussian distribution was first studied in relationship to 43533 Brownian motion. In 1956 M.C.K. Tweedie used the name Inverse Gaussian 43534 because there is an inverse relationship between the time to cover a unit 43535 distance and distance covered in unit time. 43536 43537 Parameters 43538 ---------- 43539 mean : scalar 43540 Distribution mean, should be > 0. 43541 scale : scalar 43542 Scale parameter, should be >= 0. 43543 size : int or tuple of ints, optional 43544 Output shape. Default is None, in which case a single value is 43545 returned. 43546 43547 Returns 43548 ------- 43549 samples : ndarray or scalar 43550 Drawn sample, all greater than zero. 43551 43552 Notes 43553 ----- 43554 The probability density function for the Wald distribution is 43555 43556 .. math:: P(x;mean,scale) = \sqrt{\frac{scale}{2\pi x^3}}e^ 43557 \frac{-scale(x-mean)^2}{2\cdotp mean^2x} 43558 43559 As noted above the Inverse Gaussian distribution first arise from attempts 43560 to model Brownian Motion. It is also a competitor to the Weibull for use in 43561 reliability modeling and modeling stock returns and interest rate 43562 processes. 43563 43564 References 43565 ---------- 43566 .. [1] Brighton Webs Ltd., Wald Distribution, 43567 http://www.brighton-webs.co.uk/distributions/wald.asp 43568 .. [2] Chhikara, Raj S., and Folks, J. Leroy, "The Inverse Gaussian 43569 Distribution: Theory : Methodology, and Applications", CRC Press, 43570 1988. 43571 .. [3] Wikipedia, "Wald distribution" 43572 http://en.wikipedia.org/wiki/Wald_distribution 43573 43574 Examples 43575 -------- 43576 Draw values from the distribution and plot the histogram: 43577 43578 >>> import matplotlib.pyplot as plt 43579 >>> h = plt.hist(np.random.wald(3, 2, 100000), bins=200, normed=True) 43580 >>> plt.show() 43581 43582 """ 43583 return ndarray() if False else float() 43584 def weibull(self, a, size): 43585 """ 43586 weibull(a, size=None) 43587 43588 Weibull distribution. 43589 43590 Draw samples from a 1-parameter Weibull distribution with the given 43591 shape parameter `a`. 43592 43593 .. math:: X = (-ln(U))^{1/a} 43594 43595 Here, U is drawn from the uniform distribution over (0,1]. 43596 43597 The more common 2-parameter Weibull, including a scale parameter 43598 :math:`\lambda` is just :math:`X = \lambda(-ln(U))^{1/a}`. 43599 43600 Parameters 43601 ---------- 43602 a : float 43603 Shape of the distribution. 43604 size : tuple of ints 43605 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 43606 ``m * n * k`` samples are drawn. 43607 43608 See Also 43609 -------- 43610 scipy.stats.distributions.weibull_max 43611 scipy.stats.distributions.weibull_min 43612 scipy.stats.distributions.genextreme 43613 gumbel 43614 43615 Notes 43616 ----- 43617 The Weibull (or Type III asymptotic extreme value distribution for smallest 43618 values, SEV Type III, or Rosin-Rammler distribution) is one of a class of 43619 Generalized Extreme Value (GEV) distributions used in modeling extreme 43620 value problems. This class includes the Gumbel and Frechet distributions. 43621 43622 The probability density for the Weibull distribution is 43623 43624 .. math:: p(x) = \frac{a} 43625 {\lambda}(\frac{x}{\lambda})^{a-1}e^{-(x/\lambda)^a}, 43626 43627 where :math:`a` is the shape and :math:`\lambda` the scale. 43628 43629 The function has its peak (the mode) at 43630 :math:`\lambda(\frac{a-1}{a})^{1/a}`. 43631 43632 When ``a = 1``, the Weibull distribution reduces to the exponential 43633 distribution. 43634 43635 References 43636 ---------- 43637 .. [1] Waloddi Weibull, Professor, Royal Technical University, Stockholm, 43638 1939 "A Statistical Theory Of The Strength Of Materials", 43639 Ingeniorsvetenskapsakademiens Handlingar Nr 151, 1939, 43640 Generalstabens Litografiska Anstalts Forlag, Stockholm. 43641 .. [2] Waloddi Weibull, 1951 "A Statistical Distribution Function of Wide 43642 Applicability", Journal Of Applied Mechanics ASME Paper. 43643 .. [3] Wikipedia, "Weibull distribution", 43644 http://en.wikipedia.org/wiki/Weibull_distribution 43645 43646 Examples 43647 -------- 43648 Draw samples from the distribution: 43649 43650 >>> a = 5. # shape 43651 >>> s = np.random.weibull(a, 1000) 43652 43653 Display the histogram of the samples, along with 43654 the probability density function: 43655 43656 >>> import matplotlib.pyplot as plt 43657 >>> x = np.arange(1,100.)/50. 43658 >>> def weib(x,n,a): 43659 ... return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a) 43660 43661 >>> count, bins, ignored = plt.hist(np.random.weibull(5.,1000)) 43662 >>> x = np.arange(1,100.)/50. 43663 >>> scale = count.max()/weib(x, 1., 5.).max() 43664 >>> plt.plot(x, weib(x, 1., 5.)*scale) 43665 >>> plt.show() 43666 43667 """ 43668 return None 43669 def zipf(self, a, size): 43670 """ 43671 zipf(a, size=None) 43672 43673 Draw samples from a Zipf distribution. 43674 43675 Samples are drawn from a Zipf distribution with specified parameter 43676 `a` > 1. 43677 43678 The Zipf distribution (also known as the zeta distribution) is a 43679 continuous probability distribution that satisfies Zipf's law: the 43680 frequency of an item is inversely proportional to its rank in a 43681 frequency table. 43682 43683 Parameters 43684 ---------- 43685 a : float > 1 43686 Distribution parameter. 43687 size : int or tuple of int, optional 43688 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 43689 ``m * n * k`` samples are drawn; a single integer is equivalent in 43690 its result to providing a mono-tuple, i.e., a 1-D array of length 43691 *size* is returned. The default is None, in which case a single 43692 scalar is returned. 43693 43694 Returns 43695 ------- 43696 samples : scalar or ndarray 43697 The returned samples are greater than or equal to one. 43698 43699 See Also 43700 -------- 43701 scipy.stats.distributions.zipf : probability density function, 43702 distribution, or cumulative density function, etc. 43703 43704 Notes 43705 ----- 43706 The probability density for the Zipf distribution is 43707 43708 .. math:: p(x) = \frac{x^{-a}}{\zeta(a)}, 43709 43710 where :math:`\zeta` is the Riemann Zeta function. 43711 43712 It is named for the American linguist George Kingsley Zipf, who noted 43713 that the frequency of any word in a sample of a language is inversely 43714 proportional to its rank in the frequency table. 43715 43716 References 43717 ---------- 43718 Zipf, G. K., *Selected Studies of the Principle of Relative Frequency 43719 in Language*, Cambridge, MA: Harvard Univ. Press, 1932. 43720 43721 Examples 43722 -------- 43723 Draw samples from the distribution: 43724 43725 >>> a = 2. # parameter 43726 >>> s = np.random.zipf(a, 1000) 43727 43728 Display the histogram of the samples, along with 43729 the probability density function: 43730 43731 >>> import matplotlib.pyplot as plt 43732 >>> import scipy.special as sps 43733 Truncate s values at 50 so plot is interesting 43734 >>> count, bins, ignored = plt.hist(s[s<50], 50, normed=True) 43735 >>> x = np.arange(1., 50.) 43736 >>> y = x**(-a)/sps.zetac(a) 43737 >>> plt.plot(x, y/max(y), linewidth=2, color='r') 43738 >>> plt.show() 43739 43740 """ 43741 return float() if False else ndarray() 43742 class NoseTester: 43743 __dict__ = dictproxy() 43744 __doc__ = str() 43745 __module__ = str() 43746 __weakref__ = getset_descriptor() 43747 def _get_custom_doctester(self, _): 43748 """ Return instantiated plugin for doctests 43749 43750 Allows subclassing of this class to override doctester 43751 43752 A return value of None means use the nose builtin doctest plugin 43753 """ 43754 return None 43755 def _show_system_info(self, _): 43756 """None""" 43757 return None 43758 def _test_argv(self, label, verbose, extra_argv): 43759 """ Generate argv for nosetest command 43760 43761 Parameters 43762 ---------- 43763 label : {'fast', 'full', '', attribute identifier}, optional 43764 see ``test`` docstring 43765 verbose : int, optional 43766 Verbosity value for test outputs, in the range 1-10. Default is 1. 43767 extra_argv : list, optional 43768 List with any extra arguments to pass to nosetests. 43769 43770 Returns 43771 ------- 43772 argv : list 43773 command line arguments that will be passed to nose 43774 """ 43775 return list() 43776 def bench(self=None, label="fast", verbose=1, extra_argv=None): 43777 """ 43778 Run benchmarks for module using nose. 43779 43780 Parameters 43781 ---------- 43782 label : {'fast', 'full', '', attribute identifier}, optional 43783 Identifies the benchmarks to run. This can be a string to pass to 43784 the nosetests executable with the '-A' option, or one of several 43785 special values. Special values are: 43786 * 'fast' - the default - which corresponds to the ``nosetests -A`` 43787 option of 'not slow'. 43788 * 'full' - fast (as above) and slow benchmarks as in the 43789 'no -A' option to nosetests - this is the same as ''. 43790 * None or '' - run all tests. 43791 attribute_identifier - string passed directly to nosetests as '-A'. 43792 verbose : int, optional 43793 Verbosity value for benchmark outputs, in the range 1-10. Default is 1. 43794 extra_argv : list, optional 43795 List with any extra arguments to pass to nosetests. 43796 43797 Returns 43798 ------- 43799 success : bool 43800 Returns True if running the benchmarks works, False if an error 43801 occurred. 43802 43803 Notes 43804 ----- 43805 Benchmarks are like tests, but have names starting with "bench" instead 43806 of "test", and can be found under the "benchmarks" sub-directory of the 43807 module. 43808 43809 Each NumPy module exposes `bench` in its namespace to run all benchmarks 43810 for it. 43811 43812 Examples 43813 -------- 43814 >>> success = np.lib.bench() #doctest: +SKIP 43815 Running benchmarks for numpy.lib 43816 ... 43817 using 562341 items: 43818 unique: 43819 0.11 43820 unique1d: 43821 0.11 43822 ratio: 1.0 43823 nUnique: 56230 == 56230 43824 ... 43825 OK 43826 43827 >>> success #doctest: +SKIP 43828 True 43829 43830 """ 43831 return bool() 43832 excludes = list() 43833 def prepare_test_args(self=False, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False): 43834 """ 43835 Run tests for module using nose. 43836 43837 This method does the heavy lifting for the `test` method. It takes all 43838 the same arguments, for details see `test`. 43839 43840 See Also 43841 -------- 43842 test 43843 43844 """ 43845 return None 43846 def test(self=None, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None): 43847 """ 43848 Run tests for module using nose. 43849 43850 Parameters 43851 ---------- 43852 label : {'fast', 'full', '', attribute identifier}, optional 43853 Identifies the tests to run. This can be a string to pass to 43854 the nosetests executable with the '-A' option, or one of several 43855 special values. Special values are: 43856 * 'fast' - the default - which corresponds to the ``nosetests -A`` 43857 option of 'not slow'. 43858 * 'full' - fast (as above) and slow tests as in the 43859 'no -A' option to nosetests - this is the same as ''. 43860 * None or '' - run all tests. 43861 attribute_identifier - string passed directly to nosetests as '-A'. 43862 verbose : int, optional 43863 Verbosity value for test outputs, in the range 1-10. Default is 1. 43864 extra_argv : list, optional 43865 List with any extra arguments to pass to nosetests. 43866 doctests : bool, optional 43867 If True, run doctests in module. Default is False. 43868 coverage : bool, optional 43869 If True, report coverage of NumPy code. Default is False. 43870 (This requires the `coverage module: 43871 <http://nedbatchelder.com/code/modules/coverage.html>`_). 43872 raise_warnings : str or sequence of warnings, optional 43873 This specifies which warnings to configure as 'raise' instead 43874 of 'warn' during the test execution. Valid strings are: 43875 43876 - "develop" : equals ``(DeprecationWarning, RuntimeWarning)`` 43877 - "release" : equals ``()``, don't raise on any warnings. 43878 43879 Returns 43880 ------- 43881 result : object 43882 Returns the result of running the tests as a 43883 ``nose.result.TextTestResult`` object. 43884 43885 Notes 43886 ----- 43887 Each NumPy module exposes `test` in its namespace to run all tests for it. 43888 For example, to run all tests for numpy.lib: 43889 43890 >>> np.lib.test() #doctest: +SKIP 43891 43892 Examples 43893 -------- 43894 >>> result = np.lib.test() #doctest: +SKIP 43895 Running unit tests for numpy.lib 43896 ... 43897 Ran 976 tests in 3.933s 43898 43899 OK 43900 43901 >>> result.errors #doctest: +SKIP 43902 [] 43903 >>> result.knownfail #doctest: +SKIP 43904 [] 43905 """ 43906 return object() 43907 __all__ = list() 43908 __builtins__ = dict() 43909 __doc__ = str() 43910 __file__ = str() 43911 __name__ = str() 43912 __package__ = str() 43913 __path__ = list() 43914 __warningregistry__ = dict() 43915 absolute_import = instance() 43916 def bench(self=None, label="fast", verbose=1, extra_argv=None): 43917 """ 43918 Run benchmarks for module using nose. 43919 43920 Parameters 43921 ---------- 43922 label : {'fast', 'full', '', attribute identifier}, optional 43923 Identifies the benchmarks to run. This can be a string to pass to 43924 the nosetests executable with the '-A' option, or one of several 43925 special values. Special values are: 43926 * 'fast' - the default - which corresponds to the ``nosetests -A`` 43927 option of 'not slow'. 43928 * 'full' - fast (as above) and slow benchmarks as in the 43929 'no -A' option to nosetests - this is the same as ''. 43930 * None or '' - run all tests. 43931 attribute_identifier - string passed directly to nosetests as '-A'. 43932 verbose : int, optional 43933 Verbosity value for benchmark outputs, in the range 1-10. Default is 1. 43934 extra_argv : list, optional 43935 List with any extra arguments to pass to nosetests. 43936 43937 Returns 43938 ------- 43939 success : bool 43940 Returns True if running the benchmarks works, False if an error 43941 occurred. 43942 43943 Notes 43944 ----- 43945 Benchmarks are like tests, but have names starting with "bench" instead 43946 of "test", and can be found under the "benchmarks" sub-directory of the 43947 module. 43948 43949 Each NumPy module exposes `bench` in its namespace to run all benchmarks 43950 for it. 43951 43952 Examples 43953 -------- 43954 >>> success = np.lib.bench() #doctest: +SKIP 43955 Running benchmarks for numpy.lib 43956 ... 43957 using 562341 items: 43958 unique: 43959 0.11 43960 unique1d: 43961 0.11 43962 ratio: 1.0 43963 nUnique: 56230 == 56230 43964 ... 43965 OK 43966 43967 >>> success #doctest: +SKIP 43968 True 43969 43970 """ 43971 return bool() 43972 def beta(self, a, b, size): 43973 """ 43974 beta(a, b, size=None) 43975 43976 The Beta distribution over ``[0, 1]``. 43977 43978 The Beta distribution is a special case of the Dirichlet distribution, 43979 and is related to the Gamma distribution. It has the probability 43980 distribution function 43981 43982 .. math:: f(x; a,b) = \frac{1}{B(\alpha, \beta)} x^{\alpha - 1} 43983 (1 - x)^{\beta - 1}, 43984 43985 where the normalisation, B, is the beta function, 43986 43987 .. math:: B(\alpha, \beta) = \int_0^1 t^{\alpha - 1} 43988 (1 - t)^{\beta - 1} dt. 43989 43990 It is often seen in Bayesian inference and order statistics. 43991 43992 Parameters 43993 ---------- 43994 a : float 43995 Alpha, non-negative. 43996 b : float 43997 Beta, non-negative. 43998 size : tuple of ints, optional 43999 The number of samples to draw. The output is packed according to 44000 the size given. 44001 44002 Returns 44003 ------- 44004 out : ndarray 44005 Array of the given shape, containing values drawn from a 44006 Beta distribution. 44007 44008 """ 44009 return ndarray() 44010 def binomial(self, n, p, size): 44011 """ 44012 binomial(n, p, size=None) 44013 44014 Draw samples from a binomial distribution. 44015 44016 Samples are drawn from a Binomial distribution with specified 44017 parameters, n trials and p probability of success where 44018 n an integer >= 0 and p is in the interval [0,1]. (n may be 44019 input as a float, but it is truncated to an integer in use) 44020 44021 Parameters 44022 ---------- 44023 n : float (but truncated to an integer) 44024 parameter, >= 0. 44025 p : float 44026 parameter, >= 0 and <=1. 44027 size : {tuple, int} 44028 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 44029 ``m * n * k`` samples are drawn. 44030 44031 Returns 44032 ------- 44033 samples : {ndarray, scalar} 44034 where the values are all integers in [0, n]. 44035 44036 See Also 44037 -------- 44038 scipy.stats.distributions.binom : probability density function, 44039 distribution or cumulative density function, etc. 44040 44041 Notes 44042 ----- 44043 The probability density for the Binomial distribution is 44044 44045 .. math:: P(N) = \binom{n}{N}p^N(1-p)^{n-N}, 44046 44047 where :math:`n` is the number of trials, :math:`p` is the probability 44048 of success, and :math:`N` is the number of successes. 44049 44050 When estimating the standard error of a proportion in a population by 44051 using a random sample, the normal distribution works well unless the 44052 product p*n <=5, where p = population proportion estimate, and n = 44053 number of samples, in which case the binomial distribution is used 44054 instead. For example, a sample of 15 people shows 4 who are left 44055 handed, and 11 who are right handed. Then p = 4/15 = 27%. 0.27*15 = 4, 44056 so the binomial distribution should be used in this case. 44057 44058 References 44059 ---------- 44060 .. [1] Dalgaard, Peter, "Introductory Statistics with R", 44061 Springer-Verlag, 2002. 44062 .. [2] Glantz, Stanton A. "Primer of Biostatistics.", McGraw-Hill, 44063 Fifth Edition, 2002. 44064 .. [3] Lentner, Marvin, "Elementary Applied Statistics", Bogden 44065 and Quigley, 1972. 44066 .. [4] Weisstein, Eric W. "Binomial Distribution." From MathWorld--A 44067 Wolfram Web Resource. 44068 http://mathworld.wolfram.com/BinomialDistribution.html 44069 .. [5] Wikipedia, "Binomial-distribution", 44070 http://en.wikipedia.org/wiki/Binomial_distribution 44071 44072 Examples 44073 -------- 44074 Draw samples from the distribution: 44075 44076 >>> n, p = 10, .5 # number of trials, probability of each trial 44077 >>> s = np.random.binomial(n, p, 1000) 44078 # result of flipping a coin 10 times, tested 1000 times. 44079 44080 A real world example. A company drills 9 wild-cat oil exploration 44081 wells, each with an estimated probability of success of 0.1. All nine 44082 wells fail. What is the probability of that happening? 44083 44084 Let's do 20,000 trials of the model, and count the number that 44085 generate zero positive results. 44086 44087 >>> sum(np.random.binomial(9,0.1,20000)==0)/20000. 44088 answer = 0.38885, or 38%. 44089 44090 """ 44091 return ndarray() 44092 def bytes(self, length): 44093 """ 44094 bytes(length) 44095 44096 Return random bytes. 44097 44098 Parameters 44099 ---------- 44100 length : int 44101 Number of random bytes. 44102 44103 Returns 44104 ------- 44105 out : str 44106 String of length `length`. 44107 44108 Examples 44109 -------- 44110 >>> np.random.bytes(10) 44111 ' eh\x85\x022SZ\xbf\xa4' #random 44112 44113 """ 44114 return str() 44115 def chisquare(self, df, size): 44116 """ 44117 chisquare(df, size=None) 44118 44119 Draw samples from a chi-square distribution. 44120 44121 When `df` independent random variables, each with standard normal 44122 distributions (mean 0, variance 1), are squared and summed, the 44123 resulting distribution is chi-square (see Notes). This distribution 44124 is often used in hypothesis testing. 44125 44126 Parameters 44127 ---------- 44128 df : int 44129 Number of degrees of freedom. 44130 size : tuple of ints, int, optional 44131 Size of the returned array. By default, a scalar is 44132 returned. 44133 44134 Returns 44135 ------- 44136 output : ndarray 44137 Samples drawn from the distribution, packed in a `size`-shaped 44138 array. 44139 44140 Raises 44141 ------ 44142 ValueError 44143 When `df` <= 0 or when an inappropriate `size` (e.g. ``size=-1``) 44144 is given. 44145 44146 Notes 44147 ----- 44148 The variable obtained by summing the squares of `df` independent, 44149 standard normally distributed random variables: 44150 44151 .. math:: Q = \sum_{i=0}^{\mathtt{df}} X^2_i 44152 44153 is chi-square distributed, denoted 44154 44155 .. math:: Q \sim \chi^2_k. 44156 44157 The probability density function of the chi-squared distribution is 44158 44159 .. math:: p(x) = \frac{(1/2)^{k/2}}{\Gamma(k/2)} 44160 x^{k/2 - 1} e^{-x/2}, 44161 44162 where :math:`\Gamma` is the gamma function, 44163 44164 .. math:: \Gamma(x) = \int_0^{-\infty} t^{x - 1} e^{-t} dt. 44165 44166 References 44167 ---------- 44168 `NIST/SEMATECH e-Handbook of Statistical Methods 44169 <http://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm>`_ 44170 44171 Examples 44172 -------- 44173 >>> np.random.chisquare(2,4) 44174 array([ 1.89920014, 9.00867716, 3.13710533, 5.62318272]) 44175 44176 """ 44177 return ndarray() 44178 def choice(self, a, size, replace, p): 44179 """ 44180 choice(a, size=None, replace=True, p=None) 44181 44182 Generates a random sample from a given 1-D array 44183 44184 .. versionadded:: 1.7.0 44185 44186 Parameters 44187 ----------- 44188 a : 1-D array-like or int 44189 If an ndarray, a random sample is generated from its elements. 44190 If an int, the random sample is generated as if a was np.arange(n) 44191 size : int or tuple of ints, optional 44192 Output shape. Default is None, in which case a single value is 44193 returned. 44194 replace : boolean, optional 44195 Whether the sample is with or without replacement 44196 p : 1-D array-like, optional 44197 The probabilities associated with each entry in a. 44198 If not given the sample assumes a uniform distribtion over all 44199 entries in a. 44200 44201 Returns 44202 -------- 44203 samples : 1-D ndarray, shape (size,) 44204 The generated random samples 44205 44206 Raises 44207 ------- 44208 ValueError 44209 If a is an int and less than zero, if a or p are not 1-dimensional, 44210 if a is an array-like of size 0, if p is not a vector of 44211 probabilities, if a and p have different lengths, or if 44212 replace=False and the sample size is greater than the population 44213 size 44214 44215 See Also 44216 --------- 44217 randint, shuffle, permutation 44218 44219 Examples 44220 --------- 44221 Generate a uniform random sample from np.arange(5) of size 3: 44222 44223 >>> np.random.choice(5, 3) 44224 array([0, 3, 4]) 44225 >>> #This is equivalent to np.random.randint(0,5,3) 44226 44227 Generate a non-uniform random sample from np.arange(5) of size 3: 44228 44229 >>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0]) 44230 array([3, 3, 0]) 44231 44232 Generate a uniform random sample from np.arange(5) of size 3 without 44233 replacement: 44234 44235 >>> np.random.choice(5, 3, replace=False) 44236 array([3,1,0]) 44237 >>> #This is equivalent to np.random.shuffle(np.arange(5))[:3] 44238 44239 Generate a non-uniform random sample from np.arange(5) of size 44240 3 without replacement: 44241 44242 >>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0]) 44243 array([2, 3, 0]) 44244 44245 Any of the above can be repeated with an arbitrary array-like 44246 instead of just integers. For instance: 44247 44248 >>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher'] 44249 >>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3]) 44250 array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'], 44251 dtype='|S11') 44252 44253 """ 44254 return _1_D() 44255 def dirichlet(self, alpha, size): 44256 """ 44257 dirichlet(alpha, size=None) 44258 44259 Draw samples from the Dirichlet distribution. 44260 44261 Draw `size` samples of dimension k from a Dirichlet distribution. A 44262 Dirichlet-distributed random variable can be seen as a multivariate 44263 generalization of a Beta distribution. Dirichlet pdf is the conjugate 44264 prior of a multinomial in Bayesian inference. 44265 44266 Parameters 44267 ---------- 44268 alpha : array 44269 Parameter of the distribution (k dimension for sample of 44270 dimension k). 44271 size : array 44272 Number of samples to draw. 44273 44274 Returns 44275 ------- 44276 samples : ndarray, 44277 The drawn samples, of shape (alpha.ndim, size). 44278 44279 Notes 44280 ----- 44281 .. math:: X \approx \prod_{i=1}^{k}{x^{\alpha_i-1}_i} 44282 44283 Uses the following property for computation: for each dimension, 44284 draw a random sample y_i from a standard gamma generator of shape 44285 `alpha_i`, then 44286 :math:`X = \frac{1}{\sum_{i=1}^k{y_i}} (y_1, \ldots, y_n)` is 44287 Dirichlet distributed. 44288 44289 References 44290 ---------- 44291 .. [1] David McKay, "Information Theory, Inference and Learning 44292 Algorithms," chapter 23, 44293 http://www.inference.phy.cam.ac.uk/mackay/ 44294 .. [2] Wikipedia, "Dirichlet distribution", 44295 http://en.wikipedia.org/wiki/Dirichlet_distribution 44296 44297 Examples 44298 -------- 44299 Taking an example cited in Wikipedia, this distribution can be used if 44300 one wanted to cut strings (each of initial length 1.0) into K pieces 44301 with different lengths, where each piece had, on average, a designated 44302 average length, but allowing some variation in the relative sizes of the 44303 pieces. 44304 44305 >>> s = np.random.dirichlet((10, 5, 3), 20).transpose() 44306 44307 >>> plt.barh(range(20), s[0]) 44308 >>> plt.barh(range(20), s[1], left=s[0], color='g') 44309 >>> plt.barh(range(20), s[2], left=s[0]+s[1], color='r') 44310 >>> plt.title("Lengths of Strings") 44311 44312 """ 44313 return ndarray() 44314 division = instance() 44315 def exponential(self, scale, size): 44316 """ 44317 exponential(scale=1.0, size=None) 44318 44319 Exponential distribution. 44320 44321 Its probability density function is 44322 44323 .. math:: f(x; \frac{1}{\beta}) = \frac{1}{\beta} \exp(-\frac{x}{\beta}), 44324 44325 for ``x > 0`` and 0 elsewhere. :math:`\beta` is the scale parameter, 44326 which is the inverse of the rate parameter :math:`\lambda = 1/\beta`. 44327 The rate parameter is an alternative, widely used parameterization 44328 of the exponential distribution [3]_. 44329 44330 The exponential distribution is a continuous analogue of the 44331 geometric distribution. It describes many common situations, such as 44332 the size of raindrops measured over many rainstorms [1]_, or the time 44333 between page requests to Wikipedia [2]_. 44334 44335 Parameters 44336 ---------- 44337 scale : float 44338 The scale parameter, :math:`\beta = 1/\lambda`. 44339 size : tuple of ints 44340 Number of samples to draw. The output is shaped 44341 according to `size`. 44342 44343 References 44344 ---------- 44345 .. [1] Peyton Z. Peebles Jr., "Probability, Random Variables and 44346 Random Signal Principles", 4th ed, 2001, p. 57. 44347 .. [2] "Poisson Process", Wikipedia, 44348 http://en.wikipedia.org/wiki/Poisson_process 44349 .. [3] "Exponential Distribution, Wikipedia, 44350 http://en.wikipedia.org/wiki/Exponential_distribution 44351 44352 """ 44353 return None 44354 def f(self, dfnum, dfden, size): 44355 """ 44356 f(dfnum, dfden, size=None) 44357 44358 Draw samples from a F distribution. 44359 44360 Samples are drawn from an F distribution with specified parameters, 44361 `dfnum` (degrees of freedom in numerator) and `dfden` (degrees of freedom 44362 in denominator), where both parameters should be greater than zero. 44363 44364 The random variate of the F distribution (also known as the 44365 Fisher distribution) is a continuous probability distribution 44366 that arises in ANOVA tests, and is the ratio of two chi-square 44367 variates. 44368 44369 Parameters 44370 ---------- 44371 dfnum : float 44372 Degrees of freedom in numerator. Should be greater than zero. 44373 dfden : float 44374 Degrees of freedom in denominator. Should be greater than zero. 44375 size : {tuple, int}, optional 44376 Output shape. If the given shape is, e.g., ``(m, n, k)``, 44377 then ``m * n * k`` samples are drawn. By default only one sample 44378 is returned. 44379 44380 Returns 44381 ------- 44382 samples : {ndarray, scalar} 44383 Samples from the Fisher distribution. 44384 44385 See Also 44386 -------- 44387 scipy.stats.distributions.f : probability density function, 44388 distribution or cumulative density function, etc. 44389 44390 Notes 44391 ----- 44392 The F statistic is used to compare in-group variances to between-group 44393 variances. Calculating the distribution depends on the sampling, and 44394 so it is a function of the respective degrees of freedom in the 44395 problem. The variable `dfnum` is the number of samples minus one, the 44396 between-groups degrees of freedom, while `dfden` is the within-groups 44397 degrees of freedom, the sum of the number of samples in each group 44398 minus the number of groups. 44399 44400 References 44401 ---------- 44402 .. [1] Glantz, Stanton A. "Primer of Biostatistics.", McGraw-Hill, 44403 Fifth Edition, 2002. 44404 .. [2] Wikipedia, "F-distribution", 44405 http://en.wikipedia.org/wiki/F-distribution 44406 44407 Examples 44408 -------- 44409 An example from Glantz[1], pp 47-40. 44410 Two groups, children of diabetics (25 people) and children from people 44411 without diabetes (25 controls). Fasting blood glucose was measured, 44412 case group had a mean value of 86.1, controls had a mean value of 44413 82.2. Standard deviations were 2.09 and 2.49 respectively. Are these 44414 data consistent with the null hypothesis that the parents diabetic 44415 status does not affect their children's blood glucose levels? 44416 Calculating the F statistic from the data gives a value of 36.01. 44417 44418 Draw samples from the distribution: 44419 44420 >>> dfnum = 1. # between group degrees of freedom 44421 >>> dfden = 48. # within groups degrees of freedom 44422 >>> s = np.random.f(dfnum, dfden, 1000) 44423 44424 The lower bound for the top 1% of the samples is : 44425 44426 >>> sort(s)[-10] 44427 7.61988120985 44428 44429 So there is about a 1% chance that the F statistic will exceed 7.62, 44430 the measured value is 36, so the null hypothesis is rejected at the 1% 44431 level. 44432 44433 """ 44434 return ndarray() 44435 def gamma(self, shape, scale, size): 44436 """ 44437 gamma(shape, scale=1.0, size=None) 44438 44439 Draw samples from a Gamma distribution. 44440 44441 Samples are drawn from a Gamma distribution with specified parameters, 44442 `shape` (sometimes designated "k") and `scale` (sometimes designated 44443 "theta"), where both parameters are > 0. 44444 44445 Parameters 44446 ---------- 44447 shape : scalar > 0 44448 The shape of the gamma distribution. 44449 scale : scalar > 0, optional 44450 The scale of the gamma distribution. Default is equal to 1. 44451 size : shape_tuple, optional 44452 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 44453 ``m * n * k`` samples are drawn. 44454 44455 Returns 44456 ------- 44457 out : ndarray, float 44458 Returns one sample unless `size` parameter is specified. 44459 44460 See Also 44461 -------- 44462 scipy.stats.distributions.gamma : probability density function, 44463 distribution or cumulative density function, etc. 44464 44465 Notes 44466 ----- 44467 The probability density for the Gamma distribution is 44468 44469 .. math:: p(x) = x^{k-1}\frac{e^{-x/\theta}}{\theta^k\Gamma(k)}, 44470 44471 where :math:`k` is the shape and :math:`\theta` the scale, 44472 and :math:`\Gamma` is the Gamma function. 44473 44474 The Gamma distribution is often used to model the times to failure of 44475 electronic components, and arises naturally in processes for which the 44476 waiting times between Poisson distributed events are relevant. 44477 44478 References 44479 ---------- 44480 .. [1] Weisstein, Eric W. "Gamma Distribution." From MathWorld--A 44481 Wolfram Web Resource. 44482 http://mathworld.wolfram.com/GammaDistribution.html 44483 .. [2] Wikipedia, "Gamma-distribution", 44484 http://en.wikipedia.org/wiki/Gamma-distribution 44485 44486 Examples 44487 -------- 44488 Draw samples from the distribution: 44489 44490 >>> shape, scale = 2., 2. # mean and dispersion 44491 >>> s = np.random.gamma(shape, scale, 1000) 44492 44493 Display the histogram of the samples, along with 44494 the probability density function: 44495 44496 >>> import matplotlib.pyplot as plt 44497 >>> import scipy.special as sps 44498 >>> count, bins, ignored = plt.hist(s, 50, normed=True) 44499 >>> y = bins**(shape-1)*(np.exp(-bins/scale) / 44500 ... (sps.gamma(shape)*scale**shape)) 44501 >>> plt.plot(bins, y, linewidth=2, color='r') 44502 >>> plt.show() 44503 44504 """ 44505 return ndarray() 44506 def geometric(self, p, size): 44507 """ 44508 geometric(p, size=None) 44509 44510 Draw samples from the geometric distribution. 44511 44512 Bernoulli trials are experiments with one of two outcomes: 44513 success or failure (an example of such an experiment is flipping 44514 a coin). The geometric distribution models the number of trials 44515 that must be run in order to achieve success. It is therefore 44516 supported on the positive integers, ``k = 1, 2, ...``. 44517 44518 The probability mass function of the geometric distribution is 44519 44520 .. math:: f(k) = (1 - p)^{k - 1} p 44521 44522 where `p` is the probability of success of an individual trial. 44523 44524 Parameters 44525 ---------- 44526 p : float 44527 The probability of success of an individual trial. 44528 size : tuple of ints 44529 Number of values to draw from the distribution. The output 44530 is shaped according to `size`. 44531 44532 Returns 44533 ------- 44534 out : ndarray 44535 Samples from the geometric distribution, shaped according to 44536 `size`. 44537 44538 Examples 44539 -------- 44540 Draw ten thousand values from the geometric distribution, 44541 with the probability of an individual success equal to 0.35: 44542 44543 >>> z = np.random.geometric(p=0.35, size=10000) 44544 44545 How many trials succeeded after a single run? 44546 44547 >>> (z == 1).sum() / 10000. 44548 0.34889999999999999 #random 44549 44550 """ 44551 return ndarray() 44552 def get_state(self, _): 44553 """ 44554 get_state() 44555 44556 Return a tuple representing the internal state of the generator. 44557 44558 For more details, see `set_state`. 44559 44560 Returns 44561 ------- 44562 out : tuple(str, ndarray of 624 uints, int, int, float) 44563 The returned tuple has the following items: 44564 44565 1. the string 'MT19937'. 44566 2. a 1-D array of 624 unsigned integer keys. 44567 3. an integer ``pos``. 44568 4. an integer ``has_gauss``. 44569 5. a float ``cached_gaussian``. 44570 44571 See Also 44572 -------- 44573 set_state 44574 44575 Notes 44576 ----- 44577 `set_state` and `get_state` are not needed to work with any of the 44578 random distributions in NumPy. If the internal state is manually altered, 44579 the user should know exactly what he/she is doing. 44580 44581 """ 44582 return None 44583 def gumbel(self, loc, scale, size): 44584 """ 44585 gumbel(loc=0.0, scale=1.0, size=None) 44586 44587 Gumbel distribution. 44588 44589 Draw samples from a Gumbel distribution with specified location and scale. 44590 For more information on the Gumbel distribution, see Notes and References 44591 below. 44592 44593 Parameters 44594 ---------- 44595 loc : float 44596 The location of the mode of the distribution. 44597 scale : float 44598 The scale parameter of the distribution. 44599 size : tuple of ints 44600 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 44601 ``m * n * k`` samples are drawn. 44602 44603 Returns 44604 ------- 44605 out : ndarray 44606 The samples 44607 44608 See Also 44609 -------- 44610 scipy.stats.gumbel_l 44611 scipy.stats.gumbel_r 44612 scipy.stats.genextreme 44613 probability density function, distribution, or cumulative density 44614 function, etc. for each of the above 44615 weibull 44616 44617 Notes 44618 ----- 44619 The Gumbel (or Smallest Extreme Value (SEV) or the Smallest Extreme Value 44620 Type I) distribution is one of a class of Generalized Extreme Value (GEV) 44621 distributions used in modeling extreme value problems. The Gumbel is a 44622 special case of the Extreme Value Type I distribution for maximums from 44623 distributions with "exponential-like" tails. 44624 44625 The probability density for the Gumbel distribution is 44626 44627 .. math:: p(x) = \frac{e^{-(x - \mu)/ \beta}}{\beta} e^{ -e^{-(x - \mu)/ 44628 \beta}}, 44629 44630 where :math:`\mu` is the mode, a location parameter, and :math:`\beta` is 44631 the scale parameter. 44632 44633 The Gumbel (named for German mathematician Emil Julius Gumbel) was used 44634 very early in the hydrology literature, for modeling the occurrence of 44635 flood events. It is also used for modeling maximum wind speed and rainfall 44636 rates. It is a "fat-tailed" distribution - the probability of an event in 44637 the tail of the distribution is larger than if one used a Gaussian, hence 44638 the surprisingly frequent occurrence of 100-year floods. Floods were 44639 initially modeled as a Gaussian process, which underestimated the frequency 44640 of extreme events. 44641 44642 44643 It is one of a class of extreme value distributions, the Generalized 44644 Extreme Value (GEV) distributions, which also includes the Weibull and 44645 Frechet. 44646 44647 The function has a mean of :math:`\mu + 0.57721\beta` and a variance of 44648 :math:`\frac{\pi^2}{6}\beta^2`. 44649 44650 References 44651 ---------- 44652 Gumbel, E. J., *Statistics of Extremes*, New York: Columbia University 44653 Press, 1958. 44654 44655 Reiss, R.-D. and Thomas, M., *Statistical Analysis of Extreme Values from 44656 Insurance, Finance, Hydrology and Other Fields*, Basel: Birkhauser Verlag, 44657 2001. 44658 44659 Examples 44660 -------- 44661 Draw samples from the distribution: 44662 44663 >>> mu, beta = 0, 0.1 # location and scale 44664 >>> s = np.random.gumbel(mu, beta, 1000) 44665 44666 Display the histogram of the samples, along with 44667 the probability density function: 44668 44669 >>> import matplotlib.pyplot as plt 44670 >>> count, bins, ignored = plt.hist(s, 30, normed=True) 44671 >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta) 44672 ... * np.exp( -np.exp( -(bins - mu) /beta) ), 44673 ... linewidth=2, color='r') 44674 >>> plt.show() 44675 44676 Show how an extreme value distribution can arise from a Gaussian process 44677 and compare to a Gaussian: 44678 44679 >>> means = [] 44680 >>> maxima = [] 44681 >>> for i in range(0,1000) : 44682 ... a = np.random.normal(mu, beta, 1000) 44683 ... means.append(a.mean()) 44684 ... maxima.append(a.max()) 44685 >>> count, bins, ignored = plt.hist(maxima, 30, normed=True) 44686 >>> beta = np.std(maxima)*np.pi/np.sqrt(6) 44687 >>> mu = np.mean(maxima) - 0.57721*beta 44688 >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta) 44689 ... * np.exp(-np.exp(-(bins - mu)/beta)), 44690 ... linewidth=2, color='r') 44691 >>> plt.plot(bins, 1/(beta * np.sqrt(2 * np.pi)) 44692 ... * np.exp(-(bins - mu)**2 / (2 * beta**2)), 44693 ... linewidth=2, color='g') 44694 >>> plt.show() 44695 44696 """ 44697 return ndarray() 44698 def hypergeometric(self, ngood, nbad, nsample, size): 44699 """ 44700 hypergeometric(ngood, nbad, nsample, size=None) 44701 44702 Draw samples from a Hypergeometric distribution. 44703 44704 Samples are drawn from a Hypergeometric distribution with specified 44705 parameters, ngood (ways to make a good selection), nbad (ways to make 44706 a bad selection), and nsample = number of items sampled, which is less 44707 than or equal to the sum ngood + nbad. 44708 44709 Parameters 44710 ---------- 44711 ngood : int or array_like 44712 Number of ways to make a good selection. Must be nonnegative. 44713 nbad : int or array_like 44714 Number of ways to make a bad selection. Must be nonnegative. 44715 nsample : int or array_like 44716 Number of items sampled. Must be at least 1 and at most 44717 ``ngood + nbad``. 44718 size : int or tuple of int 44719 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 44720 ``m * n * k`` samples are drawn. 44721 44722 Returns 44723 ------- 44724 samples : ndarray or scalar 44725 The values are all integers in [0, n]. 44726 44727 See Also 44728 -------- 44729 scipy.stats.distributions.hypergeom : probability density function, 44730 distribution or cumulative density function, etc. 44731 44732 Notes 44733 ----- 44734 The probability density for the Hypergeometric distribution is 44735 44736 .. math:: P(x) = \frac{\binom{m}{n}\binom{N-m}{n-x}}{\binom{N}{n}}, 44737 44738 where :math:`0 \le x \le m` and :math:`n+m-N \le x \le n` 44739 44740 for P(x) the probability of x successes, n = ngood, m = nbad, and 44741 N = number of samples. 44742 44743 Consider an urn with black and white marbles in it, ngood of them 44744 black and nbad are white. If you draw nsample balls without 44745 replacement, then the Hypergeometric distribution describes the 44746 distribution of black balls in the drawn sample. 44747 44748 Note that this distribution is very similar to the Binomial 44749 distribution, except that in this case, samples are drawn without 44750 replacement, whereas in the Binomial case samples are drawn with 44751 replacement (or the sample space is infinite). As the sample space 44752 becomes large, this distribution approaches the Binomial. 44753 44754 References 44755 ---------- 44756 .. [1] Lentner, Marvin, "Elementary Applied Statistics", Bogden 44757 and Quigley, 1972. 44758 .. [2] Weisstein, Eric W. "Hypergeometric Distribution." From 44759 MathWorld--A Wolfram Web Resource. 44760 http://mathworld.wolfram.com/HypergeometricDistribution.html 44761 .. [3] Wikipedia, "Hypergeometric-distribution", 44762 http://en.wikipedia.org/wiki/Hypergeometric-distribution 44763 44764 Examples 44765 -------- 44766 Draw samples from the distribution: 44767 44768 >>> ngood, nbad, nsamp = 100, 2, 10 44769 # number of good, number of bad, and number of samples 44770 >>> s = np.random.hypergeometric(ngood, nbad, nsamp, 1000) 44771 >>> hist(s) 44772 # note that it is very unlikely to grab both bad items 44773 44774 Suppose you have an urn with 15 white and 15 black marbles. 44775 If you pull 15 marbles at random, how likely is it that 44776 12 or more of them are one color? 44777 44778 >>> s = np.random.hypergeometric(15, 15, 15, 100000) 44779 >>> sum(s>=12)/100000. + sum(s<=3)/100000. 44780 # answer = 0.003 ... pretty unlikely! 44781 44782 """ 44783 return ndarray() if False else float() 44784 def laplace(self, loc, scale): 44785 """ 44786 laplace(loc=0.0, scale=1.0, size=None) 44787 44788 Draw samples from the Laplace or double exponential distribution with 44789 specified location (or mean) and scale (decay). 44790 44791 The Laplace distribution is similar to the Gaussian/normal distribution, 44792 but is sharper at the peak and has fatter tails. It represents the 44793 difference between two independent, identically distributed exponential 44794 random variables. 44795 44796 Parameters 44797 ---------- 44798 loc : float 44799 The position, :math:`\mu`, of the distribution peak. 44800 scale : float 44801 :math:`\lambda`, the exponential decay. 44802 44803 Notes 44804 ----- 44805 It has the probability density function 44806 44807 .. math:: f(x; \mu, \lambda) = \frac{1}{2\lambda} 44808 \exp\left(-\frac{|x - \mu|}{\lambda}\right). 44809 44810 The first law of Laplace, from 1774, states that the frequency of an error 44811 can be expressed as an exponential function of the absolute magnitude of 44812 the error, which leads to the Laplace distribution. For many problems in 44813 Economics and Health sciences, this distribution seems to model the data 44814 better than the standard Gaussian distribution 44815 44816 44817 References 44818 ---------- 44819 .. [1] Abramowitz, M. and Stegun, I. A. (Eds.). Handbook of Mathematical 44820 Functions with Formulas, Graphs, and Mathematical Tables, 9th 44821 printing. New York: Dover, 1972. 44822 44823 .. [2] The Laplace distribution and generalizations 44824 By Samuel Kotz, Tomasz J. Kozubowski, Krzysztof Podgorski, 44825 Birkhauser, 2001. 44826 44827 .. [3] Weisstein, Eric W. "Laplace Distribution." 44828 From MathWorld--A Wolfram Web Resource. 44829 http://mathworld.wolfram.com/LaplaceDistribution.html 44830 44831 .. [4] Wikipedia, "Laplace distribution", 44832 http://en.wikipedia.org/wiki/Laplace_distribution 44833 44834 Examples 44835 -------- 44836 Draw samples from the distribution 44837 44838 >>> loc, scale = 0., 1. 44839 >>> s = np.random.laplace(loc, scale, 1000) 44840 44841 Display the histogram of the samples, along with 44842 the probability density function: 44843 44844 >>> import matplotlib.pyplot as plt 44845 >>> count, bins, ignored = plt.hist(s, 30, normed=True) 44846 >>> x = np.arange(-8., 8., .01) 44847 >>> pdf = np.exp(-abs(x-loc/scale))/(2.*scale) 44848 >>> plt.plot(x, pdf) 44849 44850 Plot Gaussian for comparison: 44851 44852 >>> g = (1/(scale * np.sqrt(2 * np.pi)) * 44853 ... np.exp( - (x - loc)**2 / (2 * scale**2) )) 44854 >>> plt.plot(x,g) 44855 44856 """ 44857 return None 44858 def logistic(self, loc, scale, size): 44859 """ 44860 logistic(loc=0.0, scale=1.0, size=None) 44861 44862 Draw samples from a Logistic distribution. 44863 44864 Samples are drawn from a Logistic distribution with specified 44865 parameters, loc (location or mean, also median), and scale (>0). 44866 44867 Parameters 44868 ---------- 44869 loc : float 44870 44871 scale : float > 0. 44872 44873 size : {tuple, int} 44874 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 44875 ``m * n * k`` samples are drawn. 44876 44877 Returns 44878 ------- 44879 samples : {ndarray, scalar} 44880 where the values are all integers in [0, n]. 44881 44882 See Also 44883 -------- 44884 scipy.stats.distributions.logistic : probability density function, 44885 distribution or cumulative density function, etc. 44886 44887 Notes 44888 ----- 44889 The probability density for the Logistic distribution is 44890 44891 .. math:: P(x) = P(x) = \frac{e^{-(x-\mu)/s}}{s(1+e^{-(x-\mu)/s})^2}, 44892 44893 where :math:`\mu` = location and :math:`s` = scale. 44894 44895 The Logistic distribution is used in Extreme Value problems where it 44896 can act as a mixture of Gumbel distributions, in Epidemiology, and by 44897 the World Chess Federation (FIDE) where it is used in the Elo ranking 44898 system, assuming the performance of each player is a logistically 44899 distributed random variable. 44900 44901 References 44902 ---------- 44903 .. [1] Reiss, R.-D. and Thomas M. (2001), Statistical Analysis of Extreme 44904 Values, from Insurance, Finance, Hydrology and Other Fields, 44905 Birkhauser Verlag, Basel, pp 132-133. 44906 .. [2] Weisstein, Eric W. "Logistic Distribution." From 44907 MathWorld--A Wolfram Web Resource. 44908 http://mathworld.wolfram.com/LogisticDistribution.html 44909 .. [3] Wikipedia, "Logistic-distribution", 44910 http://en.wikipedia.org/wiki/Logistic-distribution 44911 44912 Examples 44913 -------- 44914 Draw samples from the distribution: 44915 44916 >>> loc, scale = 10, 1 44917 >>> s = np.random.logistic(loc, scale, 10000) 44918 >>> count, bins, ignored = plt.hist(s, bins=50) 44919 44920 # plot against distribution 44921 44922 >>> def logist(x, loc, scale): 44923 ... return exp((loc-x)/scale)/(scale*(1+exp((loc-x)/scale))**2) 44924 >>> plt.plot(bins, logist(bins, loc, scale)*count.max()/\ 44925 ... logist(bins, loc, scale).max()) 44926 >>> plt.show() 44927 44928 """ 44929 return ndarray() 44930 def lognormal(self, mean, sigma, size): 44931 """ 44932 lognormal(mean=0.0, sigma=1.0, size=None) 44933 44934 Return samples drawn from a log-normal distribution. 44935 44936 Draw samples from a log-normal distribution with specified mean, 44937 standard deviation, and array shape. Note that the mean and standard 44938 deviation are not the values for the distribution itself, but of the 44939 underlying normal distribution it is derived from. 44940 44941 Parameters 44942 ---------- 44943 mean : float 44944 Mean value of the underlying normal distribution 44945 sigma : float, > 0. 44946 Standard deviation of the underlying normal distribution 44947 size : tuple of ints 44948 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 44949 ``m * n * k`` samples are drawn. 44950 44951 Returns 44952 ------- 44953 samples : ndarray or float 44954 The desired samples. An array of the same shape as `size` if given, 44955 if `size` is None a float is returned. 44956 44957 See Also 44958 -------- 44959 scipy.stats.lognorm : probability density function, distribution, 44960 cumulative density function, etc. 44961 44962 Notes 44963 ----- 44964 A variable `x` has a log-normal distribution if `log(x)` is normally 44965 distributed. The probability density function for the log-normal 44966 distribution is: 44967 44968 .. math:: p(x) = \frac{1}{\sigma x \sqrt{2\pi}} 44969 e^{(-\frac{(ln(x)-\mu)^2}{2\sigma^2})} 44970 44971 where :math:`\mu` is the mean and :math:`\sigma` is the standard 44972 deviation of the normally distributed logarithm of the variable. 44973 A log-normal distribution results if a random variable is the *product* 44974 of a large number of independent, identically-distributed variables in 44975 the same way that a normal distribution results if the variable is the 44976 *sum* of a large number of independent, identically-distributed 44977 variables. 44978 44979 References 44980 ---------- 44981 Limpert, E., Stahel, W. A., and Abbt, M., "Log-normal Distributions 44982 across the Sciences: Keys and Clues," *BioScience*, Vol. 51, No. 5, 44983 May, 2001. http://stat.ethz.ch/~stahel/lognormal/bioscience.pdf 44984 44985 Reiss, R.D. and Thomas, M., *Statistical Analysis of Extreme Values*, 44986 Basel: Birkhauser Verlag, 2001, pp. 31-32. 44987 44988 Examples 44989 -------- 44990 Draw samples from the distribution: 44991 44992 >>> mu, sigma = 3., 1. # mean and standard deviation 44993 >>> s = np.random.lognormal(mu, sigma, 1000) 44994 44995 Display the histogram of the samples, along with 44996 the probability density function: 44997 44998 >>> import matplotlib.pyplot as plt 44999 >>> count, bins, ignored = plt.hist(s, 100, normed=True, align='mid') 45000 45001 >>> x = np.linspace(min(bins), max(bins), 10000) 45002 >>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)) 45003 ... / (x * sigma * np.sqrt(2 * np.pi))) 45004 45005 >>> plt.plot(x, pdf, linewidth=2, color='r') 45006 >>> plt.axis('tight') 45007 >>> plt.show() 45008 45009 Demonstrate that taking the products of random samples from a uniform 45010 distribution can be fit well by a log-normal probability density function. 45011 45012 >>> # Generate a thousand samples: each is the product of 100 random 45013 >>> # values, drawn from a normal distribution. 45014 >>> b = [] 45015 >>> for i in range(1000): 45016 ... a = 10. + np.random.random(100) 45017 ... b.append(np.product(a)) 45018 45019 >>> b = np.array(b) / np.min(b) # scale values to be positive 45020 >>> count, bins, ignored = plt.hist(b, 100, normed=True, align='center') 45021 >>> sigma = np.std(np.log(b)) 45022 >>> mu = np.mean(np.log(b)) 45023 45024 >>> x = np.linspace(min(bins), max(bins), 10000) 45025 >>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)) 45026 ... / (x * sigma * np.sqrt(2 * np.pi))) 45027 45028 >>> plt.plot(x, pdf, color='r', linewidth=2) 45029 >>> plt.show() 45030 45031 """ 45032 return ndarray() if False else float() 45033 def logseries(self, loc, scale, size): 45034 """ 45035 logseries(p, size=None) 45036 45037 Draw samples from a Logarithmic Series distribution. 45038 45039 Samples are drawn from a Log Series distribution with specified 45040 parameter, p (probability, 0 < p < 1). 45041 45042 Parameters 45043 ---------- 45044 loc : float 45045 45046 scale : float > 0. 45047 45048 size : {tuple, int} 45049 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 45050 ``m * n * k`` samples are drawn. 45051 45052 Returns 45053 ------- 45054 samples : {ndarray, scalar} 45055 where the values are all integers in [0, n]. 45056 45057 See Also 45058 -------- 45059 scipy.stats.distributions.logser : probability density function, 45060 distribution or cumulative density function, etc. 45061 45062 Notes 45063 ----- 45064 The probability density for the Log Series distribution is 45065 45066 .. math:: P(k) = \frac{-p^k}{k \ln(1-p)}, 45067 45068 where p = probability. 45069 45070 The Log Series distribution is frequently used to represent species 45071 richness and occurrence, first proposed by Fisher, Corbet, and 45072 Williams in 1943 [2]. It may also be used to model the numbers of 45073 occupants seen in cars [3]. 45074 45075 References 45076 ---------- 45077 .. [1] Buzas, Martin A.; Culver, Stephen J., Understanding regional 45078 species diversity through the log series distribution of 45079 occurrences: BIODIVERSITY RESEARCH Diversity & Distributions, 45080 Volume 5, Number 5, September 1999 , pp. 187-195(9). 45081 .. [2] Fisher, R.A,, A.S. Corbet, and C.B. Williams. 1943. The 45082 relation between the number of species and the number of 45083 individuals in a random sample of an animal population. 45084 Journal of Animal Ecology, 12:42-58. 45085 .. [3] D. J. Hand, F. Daly, D. Lunn, E. Ostrowski, A Handbook of Small 45086 Data Sets, CRC Press, 1994. 45087 .. [4] Wikipedia, "Logarithmic-distribution", 45088 http://en.wikipedia.org/wiki/Logarithmic-distribution 45089 45090 Examples 45091 -------- 45092 Draw samples from the distribution: 45093 45094 >>> a = .6 45095 >>> s = np.random.logseries(a, 10000) 45096 >>> count, bins, ignored = plt.hist(s) 45097 45098 # plot against distribution 45099 45100 >>> def logseries(k, p): 45101 ... return -p**k/(k*log(1-p)) 45102 >>> plt.plot(bins, logseries(bins, a)*count.max()/ 45103 logseries(bins, a).max(), 'r') 45104 >>> plt.show() 45105 45106 """ 45107 return ndarray() 45108 def multinomial(self, n, pvals, size): 45109 """ 45110 multinomial(n, pvals, size=None) 45111 45112 Draw samples from a multinomial distribution. 45113 45114 The multinomial distribution is a multivariate generalisation of the 45115 binomial distribution. Take an experiment with one of ``p`` 45116 possible outcomes. An example of such an experiment is throwing a dice, 45117 where the outcome can be 1 through 6. Each sample drawn from the 45118 distribution represents `n` such experiments. Its values, 45119 ``X_i = [X_0, X_1, ..., X_p]``, represent the number of times the outcome 45120 was ``i``. 45121 45122 Parameters 45123 ---------- 45124 n : int 45125 Number of experiments. 45126 pvals : sequence of floats, length p 45127 Probabilities of each of the ``p`` different outcomes. These 45128 should sum to 1 (however, the last element is always assumed to 45129 account for the remaining probability, as long as 45130 ``sum(pvals[:-1]) <= 1)``. 45131 size : tuple of ints 45132 Given a `size` of ``(M, N, K)``, then ``M*N*K`` samples are drawn, 45133 and the output shape becomes ``(M, N, K, p)``, since each sample 45134 has shape ``(p,)``. 45135 45136 Examples 45137 -------- 45138 Throw a dice 20 times: 45139 45140 >>> np.random.multinomial(20, [1/6.]*6, size=1) 45141 array([[4, 1, 7, 5, 2, 1]]) 45142 45143 It landed 4 times on 1, once on 2, etc. 45144 45145 Now, throw the dice 20 times, and 20 times again: 45146 45147 >>> np.random.multinomial(20, [1/6.]*6, size=2) 45148 array([[3, 4, 3, 3, 4, 3], 45149 [2, 4, 3, 4, 0, 7]]) 45150 45151 For the first run, we threw 3 times 1, 4 times 2, etc. For the second, 45152 we threw 2 times 1, 4 times 2, etc. 45153 45154 A loaded dice is more likely to land on number 6: 45155 45156 >>> np.random.multinomial(100, [1/7.]*5) 45157 array([13, 16, 13, 16, 42]) 45158 45159 """ 45160 return None 45161 def multivariate_normal(self, mean, cov, size): 45162 """ 45163 multivariate_normal(mean, cov[, size]) 45164 45165 Draw random samples from a multivariate normal distribution. 45166 45167 The multivariate normal, multinormal or Gaussian distribution is a 45168 generalization of the one-dimensional normal distribution to higher 45169 dimensions. Such a distribution is specified by its mean and 45170 covariance matrix. These parameters are analogous to the mean 45171 (average or "center") and variance (standard deviation, or "width," 45172 squared) of the one-dimensional normal distribution. 45173 45174 Parameters 45175 ---------- 45176 mean : 1-D array_like, of length N 45177 Mean of the N-dimensional distribution. 45178 cov : 2-D array_like, of shape (N, N) 45179 Covariance matrix of the distribution. Must be symmetric and 45180 positive semi-definite for "physically meaningful" results. 45181 size : int or tuple of ints, optional 45182 Given a shape of, for example, ``(m,n,k)``, ``m*n*k`` samples are 45183 generated, and packed in an `m`-by-`n`-by-`k` arrangement. Because 45184 each sample is `N`-dimensional, the output shape is ``(m,n,k,N)``. 45185 If no shape is specified, a single (`N`-D) sample is returned. 45186 45187 Returns 45188 ------- 45189 out : ndarray 45190 The drawn samples, of shape *size*, if that was provided. If not, 45191 the shape is ``(N,)``. 45192 45193 In other words, each entry ``out[i,j,...,:]`` is an N-dimensional 45194 value drawn from the distribution. 45195 45196 Notes 45197 ----- 45198 The mean is a coordinate in N-dimensional space, which represents the 45199 location where samples are most likely to be generated. This is 45200 analogous to the peak of the bell curve for the one-dimensional or 45201 univariate normal distribution. 45202 45203 Covariance indicates the level to which two variables vary together. 45204 From the multivariate normal distribution, we draw N-dimensional 45205 samples, :math:`X = [x_1, x_2, ... x_N]`. The covariance matrix 45206 element :math:`C_{ij}` is the covariance of :math:`x_i` and :math:`x_j`. 45207 The element :math:`C_{ii}` is the variance of :math:`x_i` (i.e. its 45208 "spread"). 45209 45210 Instead of specifying the full covariance matrix, popular 45211 approximations include: 45212 45213 - Spherical covariance (*cov* is a multiple of the identity matrix) 45214 - Diagonal covariance (*cov* has non-negative elements, and only on 45215 the diagonal) 45216 45217 This geometrical property can be seen in two dimensions by plotting 45218 generated data-points: 45219 45220 >>> mean = [0,0] 45221 >>> cov = [[1,0],[0,100]] # diagonal covariance, points lie on x or y-axis 45222 45223 >>> import matplotlib.pyplot as plt 45224 >>> x,y = np.random.multivariate_normal(mean,cov,5000).T 45225 >>> plt.plot(x,y,'x'); plt.axis('equal'); plt.show() 45226 45227 Note that the covariance matrix must be non-negative definite. 45228 45229 References 45230 ---------- 45231 Papoulis, A., *Probability, Random Variables, and Stochastic Processes*, 45232 3rd ed., New York: McGraw-Hill, 1991. 45233 45234 Duda, R. O., Hart, P. E., and Stork, D. G., *Pattern Classification*, 45235 2nd ed., New York: Wiley, 2001. 45236 45237 Examples 45238 -------- 45239 >>> mean = (1,2) 45240 >>> cov = [[1,0],[1,0]] 45241 >>> x = np.random.multivariate_normal(mean,cov,(3,3)) 45242 >>> x.shape 45243 (3, 3, 2) 45244 45245 The following is probably true, given that 0.6 is roughly twice the 45246 standard deviation: 45247 45248 >>> print list( (x[0,0,:] - mean) < 0.6 ) 45249 [True, True] 45250 45251 """ 45252 return ndarray() 45253 def negative_binomial(self, n, p, size): 45254 """ 45255 negative_binomial(n, p, size=None) 45256 45257 Draw samples from a negative_binomial distribution. 45258 45259 Samples are drawn from a negative_Binomial distribution with specified 45260 parameters, `n` trials and `p` probability of success where `n` is an 45261 integer > 0 and `p` is in the interval [0, 1]. 45262 45263 Parameters 45264 ---------- 45265 n : int 45266 Parameter, > 0. 45267 p : float 45268 Parameter, >= 0 and <=1. 45269 size : int or tuple of ints 45270 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 45271 ``m * n * k`` samples are drawn. 45272 45273 Returns 45274 ------- 45275 samples : int or ndarray of ints 45276 Drawn samples. 45277 45278 Notes 45279 ----- 45280 The probability density for the Negative Binomial distribution is 45281 45282 .. math:: P(N;n,p) = \binom{N+n-1}{n-1}p^{n}(1-p)^{N}, 45283 45284 where :math:`n-1` is the number of successes, :math:`p` is the probability 45285 of success, and :math:`N+n-1` is the number of trials. 45286 45287 The negative binomial distribution gives the probability of n-1 successes 45288 and N failures in N+n-1 trials, and success on the (N+n)th trial. 45289 45290 If one throws a die repeatedly until the third time a "1" appears, then the 45291 probability distribution of the number of non-"1"s that appear before the 45292 third "1" is a negative binomial distribution. 45293 45294 References 45295 ---------- 45296 .. [1] Weisstein, Eric W. "Negative Binomial Distribution." From 45297 MathWorld--A Wolfram Web Resource. 45298 http://mathworld.wolfram.com/NegativeBinomialDistribution.html 45299 .. [2] Wikipedia, "Negative binomial distribution", 45300 http://en.wikipedia.org/wiki/Negative_binomial_distribution 45301 45302 Examples 45303 -------- 45304 Draw samples from the distribution: 45305 45306 A real world example. A company drills wild-cat oil exploration wells, each 45307 with an estimated probability of success of 0.1. What is the probability 45308 of having one success for each successive well, that is what is the 45309 probability of a single success after drilling 5 wells, after 6 wells, 45310 etc.? 45311 45312 >>> s = np.random.negative_binomial(1, 0.1, 100000) 45313 >>> for i in range(1, 11): 45314 ... probability = sum(s<i) / 100000. 45315 ... print i, "wells drilled, probability of one success =", probability 45316 45317 """ 45318 return int() if False else ndarray() 45319 def noncentral_chisquare(self, df, nonc, size): 45320 """ 45321 noncentral_chisquare(df, nonc, size=None) 45322 45323 Draw samples from a noncentral chi-square distribution. 45324 45325 The noncentral :math:`\chi^2` distribution is a generalisation of 45326 the :math:`\chi^2` distribution. 45327 45328 Parameters 45329 ---------- 45330 df : int 45331 Degrees of freedom, should be >= 1. 45332 nonc : float 45333 Non-centrality, should be > 0. 45334 size : int or tuple of ints 45335 Shape of the output. 45336 45337 Notes 45338 ----- 45339 The probability density function for the noncentral Chi-square distribution 45340 is 45341 45342 .. math:: P(x;df,nonc) = \sum^{\infty}_{i=0} 45343 \frac{e^{-nonc/2}(nonc/2)^{i}}{i!}P_{Y_{df+2i}}(x), 45344 45345 where :math:`Y_{q}` is the Chi-square with q degrees of freedom. 45346 45347 In Delhi (2007), it is noted that the noncentral chi-square is useful in 45348 bombing and coverage problems, the probability of killing the point target 45349 given by the noncentral chi-squared distribution. 45350 45351 References 45352 ---------- 45353 .. [1] Delhi, M.S. Holla, "On a noncentral chi-square distribution in the 45354 analysis of weapon systems effectiveness", Metrika, Volume 15, 45355 Number 1 / December, 1970. 45356 .. [2] Wikipedia, "Noncentral chi-square distribution" 45357 http://en.wikipedia.org/wiki/Noncentral_chi-square_distribution 45358 45359 Examples 45360 -------- 45361 Draw values from the distribution and plot the histogram 45362 45363 >>> import matplotlib.pyplot as plt 45364 >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000), 45365 ... bins=200, normed=True) 45366 >>> plt.show() 45367 45368 Draw values from a noncentral chisquare with very small noncentrality, 45369 and compare to a chisquare. 45370 45371 >>> plt.figure() 45372 >>> values = plt.hist(np.random.noncentral_chisquare(3, .0000001, 100000), 45373 ... bins=np.arange(0., 25, .1), normed=True) 45374 >>> values2 = plt.hist(np.random.chisquare(3, 100000), 45375 ... bins=np.arange(0., 25, .1), normed=True) 45376 >>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob') 45377 >>> plt.show() 45378 45379 Demonstrate how large values of non-centrality lead to a more symmetric 45380 distribution. 45381 45382 >>> plt.figure() 45383 >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000), 45384 ... bins=200, normed=True) 45385 >>> plt.show() 45386 45387 """ 45388 return None 45389 def noncentral_f(self, dfnum, dfden, nonc, size): 45390 """ 45391 noncentral_f(dfnum, dfden, nonc, size=None) 45392 45393 Draw samples from the noncentral F distribution. 45394 45395 Samples are drawn from an F distribution with specified parameters, 45396 `dfnum` (degrees of freedom in numerator) and `dfden` (degrees of 45397 freedom in denominator), where both parameters > 1. 45398 `nonc` is the non-centrality parameter. 45399 45400 Parameters 45401 ---------- 45402 dfnum : int 45403 Parameter, should be > 1. 45404 dfden : int 45405 Parameter, should be > 1. 45406 nonc : float 45407 Parameter, should be >= 0. 45408 size : int or tuple of ints 45409 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 45410 ``m * n * k`` samples are drawn. 45411 45412 Returns 45413 ------- 45414 samples : scalar or ndarray 45415 Drawn samples. 45416 45417 Notes 45418 ----- 45419 When calculating the power of an experiment (power = probability of 45420 rejecting the null hypothesis when a specific alternative is true) the 45421 non-central F statistic becomes important. When the null hypothesis is 45422 true, the F statistic follows a central F distribution. When the null 45423 hypothesis is not true, then it follows a non-central F statistic. 45424 45425 References 45426 ---------- 45427 Weisstein, Eric W. "Noncentral F-Distribution." From MathWorld--A Wolfram 45428 Web Resource. http://mathworld.wolfram.com/NoncentralF-Distribution.html 45429 45430 Wikipedia, "Noncentral F distribution", 45431 http://en.wikipedia.org/wiki/Noncentral_F-distribution 45432 45433 Examples 45434 -------- 45435 In a study, testing for a specific alternative to the null hypothesis 45436 requires use of the Noncentral F distribution. We need to calculate the 45437 area in the tail of the distribution that exceeds the value of the F 45438 distribution for the null hypothesis. We'll plot the two probability 45439 distributions for comparison. 45440 45441 >>> dfnum = 3 # between group deg of freedom 45442 >>> dfden = 20 # within groups degrees of freedom 45443 >>> nonc = 3.0 45444 >>> nc_vals = np.random.noncentral_f(dfnum, dfden, nonc, 1000000) 45445 >>> NF = np.histogram(nc_vals, bins=50, normed=True) 45446 >>> c_vals = np.random.f(dfnum, dfden, 1000000) 45447 >>> F = np.histogram(c_vals, bins=50, normed=True) 45448 >>> plt.plot(F[1][1:], F[0]) 45449 >>> plt.plot(NF[1][1:], NF[0]) 45450 >>> plt.show() 45451 45452 """ 45453 return float() if False else ndarray() 45454 def normal(self, loc, scale, size): 45455 """ 45456 normal(loc=0.0, scale=1.0, size=None) 45457 45458 Draw random samples from a normal (Gaussian) distribution. 45459 45460 The probability density function of the normal distribution, first 45461 derived by De Moivre and 200 years later by both Gauss and Laplace 45462 independently [2]_, is often called the bell curve because of 45463 its characteristic shape (see the example below). 45464 45465 The normal distributions occurs often in nature. For example, it 45466 describes the commonly occurring distribution of samples influenced 45467 by a large number of tiny, random disturbances, each with its own 45468 unique distribution [2]_. 45469 45470 Parameters 45471 ---------- 45472 loc : float 45473 Mean ("centre") of the distribution. 45474 scale : float 45475 Standard deviation (spread or "width") of the distribution. 45476 size : tuple of ints 45477 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 45478 ``m * n * k`` samples are drawn. 45479 45480 See Also 45481 -------- 45482 scipy.stats.distributions.norm : probability density function, 45483 distribution or cumulative density function, etc. 45484 45485 Notes 45486 ----- 45487 The probability density for the Gaussian distribution is 45488 45489 .. math:: p(x) = \frac{1}{\sqrt{ 2 \pi \sigma^2 }} 45490 e^{ - \frac{ (x - \mu)^2 } {2 \sigma^2} }, 45491 45492 where :math:`\mu` is the mean and :math:`\sigma` the standard deviation. 45493 The square of the standard deviation, :math:`\sigma^2`, is called the 45494 variance. 45495 45496 The function has its peak at the mean, and its "spread" increases with 45497 the standard deviation (the function reaches 0.607 times its maximum at 45498 :math:`x + \sigma` and :math:`x - \sigma` [2]_). This implies that 45499 `numpy.random.normal` is more likely to return samples lying close to the 45500 mean, rather than those far away. 45501 45502 References 45503 ---------- 45504 .. [1] Wikipedia, "Normal distribution", 45505 http://en.wikipedia.org/wiki/Normal_distribution 45506 .. [2] P. R. Peebles Jr., "Central Limit Theorem" in "Probability, Random 45507 Variables and Random Signal Principles", 4th ed., 2001, 45508 pp. 51, 51, 125. 45509 45510 Examples 45511 -------- 45512 Draw samples from the distribution: 45513 45514 >>> mu, sigma = 0, 0.1 # mean and standard deviation 45515 >>> s = np.random.normal(mu, sigma, 1000) 45516 45517 Verify the mean and the variance: 45518 45519 >>> abs(mu - np.mean(s)) < 0.01 45520 True 45521 45522 >>> abs(sigma - np.std(s, ddof=1)) < 0.01 45523 True 45524 45525 Display the histogram of the samples, along with 45526 the probability density function: 45527 45528 >>> import matplotlib.pyplot as plt 45529 >>> count, bins, ignored = plt.hist(s, 30, normed=True) 45530 >>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * 45531 ... np.exp( - (bins - mu)**2 / (2 * sigma**2) ), 45532 ... linewidth=2, color='r') 45533 >>> plt.show() 45534 45535 """ 45536 return None 45537 def pareto(self, shape, size): 45538 """ 45539 pareto(a, size=None) 45540 45541 Draw samples from a Pareto II or Lomax distribution with specified shape. 45542 45543 The Lomax or Pareto II distribution is a shifted Pareto distribution. The 45544 classical Pareto distribution can be obtained from the Lomax distribution 45545 by adding the location parameter m, see below. The smallest value of the 45546 Lomax distribution is zero while for the classical Pareto distribution it 45547 is m, where the standard Pareto distribution has location m=1. 45548 Lomax can also be considered as a simplified version of the Generalized 45549 Pareto distribution (available in SciPy), with the scale set to one and 45550 the location set to zero. 45551 45552 The Pareto distribution must be greater than zero, and is unbounded above. 45553 It is also known as the "80-20 rule". In this distribution, 80 percent of 45554 the weights are in the lowest 20 percent of the range, while the other 20 45555 percent fill the remaining 80 percent of the range. 45556 45557 Parameters 45558 ---------- 45559 shape : float, > 0. 45560 Shape of the distribution. 45561 size : tuple of ints 45562 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 45563 ``m * n * k`` samples are drawn. 45564 45565 See Also 45566 -------- 45567 scipy.stats.distributions.lomax.pdf : probability density function, 45568 distribution or cumulative density function, etc. 45569 scipy.stats.distributions.genpareto.pdf : probability density function, 45570 distribution or cumulative density function, etc. 45571 45572 Notes 45573 ----- 45574 The probability density for the Pareto distribution is 45575 45576 .. math:: p(x) = \frac{am^a}{x^{a+1}} 45577 45578 where :math:`a` is the shape and :math:`m` the location 45579 45580 The Pareto distribution, named after the Italian economist Vilfredo Pareto, 45581 is a power law probability distribution useful in many real world problems. 45582 Outside the field of economics it is generally referred to as the Bradford 45583 distribution. Pareto developed the distribution to describe the 45584 distribution of wealth in an economy. It has also found use in insurance, 45585 web page access statistics, oil field sizes, and many other problems, 45586 including the download frequency for projects in Sourceforge [1]. It is 45587 one of the so-called "fat-tailed" distributions. 45588 45589 45590 References 45591 ---------- 45592 .. [1] Francis Hunt and Paul Johnson, On the Pareto Distribution of 45593 Sourceforge projects. 45594 .. [2] Pareto, V. (1896). Course of Political Economy. Lausanne. 45595 .. [3] Reiss, R.D., Thomas, M.(2001), Statistical Analysis of Extreme 45596 Values, Birkhauser Verlag, Basel, pp 23-30. 45597 .. [4] Wikipedia, "Pareto distribution", 45598 http://en.wikipedia.org/wiki/Pareto_distribution 45599 45600 Examples 45601 -------- 45602 Draw samples from the distribution: 45603 45604 >>> a, m = 3., 1. # shape and mode 45605 >>> s = np.random.pareto(a, 1000) + m 45606 45607 Display the histogram of the samples, along with 45608 the probability density function: 45609 45610 >>> import matplotlib.pyplot as plt 45611 >>> count, bins, ignored = plt.hist(s, 100, normed=True, align='center') 45612 >>> fit = a*m**a/bins**(a+1) 45613 >>> plt.plot(bins, max(count)*fit/max(fit),linewidth=2, color='r') 45614 >>> plt.show() 45615 45616 """ 45617 return None 45618 def permutation(self, x): 45619 """ 45620 permutation(x) 45621 45622 Randomly permute a sequence, or return a permuted range. 45623 45624 If `x` is a multi-dimensional array, it is only shuffled along its 45625 first index. 45626 45627 Parameters 45628 ---------- 45629 x : int or array_like 45630 If `x` is an integer, randomly permute ``np.arange(x)``. 45631 If `x` is an array, make a copy and shuffle the elements 45632 randomly. 45633 45634 Returns 45635 ------- 45636 out : ndarray 45637 Permuted sequence or array range. 45638 45639 Examples 45640 -------- 45641 >>> np.random.permutation(10) 45642 array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6]) 45643 45644 >>> np.random.permutation([1, 4, 9, 12, 15]) 45645 array([15, 1, 9, 4, 12]) 45646 45647 >>> arr = np.arange(9).reshape((3, 3)) 45648 >>> np.random.permutation(arr) 45649 array([[6, 7, 8], 45650 [0, 1, 2], 45651 [3, 4, 5]]) 45652 45653 """ 45654 return ndarray() 45655 def poisson(self, lam, size): 45656 """ 45657 poisson(lam=1.0, size=None) 45658 45659 Draw samples from a Poisson distribution. 45660 45661 The Poisson distribution is the limit of the Binomial 45662 distribution for large N. 45663 45664 Parameters 45665 ---------- 45666 lam : float 45667 Expectation of interval, should be >= 0. 45668 size : int or tuple of ints, optional 45669 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 45670 ``m * n * k`` samples are drawn. 45671 45672 Notes 45673 ----- 45674 The Poisson distribution 45675 45676 .. math:: f(k; \lambda)=\frac{\lambda^k e^{-\lambda}}{k!} 45677 45678 For events with an expected separation :math:`\lambda` the Poisson 45679 distribution :math:`f(k; \lambda)` describes the probability of 45680 :math:`k` events occurring within the observed interval :math:`\lambda`. 45681 45682 Because the output is limited to the range of the C long type, a 45683 ValueError is raised when `lam` is within 10 sigma of the maximum 45684 representable value. 45685 45686 References 45687 ---------- 45688 .. [1] Weisstein, Eric W. "Poisson Distribution." From MathWorld--A Wolfram 45689 Web Resource. http://mathworld.wolfram.com/PoissonDistribution.html 45690 .. [2] Wikipedia, "Poisson distribution", 45691 http://en.wikipedia.org/wiki/Poisson_distribution 45692 45693 Examples 45694 -------- 45695 Draw samples from the distribution: 45696 45697 >>> import numpy as np 45698 >>> s = np.random.poisson(5, 10000) 45699 45700 Display histogram of the sample: 45701 45702 >>> import matplotlib.pyplot as plt 45703 >>> count, bins, ignored = plt.hist(s, 14, normed=True) 45704 >>> plt.show() 45705 45706 """ 45707 return None 45708 def power(self, a, size): 45709 """ 45710 power(a, size=None) 45711 45712 Draws samples in [0, 1] from a power distribution with positive 45713 exponent a - 1. 45714 45715 Also known as the power function distribution. 45716 45717 Parameters 45718 ---------- 45719 a : float 45720 parameter, > 0 45721 size : tuple of ints 45722 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 45723 ``m * n * k`` samples are drawn. 45724 45725 Returns 45726 ------- 45727 samples : {ndarray, scalar} 45728 The returned samples lie in [0, 1]. 45729 45730 Raises 45731 ------ 45732 ValueError 45733 If a<1. 45734 45735 Notes 45736 ----- 45737 The probability density function is 45738 45739 .. math:: P(x; a) = ax^{a-1}, 0 \le x \le 1, a>0. 45740 45741 The power function distribution is just the inverse of the Pareto 45742 distribution. It may also be seen as a special case of the Beta 45743 distribution. 45744 45745 It is used, for example, in modeling the over-reporting of insurance 45746 claims. 45747 45748 References 45749 ---------- 45750 .. [1] Christian Kleiber, Samuel Kotz, "Statistical size distributions 45751 in economics and actuarial sciences", Wiley, 2003. 45752 .. [2] Heckert, N. A. and Filliben, James J. (2003). NIST Handbook 148: 45753 Dataplot Reference Manual, Volume 2: Let Subcommands and Library 45754 Functions", National Institute of Standards and Technology Handbook 45755 Series, June 2003. 45756 http://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/powpdf.pdf 45757 45758 Examples 45759 -------- 45760 Draw samples from the distribution: 45761 45762 >>> a = 5. # shape 45763 >>> samples = 1000 45764 >>> s = np.random.power(a, samples) 45765 45766 Display the histogram of the samples, along with 45767 the probability density function: 45768 45769 >>> import matplotlib.pyplot as plt 45770 >>> count, bins, ignored = plt.hist(s, bins=30) 45771 >>> x = np.linspace(0, 1, 100) 45772 >>> y = a*x**(a-1.) 45773 >>> normed_y = samples*np.diff(bins)[0]*y 45774 >>> plt.plot(x, normed_y) 45775 >>> plt.show() 45776 45777 Compare the power function distribution to the inverse of the Pareto. 45778 45779 >>> from scipy import stats 45780 >>> rvs = np.random.power(5, 1000000) 45781 >>> rvsp = np.random.pareto(5, 1000000) 45782 >>> xx = np.linspace(0,1,100) 45783 >>> powpdf = stats.powerlaw.pdf(xx,5) 45784 45785 >>> plt.figure() 45786 >>> plt.hist(rvs, bins=50, normed=True) 45787 >>> plt.plot(xx,powpdf,'r-') 45788 >>> plt.title('np.random.power(5)') 45789 45790 >>> plt.figure() 45791 >>> plt.hist(1./(1.+rvsp), bins=50, normed=True) 45792 >>> plt.plot(xx,powpdf,'r-') 45793 >>> plt.title('inverse of 1 + np.random.pareto(5)') 45794 45795 >>> plt.figure() 45796 >>> plt.hist(1./(1.+rvsp), bins=50, normed=True) 45797 >>> plt.plot(xx,powpdf,'r-') 45798 >>> plt.title('inverse of stats.pareto(5)') 45799 45800 """ 45801 return ndarray() 45802 print_function = instance() 45803 def rand(self, d0d1more_argsdn): 45804 """ 45805 rand(d0, d1, ..., dn) 45806 45807 Random values in a given shape. 45808 45809 Create an array of the given shape and propagate it with 45810 random samples from a uniform distribution 45811 over ``[0, 1)``. 45812 45813 Parameters 45814 ---------- 45815 d0, d1, ..., dn : int, optional 45816 The dimensions of the returned array, should all be positive. 45817 If no argument is given a single Python float is returned. 45818 45819 Returns 45820 ------- 45821 out : ndarray, shape ``(d0, d1, ..., dn)`` 45822 Random values. 45823 45824 See Also 45825 -------- 45826 random 45827 45828 Notes 45829 ----- 45830 This is a convenience function. If you want an interface that 45831 takes a shape-tuple as the first argument, refer to 45832 np.random.random_sample . 45833 45834 Examples 45835 -------- 45836 >>> np.random.rand(3,2) 45837 array([[ 0.14022471, 0.96360618], #random 45838 [ 0.37601032, 0.25528411], #random 45839 [ 0.49313049, 0.94909878]]) #random 45840 45841 """ 45842 return None 45843 def randint(self, low, high, size): 45844 """ 45845 randint(low, high=None, size=None) 45846 45847 Return random integers from `low` (inclusive) to `high` (exclusive). 45848 45849 Return random integers from the "discrete uniform" distribution in the 45850 "half-open" interval [`low`, `high`). If `high` is None (the default), 45851 then results are from [0, `low`). 45852 45853 Parameters 45854 ---------- 45855 low : int 45856 Lowest (signed) integer to be drawn from the distribution (unless 45857 ``high=None``, in which case this parameter is the *highest* such 45858 integer). 45859 high : int, optional 45860 If provided, one above the largest (signed) integer to be drawn 45861 from the distribution (see above for behavior if ``high=None``). 45862 size : int or tuple of ints, optional 45863 Output shape. Default is None, in which case a single int is 45864 returned. 45865 45866 Returns 45867 ------- 45868 out : int or ndarray of ints 45869 `size`-shaped array of random integers from the appropriate 45870 distribution, or a single such random int if `size` not provided. 45871 45872 See Also 45873 -------- 45874 random.random_integers : similar to `randint`, only for the closed 45875 interval [`low`, `high`], and 1 is the lowest value if `high` is 45876 omitted. In particular, this other one is the one to use to generate 45877 uniformly distributed discrete non-integers. 45878 45879 Examples 45880 -------- 45881 >>> np.random.randint(2, size=10) 45882 array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) 45883 >>> np.random.randint(1, size=10) 45884 array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) 45885 45886 Generate a 2 x 4 array of ints between 0 and 4, inclusive: 45887 45888 >>> np.random.randint(5, size=(2, 4)) 45889 array([[4, 0, 2, 1], 45890 [3, 2, 2, 0]]) 45891 45892 """ 45893 return int() if False else ndarray() 45894 def randn(self, d0d1more_argsdn): 45895 """ 45896 randn(d0, d1, ..., dn) 45897 45898 Return a sample (or samples) from the "standard normal" distribution. 45899 45900 If positive, int_like or int-convertible arguments are provided, 45901 `randn` generates an array of shape ``(d0, d1, ..., dn)``, filled 45902 with random floats sampled from a univariate "normal" (Gaussian) 45903 distribution of mean 0 and variance 1 (if any of the :math:`d_i` are 45904 floats, they are first converted to integers by truncation). A single 45905 float randomly sampled from the distribution is returned if no 45906 argument is provided. 45907 45908 This is a convenience function. If you want an interface that takes a 45909 tuple as the first argument, use `numpy.random.standard_normal` instead. 45910 45911 Parameters 45912 ---------- 45913 d0, d1, ..., dn : int, optional 45914 The dimensions of the returned array, should be all positive. 45915 If no argument is given a single Python float is returned. 45916 45917 Returns 45918 ------- 45919 Z : ndarray or float 45920 A ``(d0, d1, ..., dn)``-shaped array of floating-point samples from 45921 the standard normal distribution, or a single such float if 45922 no parameters were supplied. 45923 45924 See Also 45925 -------- 45926 random.standard_normal : Similar, but takes a tuple as its argument. 45927 45928 Notes 45929 ----- 45930 For random samples from :math:`N(\mu, \sigma^2)`, use: 45931 45932 ``sigma * np.random.randn(...) + mu`` 45933 45934 Examples 45935 -------- 45936 >>> np.random.randn() 45937 2.1923875335537315 #random 45938 45939 Two-by-four array of samples from N(3, 6.25): 45940 45941 >>> 2.5 * np.random.randn(2, 4) + 3 45942 array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], #random 45943 [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) #random 45944 45945 """ 45946 return ndarray() if False else float() 45947 def random_sample(self, size): 45948 """ 45949 random_sample(size=None) 45950 45951 Return random floats in the half-open interval [0.0, 1.0). 45952 45953 Results are from the "continuous uniform" distribution over the 45954 stated interval. To sample :math:`Unif[a, b), b > a` multiply 45955 the output of `random_sample` by `(b-a)` and add `a`:: 45956 45957 (b - a) * random_sample() + a 45958 45959 Parameters 45960 ---------- 45961 size : int or tuple of ints, optional 45962 Defines the shape of the returned array of random floats. If None 45963 (the default), returns a single float. 45964 45965 Returns 45966 ------- 45967 out : float or ndarray of floats 45968 Array of random floats of shape `size` (unless ``size=None``, in which 45969 case a single float is returned). 45970 45971 Examples 45972 -------- 45973 >>> np.random.random_sample() 45974 0.47108547995356098 45975 >>> type(np.random.random_sample()) 45976 <type 'float'> 45977 >>> np.random.random_sample((5,)) 45978 array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428]) 45979 45980 Three-by-two array of random numbers from [-5, 0): 45981 45982 >>> 5 * np.random.random_sample((3, 2)) - 5 45983 array([[-3.99149989, -0.52338984], 45984 [-2.99091858, -0.79479508], 45985 [-1.23204345, -1.75224494]]) 45986 45987 """ 45988 return float() if False else ndarray() 45989 def random_integers(self, low, high, size): 45990 """ 45991 random_integers(low, high=None, size=None) 45992 45993 Return random integers between `low` and `high`, inclusive. 45994 45995 Return random integers from the "discrete uniform" distribution in the 45996 closed interval [`low`, `high`]. If `high` is None (the default), 45997 then results are from [1, `low`]. 45998 45999 Parameters 46000 ---------- 46001 low : int 46002 Lowest (signed) integer to be drawn from the distribution (unless 46003 ``high=None``, in which case this parameter is the *highest* such 46004 integer). 46005 high : int, optional 46006 If provided, the largest (signed) integer to be drawn from the 46007 distribution (see above for behavior if ``high=None``). 46008 size : int or tuple of ints, optional 46009 Output shape. Default is None, in which case a single int is returned. 46010 46011 Returns 46012 ------- 46013 out : int or ndarray of ints 46014 `size`-shaped array of random integers from the appropriate 46015 distribution, or a single such random int if `size` not provided. 46016 46017 See Also 46018 -------- 46019 random.randint : Similar to `random_integers`, only for the half-open 46020 interval [`low`, `high`), and 0 is the lowest value if `high` is 46021 omitted. 46022 46023 Notes 46024 ----- 46025 To sample from N evenly spaced floating-point numbers between a and b, 46026 use:: 46027 46028 a + (b - a) * (np.random.random_integers(N) - 1) / (N - 1.) 46029 46030 Examples 46031 -------- 46032 >>> np.random.random_integers(5) 46033 4 46034 >>> type(np.random.random_integers(5)) 46035 <type 'int'> 46036 >>> np.random.random_integers(5, size=(3.,2.)) 46037 array([[5, 4], 46038 [3, 3], 46039 [4, 5]]) 46040 46041 Choose five random numbers from the set of five evenly-spaced 46042 numbers between 0 and 2.5, inclusive (*i.e.*, from the set 46043 :math:`{0, 5/8, 10/8, 15/8, 20/8}`): 46044 46045 >>> 2.5 * (np.random.random_integers(5, size=(5,)) - 1) / 4. 46046 array([ 0.625, 1.25 , 0.625, 0.625, 2.5 ]) 46047 46048 Roll two six sided dice 1000 times and sum the results: 46049 46050 >>> d1 = np.random.random_integers(1, 6, 1000) 46051 >>> d2 = np.random.random_integers(1, 6, 1000) 46052 >>> dsums = d1 + d2 46053 46054 Display results as a histogram: 46055 46056 >>> import matplotlib.pyplot as plt 46057 >>> count, bins, ignored = plt.hist(dsums, 11, normed=True) 46058 >>> plt.show() 46059 46060 """ 46061 return int() if False else ndarray() 46062 def random_sample(self, size): 46063 """ 46064 random_sample(size=None) 46065 46066 Return random floats in the half-open interval [0.0, 1.0). 46067 46068 Results are from the "continuous uniform" distribution over the 46069 stated interval. To sample :math:`Unif[a, b), b > a` multiply 46070 the output of `random_sample` by `(b-a)` and add `a`:: 46071 46072 (b - a) * random_sample() + a 46073 46074 Parameters 46075 ---------- 46076 size : int or tuple of ints, optional 46077 Defines the shape of the returned array of random floats. If None 46078 (the default), returns a single float. 46079 46080 Returns 46081 ------- 46082 out : float or ndarray of floats 46083 Array of random floats of shape `size` (unless ``size=None``, in which 46084 case a single float is returned). 46085 46086 Examples 46087 -------- 46088 >>> np.random.random_sample() 46089 0.47108547995356098 46090 >>> type(np.random.random_sample()) 46091 <type 'float'> 46092 >>> np.random.random_sample((5,)) 46093 array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428]) 46094 46095 Three-by-two array of random numbers from [-5, 0): 46096 46097 >>> 5 * np.random.random_sample((3, 2)) - 5 46098 array([[-3.99149989, -0.52338984], 46099 [-2.99091858, -0.79479508], 46100 [-1.23204345, -1.75224494]]) 46101 46102 """ 46103 return float() if False else ndarray() 46104 def random_sample(self, size): 46105 """ 46106 random_sample(size=None) 46107 46108 Return random floats in the half-open interval [0.0, 1.0). 46109 46110 Results are from the "continuous uniform" distribution over the 46111 stated interval. To sample :math:`Unif[a, b), b > a` multiply 46112 the output of `random_sample` by `(b-a)` and add `a`:: 46113 46114 (b - a) * random_sample() + a 46115 46116 Parameters 46117 ---------- 46118 size : int or tuple of ints, optional 46119 Defines the shape of the returned array of random floats. If None 46120 (the default), returns a single float. 46121 46122 Returns 46123 ------- 46124 out : float or ndarray of floats 46125 Array of random floats of shape `size` (unless ``size=None``, in which 46126 case a single float is returned). 46127 46128 Examples 46129 -------- 46130 >>> np.random.random_sample() 46131 0.47108547995356098 46132 >>> type(np.random.random_sample()) 46133 <type 'float'> 46134 >>> np.random.random_sample((5,)) 46135 array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428]) 46136 46137 Three-by-two array of random numbers from [-5, 0): 46138 46139 >>> 5 * np.random.random_sample((3, 2)) - 5 46140 array([[-3.99149989, -0.52338984], 46141 [-2.99091858, -0.79479508], 46142 [-1.23204345, -1.75224494]]) 46143 46144 """ 46145 return float() if False else ndarray() 46146 def rayleigh(self, scale, size): 46147 """ 46148 rayleigh(scale=1.0, size=None) 46149 46150 Draw samples from a Rayleigh distribution. 46151 46152 The :math:`\chi` and Weibull distributions are generalizations of the 46153 Rayleigh. 46154 46155 Parameters 46156 ---------- 46157 scale : scalar 46158 Scale, also equals the mode. Should be >= 0. 46159 size : int or tuple of ints, optional 46160 Shape of the output. Default is None, in which case a single 46161 value is returned. 46162 46163 Notes 46164 ----- 46165 The probability density function for the Rayleigh distribution is 46166 46167 .. math:: P(x;scale) = \frac{x}{scale^2}e^{\frac{-x^2}{2 \cdotp scale^2}} 46168 46169 The Rayleigh distribution arises if the wind speed and wind direction are 46170 both gaussian variables, then the vector wind velocity forms a Rayleigh 46171 distribution. The Rayleigh distribution is used to model the expected 46172 output from wind turbines. 46173 46174 References 46175 ---------- 46176 .. [1] Brighton Webs Ltd., Rayleigh Distribution, 46177 http://www.brighton-webs.co.uk/distributions/rayleigh.asp 46178 .. [2] Wikipedia, "Rayleigh distribution" 46179 http://en.wikipedia.org/wiki/Rayleigh_distribution 46180 46181 Examples 46182 -------- 46183 Draw values from the distribution and plot the histogram 46184 46185 >>> values = hist(np.random.rayleigh(3, 100000), bins=200, normed=True) 46186 46187 Wave heights tend to follow a Rayleigh distribution. If the mean wave 46188 height is 1 meter, what fraction of waves are likely to be larger than 3 46189 meters? 46190 46191 >>> meanvalue = 1 46192 >>> modevalue = np.sqrt(2 / np.pi) * meanvalue 46193 >>> s = np.random.rayleigh(modevalue, 1000000) 46194 46195 The percentage of waves larger than 3 meters is: 46196 46197 >>> 100.*sum(s>3)/1000000. 46198 0.087300000000000003 46199 46200 """ 46201 return None 46202 def random_sample(self, size): 46203 """ 46204 random_sample(size=None) 46205 46206 Return random floats in the half-open interval [0.0, 1.0). 46207 46208 Results are from the "continuous uniform" distribution over the 46209 stated interval. To sample :math:`Unif[a, b), b > a` multiply 46210 the output of `random_sample` by `(b-a)` and add `a`:: 46211 46212 (b - a) * random_sample() + a 46213 46214 Parameters 46215 ---------- 46216 size : int or tuple of ints, optional 46217 Defines the shape of the returned array of random floats. If None 46218 (the default), returns a single float. 46219 46220 Returns 46221 ------- 46222 out : float or ndarray of floats 46223 Array of random floats of shape `size` (unless ``size=None``, in which 46224 case a single float is returned). 46225 46226 Examples 46227 -------- 46228 >>> np.random.random_sample() 46229 0.47108547995356098 46230 >>> type(np.random.random_sample()) 46231 <type 'float'> 46232 >>> np.random.random_sample((5,)) 46233 array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428]) 46234 46235 Three-by-two array of random numbers from [-5, 0): 46236 46237 >>> 5 * np.random.random_sample((3, 2)) - 5 46238 array([[-3.99149989, -0.52338984], 46239 [-2.99091858, -0.79479508], 46240 [-1.23204345, -1.75224494]]) 46241 46242 """ 46243 return float() if False else ndarray() 46244 def seed(self, seed): 46245 """ 46246 seed(seed=None) 46247 46248 Seed the generator. 46249 46250 This method is called when `RandomState` is initialized. It can be 46251 called again to re-seed the generator. For details, see `RandomState`. 46252 46253 Parameters 46254 ---------- 46255 seed : int or array_like, optional 46256 Seed for `RandomState`. 46257 46258 See Also 46259 -------- 46260 RandomState 46261 46262 """ 46263 return None 46264 def set_state(self, state): 46265 """ 46266 set_state(state) 46267 46268 Set the internal state of the generator from a tuple. 46269 46270 For use if one has reason to manually (re-)set the internal state of the 46271 "Mersenne Twister"[1]_ pseudo-random number generating algorithm. 46272 46273 Parameters 46274 ---------- 46275 state : tuple(str, ndarray of 624 uints, int, int, float) 46276 The `state` tuple has the following items: 46277 46278 1. the string 'MT19937', specifying the Mersenne Twister algorithm. 46279 2. a 1-D array of 624 unsigned integers ``keys``. 46280 3. an integer ``pos``. 46281 4. an integer ``has_gauss``. 46282 5. a float ``cached_gaussian``. 46283 46284 Returns 46285 ------- 46286 out : None 46287 Returns 'None' on success. 46288 46289 See Also 46290 -------- 46291 get_state 46292 46293 Notes 46294 ----- 46295 `set_state` and `get_state` are not needed to work with any of the 46296 random distributions in NumPy. If the internal state is manually altered, 46297 the user should know exactly what he/she is doing. 46298 46299 For backwards compatibility, the form (str, array of 624 uints, int) is 46300 also accepted although it is missing some information about the cached 46301 Gaussian value: ``state = ('MT19937', keys, pos)``. 46302 46303 References 46304 ---------- 46305 .. [1] M. Matsumoto and T. Nishimura, "Mersenne Twister: A 46306 623-dimensionally equidistributed uniform pseudorandom number 46307 generator," *ACM Trans. on Modeling and Computer Simulation*, 46308 Vol. 8, No. 1, pp. 3-30, Jan. 1998. 46309 46310 """ 46311 return None 46312 def shuffle(self, x): 46313 """ 46314 shuffle(x) 46315 46316 Modify a sequence in-place by shuffling its contents. 46317 46318 Parameters 46319 ---------- 46320 x : array_like 46321 The array or list to be shuffled. 46322 46323 Returns 46324 ------- 46325 None 46326 46327 Examples 46328 -------- 46329 >>> arr = np.arange(10) 46330 >>> np.random.shuffle(arr) 46331 >>> arr 46332 [1 7 5 2 9 4 3 6 0 8] 46333 46334 This function only shuffles the array along the first index of a 46335 multi-dimensional array: 46336 46337 >>> arr = np.arange(9).reshape((3, 3)) 46338 >>> np.random.shuffle(arr) 46339 >>> arr 46340 array([[3, 4, 5], 46341 [6, 7, 8], 46342 [0, 1, 2]]) 46343 46344 """ 46345 return None 46346 def standard_cauchy(self, size): 46347 """ 46348 standard_cauchy(size=None) 46349 46350 Standard Cauchy distribution with mode = 0. 46351 46352 Also known as the Lorentz distribution. 46353 46354 Parameters 46355 ---------- 46356 size : int or tuple of ints 46357 Shape of the output. 46358 46359 Returns 46360 ------- 46361 samples : ndarray or scalar 46362 The drawn samples. 46363 46364 Notes 46365 ----- 46366 The probability density function for the full Cauchy distribution is 46367 46368 .. math:: P(x; x_0, \gamma) = \frac{1}{\pi \gamma \bigl[ 1+ 46369 (\frac{x-x_0}{\gamma})^2 \bigr] } 46370 46371 and the Standard Cauchy distribution just sets :math:`x_0=0` and 46372 :math:`\gamma=1` 46373 46374 The Cauchy distribution arises in the solution to the driven harmonic 46375 oscillator problem, and also describes spectral line broadening. It 46376 also describes the distribution of values at which a line tilted at 46377 a random angle will cut the x axis. 46378 46379 When studying hypothesis tests that assume normality, seeing how the 46380 tests perform on data from a Cauchy distribution is a good indicator of 46381 their sensitivity to a heavy-tailed distribution, since the Cauchy looks 46382 very much like a Gaussian distribution, but with heavier tails. 46383 46384 References 46385 ---------- 46386 .. [1] NIST/SEMATECH e-Handbook of Statistical Methods, "Cauchy 46387 Distribution", 46388 http://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm 46389 .. [2] Weisstein, Eric W. "Cauchy Distribution." From MathWorld--A 46390 Wolfram Web Resource. 46391 http://mathworld.wolfram.com/CauchyDistribution.html 46392 .. [3] Wikipedia, "Cauchy distribution" 46393 http://en.wikipedia.org/wiki/Cauchy_distribution 46394 46395 Examples 46396 -------- 46397 Draw samples and plot the distribution: 46398 46399 >>> s = np.random.standard_cauchy(1000000) 46400 >>> s = s[(s>-25) & (s<25)] # truncate distribution so it plots well 46401 >>> plt.hist(s, bins=100) 46402 >>> plt.show() 46403 46404 """ 46405 return ndarray() if False else float() 46406 def standard_exponential(self, size): 46407 """ 46408 standard_exponential(size=None) 46409 46410 Draw samples from the standard exponential distribution. 46411 46412 `standard_exponential` is identical to the exponential distribution 46413 with a scale parameter of 1. 46414 46415 Parameters 46416 ---------- 46417 size : int or tuple of ints 46418 Shape of the output. 46419 46420 Returns 46421 ------- 46422 out : float or ndarray 46423 Drawn samples. 46424 46425 Examples 46426 -------- 46427 Output a 3x8000 array: 46428 46429 >>> n = np.random.standard_exponential((3, 8000)) 46430 46431 """ 46432 return float() if False else ndarray() 46433 def standard_gamma(self, shape, size): 46434 """ 46435 standard_gamma(shape, size=None) 46436 46437 Draw samples from a Standard Gamma distribution. 46438 46439 Samples are drawn from a Gamma distribution with specified parameters, 46440 shape (sometimes designated "k") and scale=1. 46441 46442 Parameters 46443 ---------- 46444 shape : float 46445 Parameter, should be > 0. 46446 size : int or tuple of ints 46447 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 46448 ``m * n * k`` samples are drawn. 46449 46450 Returns 46451 ------- 46452 samples : ndarray or scalar 46453 The drawn samples. 46454 46455 See Also 46456 -------- 46457 scipy.stats.distributions.gamma : probability density function, 46458 distribution or cumulative density function, etc. 46459 46460 Notes 46461 ----- 46462 The probability density for the Gamma distribution is 46463 46464 .. math:: p(x) = x^{k-1}\frac{e^{-x/\theta}}{\theta^k\Gamma(k)}, 46465 46466 where :math:`k` is the shape and :math:`\theta` the scale, 46467 and :math:`\Gamma` is the Gamma function. 46468 46469 The Gamma distribution is often used to model the times to failure of 46470 electronic components, and arises naturally in processes for which the 46471 waiting times between Poisson distributed events are relevant. 46472 46473 References 46474 ---------- 46475 .. [1] Weisstein, Eric W. "Gamma Distribution." From MathWorld--A 46476 Wolfram Web Resource. 46477 http://mathworld.wolfram.com/GammaDistribution.html 46478 .. [2] Wikipedia, "Gamma-distribution", 46479 http://en.wikipedia.org/wiki/Gamma-distribution 46480 46481 Examples 46482 -------- 46483 Draw samples from the distribution: 46484 46485 >>> shape, scale = 2., 1. # mean and width 46486 >>> s = np.random.standard_gamma(shape, 1000000) 46487 46488 Display the histogram of the samples, along with 46489 the probability density function: 46490 46491 >>> import matplotlib.pyplot as plt 46492 >>> import scipy.special as sps 46493 >>> count, bins, ignored = plt.hist(s, 50, normed=True) 46494 >>> y = bins**(shape-1) * ((np.exp(-bins/scale))/ \ 46495 ... (sps.gamma(shape) * scale**shape)) 46496 >>> plt.plot(bins, y, linewidth=2, color='r') 46497 >>> plt.show() 46498 46499 """ 46500 return ndarray() if False else float() 46501 def standard_normal(self, size): 46502 """ 46503 standard_normal(size=None) 46504 46505 Returns samples from a Standard Normal distribution (mean=0, stdev=1). 46506 46507 Parameters 46508 ---------- 46509 size : int or tuple of ints, optional 46510 Output shape. Default is None, in which case a single value is 46511 returned. 46512 46513 Returns 46514 ------- 46515 out : float or ndarray 46516 Drawn samples. 46517 46518 Examples 46519 -------- 46520 >>> s = np.random.standard_normal(8000) 46521 >>> s 46522 array([ 0.6888893 , 0.78096262, -0.89086505, ..., 0.49876311, #random 46523 -0.38672696, -0.4685006 ]) #random 46524 >>> s.shape 46525 (8000,) 46526 >>> s = np.random.standard_normal(size=(3, 4, 2)) 46527 >>> s.shape 46528 (3, 4, 2) 46529 46530 """ 46531 return float() if False else ndarray() 46532 def standard_t(self, df, size): 46533 """ 46534 standard_t(df, size=None) 46535 46536 Standard Student's t distribution with df degrees of freedom. 46537 46538 A special case of the hyperbolic distribution. 46539 As `df` gets large, the result resembles that of the standard normal 46540 distribution (`standard_normal`). 46541 46542 Parameters 46543 ---------- 46544 df : int 46545 Degrees of freedom, should be > 0. 46546 size : int or tuple of ints, optional 46547 Output shape. Default is None, in which case a single value is 46548 returned. 46549 46550 Returns 46551 ------- 46552 samples : ndarray or scalar 46553 Drawn samples. 46554 46555 Notes 46556 ----- 46557 The probability density function for the t distribution is 46558 46559 .. math:: P(x, df) = \frac{\Gamma(\frac{df+1}{2})}{\sqrt{\pi df} 46560 \Gamma(\frac{df}{2})}\Bigl( 1+\frac{x^2}{df} \Bigr)^{-(df+1)/2} 46561 46562 The t test is based on an assumption that the data come from a Normal 46563 distribution. The t test provides a way to test whether the sample mean 46564 (that is the mean calculated from the data) is a good estimate of the true 46565 mean. 46566 46567 The derivation of the t-distribution was forst published in 1908 by William 46568 Gisset while working for the Guinness Brewery in Dublin. Due to proprietary 46569 issues, he had to publish under a pseudonym, and so he used the name 46570 Student. 46571 46572 References 46573 ---------- 46574 .. [1] Dalgaard, Peter, "Introductory Statistics With R", 46575 Springer, 2002. 46576 .. [2] Wikipedia, "Student's t-distribution" 46577 http://en.wikipedia.org/wiki/Student's_t-distribution 46578 46579 Examples 46580 -------- 46581 From Dalgaard page 83 [1]_, suppose the daily energy intake for 11 46582 women in Kj is: 46583 46584 >>> intake = np.array([5260., 5470, 5640, 6180, 6390, 6515, 6805, 7515, \ 46585 ... 7515, 8230, 8770]) 46586 46587 Does their energy intake deviate systematically from the recommended 46588 value of 7725 kJ? 46589 46590 We have 10 degrees of freedom, so is the sample mean within 95% of the 46591 recommended value? 46592 46593 >>> s = np.random.standard_t(10, size=100000) 46594 >>> np.mean(intake) 46595 6753.636363636364 46596 >>> intake.std(ddof=1) 46597 1142.1232221373727 46598 46599 Calculate the t statistic, setting the ddof parameter to the unbiased 46600 value so the divisor in the standard deviation will be degrees of 46601 freedom, N-1. 46602 46603 >>> t = (np.mean(intake)-7725)/(intake.std(ddof=1)/np.sqrt(len(intake))) 46604 >>> import matplotlib.pyplot as plt 46605 >>> h = plt.hist(s, bins=100, normed=True) 46606 46607 For a one-sided t-test, how far out in the distribution does the t 46608 statistic appear? 46609 46610 >>> >>> np.sum(s<t) / float(len(s)) 46611 0.0090699999999999999 #random 46612 46613 So the p-value is about 0.009, which says the null hypothesis has a 46614 probability of about 99% of being true. 46615 46616 """ 46617 return ndarray() if False else float() 46618 def test(self=None, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None): 46619 """ 46620 Run tests for module using nose. 46621 46622 Parameters 46623 ---------- 46624 label : {'fast', 'full', '', attribute identifier}, optional 46625 Identifies the tests to run. This can be a string to pass to 46626 the nosetests executable with the '-A' option, or one of several 46627 special values. Special values are: 46628 * 'fast' - the default - which corresponds to the ``nosetests -A`` 46629 option of 'not slow'. 46630 * 'full' - fast (as above) and slow tests as in the 46631 'no -A' option to nosetests - this is the same as ''. 46632 * None or '' - run all tests. 46633 attribute_identifier - string passed directly to nosetests as '-A'. 46634 verbose : int, optional 46635 Verbosity value for test outputs, in the range 1-10. Default is 1. 46636 extra_argv : list, optional 46637 List with any extra arguments to pass to nosetests. 46638 doctests : bool, optional 46639 If True, run doctests in module. Default is False. 46640 coverage : bool, optional 46641 If True, report coverage of NumPy code. Default is False. 46642 (This requires the `coverage module: 46643 <http://nedbatchelder.com/code/modules/coverage.html>`_). 46644 raise_warnings : str or sequence of warnings, optional 46645 This specifies which warnings to configure as 'raise' instead 46646 of 'warn' during the test execution. Valid strings are: 46647 46648 - "develop" : equals ``(DeprecationWarning, RuntimeWarning)`` 46649 - "release" : equals ``()``, don't raise on any warnings. 46650 46651 Returns 46652 ------- 46653 result : object 46654 Returns the result of running the tests as a 46655 ``nose.result.TextTestResult`` object. 46656 46657 Notes 46658 ----- 46659 Each NumPy module exposes `test` in its namespace to run all tests for it. 46660 For example, to run all tests for numpy.lib: 46661 46662 >>> np.lib.test() #doctest: +SKIP 46663 46664 Examples 46665 -------- 46666 >>> result = np.lib.test() #doctest: +SKIP 46667 Running unit tests for numpy.lib 46668 ... 46669 Ran 976 tests in 3.933s 46670 46671 OK 46672 46673 >>> result.errors #doctest: +SKIP 46674 [] 46675 >>> result.knownfail #doctest: +SKIP 46676 [] 46677 """ 46678 return object() 46679 def triangular(self, left, mode, right, size): 46680 """ 46681 triangular(left, mode, right, size=None) 46682 46683 Draw samples from the triangular distribution. 46684 46685 The triangular distribution is a continuous probability distribution with 46686 lower limit left, peak at mode, and upper limit right. Unlike the other 46687 distributions, these parameters directly define the shape of the pdf. 46688 46689 Parameters 46690 ---------- 46691 left : scalar 46692 Lower limit. 46693 mode : scalar 46694 The value where the peak of the distribution occurs. 46695 The value should fulfill the condition ``left <= mode <= right``. 46696 right : scalar 46697 Upper limit, should be larger than `left`. 46698 size : int or tuple of ints, optional 46699 Output shape. Default is None, in which case a single value is 46700 returned. 46701 46702 Returns 46703 ------- 46704 samples : ndarray or scalar 46705 The returned samples all lie in the interval [left, right]. 46706 46707 Notes 46708 ----- 46709 The probability density function for the Triangular distribution is 46710 46711 .. math:: P(x;l, m, r) = \begin{cases} 46712 \frac{2(x-l)}{(r-l)(m-l)}& \text{for $l \leq x \leq m$},\\ 46713 \frac{2(m-x)}{(r-l)(r-m)}& \text{for $m \leq x \leq r$},\\ 46714 0& \text{otherwise}. 46715 \end{cases} 46716 46717 The triangular distribution is often used in ill-defined problems where the 46718 underlying distribution is not known, but some knowledge of the limits and 46719 mode exists. Often it is used in simulations. 46720 46721 References 46722 ---------- 46723 .. [1] Wikipedia, "Triangular distribution" 46724 http://en.wikipedia.org/wiki/Triangular_distribution 46725 46726 Examples 46727 -------- 46728 Draw values from the distribution and plot the histogram: 46729 46730 >>> import matplotlib.pyplot as plt 46731 >>> h = plt.hist(np.random.triangular(-3, 0, 8, 100000), bins=200, 46732 ... normed=True) 46733 >>> plt.show() 46734 46735 """ 46736 return ndarray() if False else float() 46737 def uniform(self, low, high, size): 46738 """ 46739 uniform(low=0.0, high=1.0, size=1) 46740 46741 Draw samples from a uniform distribution. 46742 46743 Samples are uniformly distributed over the half-open interval 46744 ``[low, high)`` (includes low, but excludes high). In other words, 46745 any value within the given interval is equally likely to be drawn 46746 by `uniform`. 46747 46748 Parameters 46749 ---------- 46750 low : float, optional 46751 Lower boundary of the output interval. All values generated will be 46752 greater than or equal to low. The default value is 0. 46753 high : float 46754 Upper boundary of the output interval. All values generated will be 46755 less than high. The default value is 1.0. 46756 size : int or tuple of ints, optional 46757 Shape of output. If the given size is, for example, (m,n,k), 46758 m*n*k samples are generated. If no shape is specified, a single sample 46759 is returned. 46760 46761 Returns 46762 ------- 46763 out : ndarray 46764 Drawn samples, with shape `size`. 46765 46766 See Also 46767 -------- 46768 randint : Discrete uniform distribution, yielding integers. 46769 random_integers : Discrete uniform distribution over the closed 46770 interval ``[low, high]``. 46771 random_sample : Floats uniformly distributed over ``[0, 1)``. 46772 random : Alias for `random_sample`. 46773 rand : Convenience function that accepts dimensions as input, e.g., 46774 ``rand(2,2)`` would generate a 2-by-2 array of floats, 46775 uniformly distributed over ``[0, 1)``. 46776 46777 Notes 46778 ----- 46779 The probability density function of the uniform distribution is 46780 46781 .. math:: p(x) = \frac{1}{b - a} 46782 46783 anywhere within the interval ``[a, b)``, and zero elsewhere. 46784 46785 Examples 46786 -------- 46787 Draw samples from the distribution: 46788 46789 >>> s = np.random.uniform(-1,0,1000) 46790 46791 All values are within the given interval: 46792 46793 >>> np.all(s >= -1) 46794 True 46795 >>> np.all(s < 0) 46796 True 46797 46798 Display the histogram of the samples, along with the 46799 probability density function: 46800 46801 >>> import matplotlib.pyplot as plt 46802 >>> count, bins, ignored = plt.hist(s, 15, normed=True) 46803 >>> plt.plot(bins, np.ones_like(bins), linewidth=2, color='r') 46804 >>> plt.show() 46805 46806 """ 46807 return ndarray() 46808 def vonmises(self, mu, kappa, size): 46809 """ 46810 vonmises(mu, kappa, size=None) 46811 46812 Draw samples from a von Mises distribution. 46813 46814 Samples are drawn from a von Mises distribution with specified mode 46815 (mu) and dispersion (kappa), on the interval [-pi, pi]. 46816 46817 The von Mises distribution (also known as the circular normal 46818 distribution) is a continuous probability distribution on the unit 46819 circle. It may be thought of as the circular analogue of the normal 46820 distribution. 46821 46822 Parameters 46823 ---------- 46824 mu : float 46825 Mode ("center") of the distribution. 46826 kappa : float 46827 Dispersion of the distribution, has to be >=0. 46828 size : int or tuple of int 46829 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 46830 ``m * n * k`` samples are drawn. 46831 46832 Returns 46833 ------- 46834 samples : scalar or ndarray 46835 The returned samples, which are in the interval [-pi, pi]. 46836 46837 See Also 46838 -------- 46839 scipy.stats.distributions.vonmises : probability density function, 46840 distribution, or cumulative density function, etc. 46841 46842 Notes 46843 ----- 46844 The probability density for the von Mises distribution is 46845 46846 .. math:: p(x) = \frac{e^{\kappa cos(x-\mu)}}{2\pi I_0(\kappa)}, 46847 46848 where :math:`\mu` is the mode and :math:`\kappa` the dispersion, 46849 and :math:`I_0(\kappa)` is the modified Bessel function of order 0. 46850 46851 The von Mises is named for Richard Edler von Mises, who was born in 46852 Austria-Hungary, in what is now the Ukraine. He fled to the United 46853 States in 1939 and became a professor at Harvard. He worked in 46854 probability theory, aerodynamics, fluid mechanics, and philosophy of 46855 science. 46856 46857 References 46858 ---------- 46859 Abramowitz, M. and Stegun, I. A. (ed.), *Handbook of Mathematical 46860 Functions*, New York: Dover, 1965. 46861 46862 von Mises, R., *Mathematical Theory of Probability and Statistics*, 46863 New York: Academic Press, 1964. 46864 46865 Examples 46866 -------- 46867 Draw samples from the distribution: 46868 46869 >>> mu, kappa = 0.0, 4.0 # mean and dispersion 46870 >>> s = np.random.vonmises(mu, kappa, 1000) 46871 46872 Display the histogram of the samples, along with 46873 the probability density function: 46874 46875 >>> import matplotlib.pyplot as plt 46876 >>> import scipy.special as sps 46877 >>> count, bins, ignored = plt.hist(s, 50, normed=True) 46878 >>> x = np.arange(-np.pi, np.pi, 2*np.pi/50.) 46879 >>> y = -np.exp(kappa*np.cos(x-mu))/(2*np.pi*sps.jn(0,kappa)) 46880 >>> plt.plot(x, y/max(y), linewidth=2, color='r') 46881 >>> plt.show() 46882 46883 """ 46884 return float() if False else ndarray() 46885 def wald(self, mean, scale, size): 46886 """ 46887 wald(mean, scale, size=None) 46888 46889 Draw samples from a Wald, or Inverse Gaussian, distribution. 46890 46891 As the scale approaches infinity, the distribution becomes more like a 46892 Gaussian. 46893 46894 Some references claim that the Wald is an Inverse Gaussian with mean=1, but 46895 this is by no means universal. 46896 46897 The Inverse Gaussian distribution was first studied in relationship to 46898 Brownian motion. In 1956 M.C.K. Tweedie used the name Inverse Gaussian 46899 because there is an inverse relationship between the time to cover a unit 46900 distance and distance covered in unit time. 46901 46902 Parameters 46903 ---------- 46904 mean : scalar 46905 Distribution mean, should be > 0. 46906 scale : scalar 46907 Scale parameter, should be >= 0. 46908 size : int or tuple of ints, optional 46909 Output shape. Default is None, in which case a single value is 46910 returned. 46911 46912 Returns 46913 ------- 46914 samples : ndarray or scalar 46915 Drawn sample, all greater than zero. 46916 46917 Notes 46918 ----- 46919 The probability density function for the Wald distribution is 46920 46921 .. math:: P(x;mean,scale) = \sqrt{\frac{scale}{2\pi x^3}}e^ 46922 \frac{-scale(x-mean)^2}{2\cdotp mean^2x} 46923 46924 As noted above the Inverse Gaussian distribution first arise from attempts 46925 to model Brownian Motion. It is also a competitor to the Weibull for use in 46926 reliability modeling and modeling stock returns and interest rate 46927 processes. 46928 46929 References 46930 ---------- 46931 .. [1] Brighton Webs Ltd., Wald Distribution, 46932 http://www.brighton-webs.co.uk/distributions/wald.asp 46933 .. [2] Chhikara, Raj S., and Folks, J. Leroy, "The Inverse Gaussian 46934 Distribution: Theory : Methodology, and Applications", CRC Press, 46935 1988. 46936 .. [3] Wikipedia, "Wald distribution" 46937 http://en.wikipedia.org/wiki/Wald_distribution 46938 46939 Examples 46940 -------- 46941 Draw values from the distribution and plot the histogram: 46942 46943 >>> import matplotlib.pyplot as plt 46944 >>> h = plt.hist(np.random.wald(3, 2, 100000), bins=200, normed=True) 46945 >>> plt.show() 46946 46947 """ 46948 return ndarray() if False else float() 46949 def weibull(self, a, size): 46950 """ 46951 weibull(a, size=None) 46952 46953 Weibull distribution. 46954 46955 Draw samples from a 1-parameter Weibull distribution with the given 46956 shape parameter `a`. 46957 46958 .. math:: X = (-ln(U))^{1/a} 46959 46960 Here, U is drawn from the uniform distribution over (0,1]. 46961 46962 The more common 2-parameter Weibull, including a scale parameter 46963 :math:`\lambda` is just :math:`X = \lambda(-ln(U))^{1/a}`. 46964 46965 Parameters 46966 ---------- 46967 a : float 46968 Shape of the distribution. 46969 size : tuple of ints 46970 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 46971 ``m * n * k`` samples are drawn. 46972 46973 See Also 46974 -------- 46975 scipy.stats.distributions.weibull_max 46976 scipy.stats.distributions.weibull_min 46977 scipy.stats.distributions.genextreme 46978 gumbel 46979 46980 Notes 46981 ----- 46982 The Weibull (or Type III asymptotic extreme value distribution for smallest 46983 values, SEV Type III, or Rosin-Rammler distribution) is one of a class of 46984 Generalized Extreme Value (GEV) distributions used in modeling extreme 46985 value problems. This class includes the Gumbel and Frechet distributions. 46986 46987 The probability density for the Weibull distribution is 46988 46989 .. math:: p(x) = \frac{a} 46990 {\lambda}(\frac{x}{\lambda})^{a-1}e^{-(x/\lambda)^a}, 46991 46992 where :math:`a` is the shape and :math:`\lambda` the scale. 46993 46994 The function has its peak (the mode) at 46995 :math:`\lambda(\frac{a-1}{a})^{1/a}`. 46996 46997 When ``a = 1``, the Weibull distribution reduces to the exponential 46998 distribution. 46999 47000 References 47001 ---------- 47002 .. [1] Waloddi Weibull, Professor, Royal Technical University, Stockholm, 47003 1939 "A Statistical Theory Of The Strength Of Materials", 47004 Ingeniorsvetenskapsakademiens Handlingar Nr 151, 1939, 47005 Generalstabens Litografiska Anstalts Forlag, Stockholm. 47006 .. [2] Waloddi Weibull, 1951 "A Statistical Distribution Function of Wide 47007 Applicability", Journal Of Applied Mechanics ASME Paper. 47008 .. [3] Wikipedia, "Weibull distribution", 47009 http://en.wikipedia.org/wiki/Weibull_distribution 47010 47011 Examples 47012 -------- 47013 Draw samples from the distribution: 47014 47015 >>> a = 5. # shape 47016 >>> s = np.random.weibull(a, 1000) 47017 47018 Display the histogram of the samples, along with 47019 the probability density function: 47020 47021 >>> import matplotlib.pyplot as plt 47022 >>> x = np.arange(1,100.)/50. 47023 >>> def weib(x,n,a): 47024 ... return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a) 47025 47026 >>> count, bins, ignored = plt.hist(np.random.weibull(5.,1000)) 47027 >>> x = np.arange(1,100.)/50. 47028 >>> scale = count.max()/weib(x, 1., 5.).max() 47029 >>> plt.plot(x, weib(x, 1., 5.)*scale) 47030 >>> plt.show() 47031 47032 """ 47033 return None 47034 def zipf(self, a, size): 47035 """ 47036 zipf(a, size=None) 47037 47038 Draw samples from a Zipf distribution. 47039 47040 Samples are drawn from a Zipf distribution with specified parameter 47041 `a` > 1. 47042 47043 The Zipf distribution (also known as the zeta distribution) is a 47044 continuous probability distribution that satisfies Zipf's law: the 47045 frequency of an item is inversely proportional to its rank in a 47046 frequency table. 47047 47048 Parameters 47049 ---------- 47050 a : float > 1 47051 Distribution parameter. 47052 size : int or tuple of int, optional 47053 Output shape. If the given shape is, e.g., ``(m, n, k)``, then 47054 ``m * n * k`` samples are drawn; a single integer is equivalent in 47055 its result to providing a mono-tuple, i.e., a 1-D array of length 47056 *size* is returned. The default is None, in which case a single 47057 scalar is returned. 47058 47059 Returns 47060 ------- 47061 samples : scalar or ndarray 47062 The returned samples are greater than or equal to one. 47063 47064 See Also 47065 -------- 47066 scipy.stats.distributions.zipf : probability density function, 47067 distribution, or cumulative density function, etc. 47068 47069 Notes 47070 ----- 47071 The probability density for the Zipf distribution is 47072 47073 .. math:: p(x) = \frac{x^{-a}}{\zeta(a)}, 47074 47075 where :math:`\zeta` is the Riemann Zeta function. 47076 47077 It is named for the American linguist George Kingsley Zipf, who noted 47078 that the frequency of any word in a sample of a language is inversely 47079 proportional to its rank in the frequency table. 47080 47081 References 47082 ---------- 47083 Zipf, G. K., *Selected Studies of the Principle of Relative Frequency 47084 in Language*, Cambridge, MA: Harvard Univ. Press, 1932. 47085 47086 Examples 47087 -------- 47088 Draw samples from the distribution: 47089 47090 >>> a = 2. # parameter 47091 >>> s = np.random.zipf(a, 1000) 47092 47093 Display the histogram of the samples, along with 47094 the probability density function: 47095 47096 >>> import matplotlib.pyplot as plt 47097 >>> import scipy.special as sps 47098 Truncate s values at 50 so plot is interesting 47099 >>> count, bins, ignored = plt.hist(s[s<50], 50, normed=True) 47100 >>> x = np.arange(1., 50.) 47101 >>> y = x**(-a)/sps.zetac(a) 47102 >>> plt.plot(x, y/max(y), linewidth=2, color='r') 47103 >>> plt.show() 47104 47105 """ 47106 return float() if False else ndarray() 47107 fromfile = _fromfile 47108 frombuffer = _frombuffer 47109 fromstring = _fromstring