Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/add_newdocs.py @ 87:2a2c65a20a8b
Add Python libs and headers
author | Chris Cannam |
---|---|
date | Wed, 25 Feb 2015 14:05:22 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
86:413a9d26189e | 87:2a2c65a20a8b |
---|---|
1 """ | |
2 This is only meant to add docs to objects defined in C-extension modules. | |
3 The purpose is to allow easier editing of the docstrings without | |
4 requiring a re-compile. | |
5 | |
6 NOTE: Many of the methods of ndarray have corresponding functions. | |
7 If you update these docstrings, please keep also the ones in | |
8 core/fromnumeric.py, core/defmatrix.py up-to-date. | |
9 | |
10 """ | |
11 from __future__ import division, absolute_import, print_function | |
12 | |
13 from numpy.lib import add_newdoc | |
14 | |
15 ############################################################################### | |
16 # | |
17 # flatiter | |
18 # | |
19 # flatiter needs a toplevel description | |
20 # | |
21 ############################################################################### | |
22 | |
23 add_newdoc('numpy.core', 'flatiter', | |
24 """ | |
25 Flat iterator object to iterate over arrays. | |
26 | |
27 A `flatiter` iterator is returned by ``x.flat`` for any array `x`. | |
28 It allows iterating over the array as if it were a 1-D array, | |
29 either in a for-loop or by calling its `next` method. | |
30 | |
31 Iteration is done in C-contiguous style, with the last index varying the | |
32 fastest. The iterator can also be indexed using basic slicing or | |
33 advanced indexing. | |
34 | |
35 See Also | |
36 -------- | |
37 ndarray.flat : Return a flat iterator over an array. | |
38 ndarray.flatten : Returns a flattened copy of an array. | |
39 | |
40 Notes | |
41 ----- | |
42 A `flatiter` iterator can not be constructed directly from Python code | |
43 by calling the `flatiter` constructor. | |
44 | |
45 Examples | |
46 -------- | |
47 >>> x = np.arange(6).reshape(2, 3) | |
48 >>> fl = x.flat | |
49 >>> type(fl) | |
50 <type 'numpy.flatiter'> | |
51 >>> for item in fl: | |
52 ... print item | |
53 ... | |
54 0 | |
55 1 | |
56 2 | |
57 3 | |
58 4 | |
59 5 | |
60 | |
61 >>> fl[2:4] | |
62 array([2, 3]) | |
63 | |
64 """) | |
65 | |
66 # flatiter attributes | |
67 | |
68 add_newdoc('numpy.core', 'flatiter', ('base', | |
69 """ | |
70 A reference to the array that is iterated over. | |
71 | |
72 Examples | |
73 -------- | |
74 >>> x = np.arange(5) | |
75 >>> fl = x.flat | |
76 >>> fl.base is x | |
77 True | |
78 | |
79 """)) | |
80 | |
81 | |
82 | |
83 add_newdoc('numpy.core', 'flatiter', ('coords', | |
84 """ | |
85 An N-dimensional tuple of current coordinates. | |
86 | |
87 Examples | |
88 -------- | |
89 >>> x = np.arange(6).reshape(2, 3) | |
90 >>> fl = x.flat | |
91 >>> fl.coords | |
92 (0, 0) | |
93 >>> fl.next() | |
94 0 | |
95 >>> fl.coords | |
96 (0, 1) | |
97 | |
98 """)) | |
99 | |
100 | |
101 | |
102 add_newdoc('numpy.core', 'flatiter', ('index', | |
103 """ | |
104 Current flat index into the array. | |
105 | |
106 Examples | |
107 -------- | |
108 >>> x = np.arange(6).reshape(2, 3) | |
109 >>> fl = x.flat | |
110 >>> fl.index | |
111 0 | |
112 >>> fl.next() | |
113 0 | |
114 >>> fl.index | |
115 1 | |
116 | |
117 """)) | |
118 | |
119 # flatiter functions | |
120 | |
121 add_newdoc('numpy.core', 'flatiter', ('__array__', | |
122 """__array__(type=None) Get array from iterator | |
123 | |
124 """)) | |
125 | |
126 | |
127 add_newdoc('numpy.core', 'flatiter', ('copy', | |
128 """ | |
129 copy() | |
130 | |
131 Get a copy of the iterator as a 1-D array. | |
132 | |
133 Examples | |
134 -------- | |
135 >>> x = np.arange(6).reshape(2, 3) | |
136 >>> x | |
137 array([[0, 1, 2], | |
138 [3, 4, 5]]) | |
139 >>> fl = x.flat | |
140 >>> fl.copy() | |
141 array([0, 1, 2, 3, 4, 5]) | |
142 | |
143 """)) | |
144 | |
145 | |
146 ############################################################################### | |
147 # | |
148 # nditer | |
149 # | |
150 ############################################################################### | |
151 | |
152 add_newdoc('numpy.core', 'nditer', | |
153 """ | |
154 Efficient multi-dimensional iterator object to iterate over arrays. | |
155 To get started using this object, see the | |
156 :ref:`introductory guide to array iteration <arrays.nditer>`. | |
157 | |
158 Parameters | |
159 ---------- | |
160 op : ndarray or sequence of array_like | |
161 The array(s) to iterate over. | |
162 flags : sequence of str, optional | |
163 Flags to control the behavior of the iterator. | |
164 | |
165 * "buffered" enables buffering when required. | |
166 * "c_index" causes a C-order index to be tracked. | |
167 * "f_index" causes a Fortran-order index to be tracked. | |
168 * "multi_index" causes a multi-index, or a tuple of indices | |
169 with one per iteration dimension, to be tracked. | |
170 * "common_dtype" causes all the operands to be converted to | |
171 a common data type, with copying or buffering as necessary. | |
172 * "delay_bufalloc" delays allocation of the buffers until | |
173 a reset() call is made. Allows "allocate" operands to | |
174 be initialized before their values are copied into the buffers. | |
175 * "external_loop" causes the `values` given to be | |
176 one-dimensional arrays with multiple values instead of | |
177 zero-dimensional arrays. | |
178 * "grow_inner" allows the `value` array sizes to be made | |
179 larger than the buffer size when both "buffered" and | |
180 "external_loop" is used. | |
181 * "ranged" allows the iterator to be restricted to a sub-range | |
182 of the iterindex values. | |
183 * "refs_ok" enables iteration of reference types, such as | |
184 object arrays. | |
185 * "reduce_ok" enables iteration of "readwrite" operands | |
186 which are broadcasted, also known as reduction operands. | |
187 * "zerosize_ok" allows `itersize` to be zero. | |
188 op_flags : list of list of str, optional | |
189 This is a list of flags for each operand. At minimum, one of | |
190 "readonly", "readwrite", or "writeonly" must be specified. | |
191 | |
192 * "readonly" indicates the operand will only be read from. | |
193 * "readwrite" indicates the operand will be read from and written to. | |
194 * "writeonly" indicates the operand will only be written to. | |
195 * "no_broadcast" prevents the operand from being broadcasted. | |
196 * "contig" forces the operand data to be contiguous. | |
197 * "aligned" forces the operand data to be aligned. | |
198 * "nbo" forces the operand data to be in native byte order. | |
199 * "copy" allows a temporary read-only copy if required. | |
200 * "updateifcopy" allows a temporary read-write copy if required. | |
201 * "allocate" causes the array to be allocated if it is None | |
202 in the `op` parameter. | |
203 * "no_subtype" prevents an "allocate" operand from using a subtype. | |
204 * "arraymask" indicates that this operand is the mask to use | |
205 for selecting elements when writing to operands with the | |
206 'writemasked' flag set. The iterator does not enforce this, | |
207 but when writing from a buffer back to the array, it only | |
208 copies those elements indicated by this mask. | |
209 * 'writemasked' indicates that only elements where the chosen | |
210 'arraymask' operand is True will be written to. | |
211 op_dtypes : dtype or tuple of dtype(s), optional | |
212 The required data type(s) of the operands. If copying or buffering | |
213 is enabled, the data will be converted to/from their original types. | |
214 order : {'C', 'F', 'A', 'K'}, optional | |
215 Controls the iteration order. 'C' means C order, 'F' means | |
216 Fortran order, 'A' means 'F' order if all the arrays are Fortran | |
217 contiguous, 'C' order otherwise, and 'K' means as close to the | |
218 order the array elements appear in memory as possible. This also | |
219 affects the element memory order of "allocate" operands, as they | |
220 are allocated to be compatible with iteration order. | |
221 Default is 'K'. | |
222 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional | |
223 Controls what kind of data casting may occur when making a copy | |
224 or buffering. Setting this to 'unsafe' is not recommended, | |
225 as it can adversely affect accumulations. | |
226 | |
227 * 'no' means the data types should not be cast at all. | |
228 * 'equiv' means only byte-order changes are allowed. | |
229 * 'safe' means only casts which can preserve values are allowed. | |
230 * 'same_kind' means only safe casts or casts within a kind, | |
231 like float64 to float32, are allowed. | |
232 * 'unsafe' means any data conversions may be done. | |
233 op_axes : list of list of ints, optional | |
234 If provided, is a list of ints or None for each operands. | |
235 The list of axes for an operand is a mapping from the dimensions | |
236 of the iterator to the dimensions of the operand. A value of | |
237 -1 can be placed for entries, causing that dimension to be | |
238 treated as "newaxis". | |
239 itershape : tuple of ints, optional | |
240 The desired shape of the iterator. This allows "allocate" operands | |
241 with a dimension mapped by op_axes not corresponding to a dimension | |
242 of a different operand to get a value not equal to 1 for that | |
243 dimension. | |
244 buffersize : int, optional | |
245 When buffering is enabled, controls the size of the temporary | |
246 buffers. Set to 0 for the default value. | |
247 | |
248 Attributes | |
249 ---------- | |
250 dtypes : tuple of dtype(s) | |
251 The data types of the values provided in `value`. This may be | |
252 different from the operand data types if buffering is enabled. | |
253 finished : bool | |
254 Whether the iteration over the operands is finished or not. | |
255 has_delayed_bufalloc : bool | |
256 If True, the iterator was created with the "delay_bufalloc" flag, | |
257 and no reset() function was called on it yet. | |
258 has_index : bool | |
259 If True, the iterator was created with either the "c_index" or | |
260 the "f_index" flag, and the property `index` can be used to | |
261 retrieve it. | |
262 has_multi_index : bool | |
263 If True, the iterator was created with the "multi_index" flag, | |
264 and the property `multi_index` can be used to retrieve it. | |
265 index : | |
266 When the "c_index" or "f_index" flag was used, this property | |
267 provides access to the index. Raises a ValueError if accessed | |
268 and `has_index` is False. | |
269 iterationneedsapi : bool | |
270 Whether iteration requires access to the Python API, for example | |
271 if one of the operands is an object array. | |
272 iterindex : int | |
273 An index which matches the order of iteration. | |
274 itersize : int | |
275 Size of the iterator. | |
276 itviews : | |
277 Structured view(s) of `operands` in memory, matching the reordered | |
278 and optimized iterator access pattern. | |
279 multi_index : | |
280 When the "multi_index" flag was used, this property | |
281 provides access to the index. Raises a ValueError if accessed | |
282 accessed and `has_multi_index` is False. | |
283 ndim : int | |
284 The iterator's dimension. | |
285 nop : int | |
286 The number of iterator operands. | |
287 operands : tuple of operand(s) | |
288 The array(s) to be iterated over. | |
289 shape : tuple of ints | |
290 Shape tuple, the shape of the iterator. | |
291 value : | |
292 Value of `operands` at current iteration. Normally, this is a | |
293 tuple of array scalars, but if the flag "external_loop" is used, | |
294 it is a tuple of one dimensional arrays. | |
295 | |
296 Notes | |
297 ----- | |
298 `nditer` supersedes `flatiter`. The iterator implementation behind | |
299 `nditer` is also exposed by the Numpy C API. | |
300 | |
301 The Python exposure supplies two iteration interfaces, one which follows | |
302 the Python iterator protocol, and another which mirrors the C-style | |
303 do-while pattern. The native Python approach is better in most cases, but | |
304 if you need the iterator's coordinates or index, use the C-style pattern. | |
305 | |
306 Examples | |
307 -------- | |
308 Here is how we might write an ``iter_add`` function, using the | |
309 Python iterator protocol:: | |
310 | |
311 def iter_add_py(x, y, out=None): | |
312 addop = np.add | |
313 it = np.nditer([x, y, out], [], | |
314 [['readonly'], ['readonly'], ['writeonly','allocate']]) | |
315 for (a, b, c) in it: | |
316 addop(a, b, out=c) | |
317 return it.operands[2] | |
318 | |
319 Here is the same function, but following the C-style pattern:: | |
320 | |
321 def iter_add(x, y, out=None): | |
322 addop = np.add | |
323 | |
324 it = np.nditer([x, y, out], [], | |
325 [['readonly'], ['readonly'], ['writeonly','allocate']]) | |
326 | |
327 while not it.finished: | |
328 addop(it[0], it[1], out=it[2]) | |
329 it.iternext() | |
330 | |
331 return it.operands[2] | |
332 | |
333 Here is an example outer product function:: | |
334 | |
335 def outer_it(x, y, out=None): | |
336 mulop = np.multiply | |
337 | |
338 it = np.nditer([x, y, out], ['external_loop'], | |
339 [['readonly'], ['readonly'], ['writeonly', 'allocate']], | |
340 op_axes=[range(x.ndim)+[-1]*y.ndim, | |
341 [-1]*x.ndim+range(y.ndim), | |
342 None]) | |
343 | |
344 for (a, b, c) in it: | |
345 mulop(a, b, out=c) | |
346 | |
347 return it.operands[2] | |
348 | |
349 >>> a = np.arange(2)+1 | |
350 >>> b = np.arange(3)+1 | |
351 >>> outer_it(a,b) | |
352 array([[1, 2, 3], | |
353 [2, 4, 6]]) | |
354 | |
355 Here is an example function which operates like a "lambda" ufunc:: | |
356 | |
357 def luf(lamdaexpr, *args, **kwargs): | |
358 "luf(lambdaexpr, op1, ..., opn, out=None, order='K', casting='safe', buffersize=0)" | |
359 nargs = len(args) | |
360 op = (kwargs.get('out',None),) + args | |
361 it = np.nditer(op, ['buffered','external_loop'], | |
362 [['writeonly','allocate','no_broadcast']] + | |
363 [['readonly','nbo','aligned']]*nargs, | |
364 order=kwargs.get('order','K'), | |
365 casting=kwargs.get('casting','safe'), | |
366 buffersize=kwargs.get('buffersize',0)) | |
367 while not it.finished: | |
368 it[0] = lamdaexpr(*it[1:]) | |
369 it.iternext() | |
370 return it.operands[0] | |
371 | |
372 >>> a = np.arange(5) | |
373 >>> b = np.ones(5) | |
374 >>> luf(lambda i,j:i*i + j/2, a, b) | |
375 array([ 0.5, 1.5, 4.5, 9.5, 16.5]) | |
376 | |
377 """) | |
378 | |
379 # nditer methods | |
380 | |
381 add_newdoc('numpy.core', 'nditer', ('copy', | |
382 """ | |
383 copy() | |
384 | |
385 Get a copy of the iterator in its current state. | |
386 | |
387 Examples | |
388 -------- | |
389 >>> x = np.arange(10) | |
390 >>> y = x + 1 | |
391 >>> it = np.nditer([x, y]) | |
392 >>> it.next() | |
393 (array(0), array(1)) | |
394 >>> it2 = it.copy() | |
395 >>> it2.next() | |
396 (array(1), array(2)) | |
397 | |
398 """)) | |
399 | |
400 add_newdoc('numpy.core', 'nditer', ('debug_print', | |
401 """ | |
402 debug_print() | |
403 | |
404 Print the current state of the `nditer` instance and debug info to stdout. | |
405 | |
406 """)) | |
407 | |
408 add_newdoc('numpy.core', 'nditer', ('enable_external_loop', | |
409 """ | |
410 enable_external_loop() | |
411 | |
412 When the "external_loop" was not used during construction, but | |
413 is desired, this modifies the iterator to behave as if the flag | |
414 was specified. | |
415 | |
416 """)) | |
417 | |
418 add_newdoc('numpy.core', 'nditer', ('iternext', | |
419 """ | |
420 iternext() | |
421 | |
422 Check whether iterations are left, and perform a single internal iteration | |
423 without returning the result. Used in the C-style pattern do-while | |
424 pattern. For an example, see `nditer`. | |
425 | |
426 Returns | |
427 ------- | |
428 iternext : bool | |
429 Whether or not there are iterations left. | |
430 | |
431 """)) | |
432 | |
433 add_newdoc('numpy.core', 'nditer', ('remove_axis', | |
434 """ | |
435 remove_axis(i) | |
436 | |
437 Removes axis `i` from the iterator. Requires that the flag "multi_index" | |
438 be enabled. | |
439 | |
440 """)) | |
441 | |
442 add_newdoc('numpy.core', 'nditer', ('remove_multi_index', | |
443 """ | |
444 remove_multi_index() | |
445 | |
446 When the "multi_index" flag was specified, this removes it, allowing | |
447 the internal iteration structure to be optimized further. | |
448 | |
449 """)) | |
450 | |
451 add_newdoc('numpy.core', 'nditer', ('reset', | |
452 """ | |
453 reset() | |
454 | |
455 Reset the iterator to its initial state. | |
456 | |
457 """)) | |
458 | |
459 | |
460 | |
461 ############################################################################### | |
462 # | |
463 # broadcast | |
464 # | |
465 ############################################################################### | |
466 | |
467 add_newdoc('numpy.core', 'broadcast', | |
468 """ | |
469 Produce an object that mimics broadcasting. | |
470 | |
471 Parameters | |
472 ---------- | |
473 in1, in2, ... : array_like | |
474 Input parameters. | |
475 | |
476 Returns | |
477 ------- | |
478 b : broadcast object | |
479 Broadcast the input parameters against one another, and | |
480 return an object that encapsulates the result. | |
481 Amongst others, it has ``shape`` and ``nd`` properties, and | |
482 may be used as an iterator. | |
483 | |
484 Examples | |
485 -------- | |
486 Manually adding two vectors, using broadcasting: | |
487 | |
488 >>> x = np.array([[1], [2], [3]]) | |
489 >>> y = np.array([4, 5, 6]) | |
490 >>> b = np.broadcast(x, y) | |
491 | |
492 >>> out = np.empty(b.shape) | |
493 >>> out.flat = [u+v for (u,v) in b] | |
494 >>> out | |
495 array([[ 5., 6., 7.], | |
496 [ 6., 7., 8.], | |
497 [ 7., 8., 9.]]) | |
498 | |
499 Compare against built-in broadcasting: | |
500 | |
501 >>> x + y | |
502 array([[5, 6, 7], | |
503 [6, 7, 8], | |
504 [7, 8, 9]]) | |
505 | |
506 """) | |
507 | |
508 # attributes | |
509 | |
510 add_newdoc('numpy.core', 'broadcast', ('index', | |
511 """ | |
512 current index in broadcasted result | |
513 | |
514 Examples | |
515 -------- | |
516 >>> x = np.array([[1], [2], [3]]) | |
517 >>> y = np.array([4, 5, 6]) | |
518 >>> b = np.broadcast(x, y) | |
519 >>> b.index | |
520 0 | |
521 >>> b.next(), b.next(), b.next() | |
522 ((1, 4), (1, 5), (1, 6)) | |
523 >>> b.index | |
524 3 | |
525 | |
526 """)) | |
527 | |
528 add_newdoc('numpy.core', 'broadcast', ('iters', | |
529 """ | |
530 tuple of iterators along ``self``'s "components." | |
531 | |
532 Returns a tuple of `numpy.flatiter` objects, one for each "component" | |
533 of ``self``. | |
534 | |
535 See Also | |
536 -------- | |
537 numpy.flatiter | |
538 | |
539 Examples | |
540 -------- | |
541 >>> x = np.array([1, 2, 3]) | |
542 >>> y = np.array([[4], [5], [6]]) | |
543 >>> b = np.broadcast(x, y) | |
544 >>> row, col = b.iters | |
545 >>> row.next(), col.next() | |
546 (1, 4) | |
547 | |
548 """)) | |
549 | |
550 add_newdoc('numpy.core', 'broadcast', ('nd', | |
551 """ | |
552 Number of dimensions of broadcasted result. | |
553 | |
554 Examples | |
555 -------- | |
556 >>> x = np.array([1, 2, 3]) | |
557 >>> y = np.array([[4], [5], [6]]) | |
558 >>> b = np.broadcast(x, y) | |
559 >>> b.nd | |
560 2 | |
561 | |
562 """)) | |
563 | |
564 add_newdoc('numpy.core', 'broadcast', ('numiter', | |
565 """ | |
566 Number of iterators possessed by the broadcasted result. | |
567 | |
568 Examples | |
569 -------- | |
570 >>> x = np.array([1, 2, 3]) | |
571 >>> y = np.array([[4], [5], [6]]) | |
572 >>> b = np.broadcast(x, y) | |
573 >>> b.numiter | |
574 2 | |
575 | |
576 """)) | |
577 | |
578 add_newdoc('numpy.core', 'broadcast', ('shape', | |
579 """ | |
580 Shape of broadcasted result. | |
581 | |
582 Examples | |
583 -------- | |
584 >>> x = np.array([1, 2, 3]) | |
585 >>> y = np.array([[4], [5], [6]]) | |
586 >>> b = np.broadcast(x, y) | |
587 >>> b.shape | |
588 (3, 3) | |
589 | |
590 """)) | |
591 | |
592 add_newdoc('numpy.core', 'broadcast', ('size', | |
593 """ | |
594 Total size of broadcasted result. | |
595 | |
596 Examples | |
597 -------- | |
598 >>> x = np.array([1, 2, 3]) | |
599 >>> y = np.array([[4], [5], [6]]) | |
600 >>> b = np.broadcast(x, y) | |
601 >>> b.size | |
602 9 | |
603 | |
604 """)) | |
605 | |
606 add_newdoc('numpy.core', 'broadcast', ('reset', | |
607 """ | |
608 reset() | |
609 | |
610 Reset the broadcasted result's iterator(s). | |
611 | |
612 Parameters | |
613 ---------- | |
614 None | |
615 | |
616 Returns | |
617 ------- | |
618 None | |
619 | |
620 Examples | |
621 -------- | |
622 >>> x = np.array([1, 2, 3]) | |
623 >>> y = np.array([[4], [5], [6]] | |
624 >>> b = np.broadcast(x, y) | |
625 >>> b.index | |
626 0 | |
627 >>> b.next(), b.next(), b.next() | |
628 ((1, 4), (2, 4), (3, 4)) | |
629 >>> b.index | |
630 3 | |
631 >>> b.reset() | |
632 >>> b.index | |
633 0 | |
634 | |
635 """)) | |
636 | |
637 ############################################################################### | |
638 # | |
639 # numpy functions | |
640 # | |
641 ############################################################################### | |
642 | |
643 add_newdoc('numpy.core.multiarray', 'array', | |
644 """ | |
645 array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0) | |
646 | |
647 Create an array. | |
648 | |
649 Parameters | |
650 ---------- | |
651 object : array_like | |
652 An array, any object exposing the array interface, an | |
653 object whose __array__ method returns an array, or any | |
654 (nested) sequence. | |
655 dtype : data-type, optional | |
656 The desired data-type for the array. If not given, then | |
657 the type will be determined as the minimum type required | |
658 to hold the objects in the sequence. This argument can only | |
659 be used to 'upcast' the array. For downcasting, use the | |
660 .astype(t) method. | |
661 copy : bool, optional | |
662 If true (default), then the object is copied. Otherwise, a copy | |
663 will only be made if __array__ returns a copy, if obj is a | |
664 nested sequence, or if a copy is needed to satisfy any of the other | |
665 requirements (`dtype`, `order`, etc.). | |
666 order : {'C', 'F', 'A'}, optional | |
667 Specify the order of the array. If order is 'C' (default), then the | |
668 array will be in C-contiguous order (last-index varies the | |
669 fastest). If order is 'F', then the returned array | |
670 will be in Fortran-contiguous order (first-index varies the | |
671 fastest). If order is 'A', then the returned array may | |
672 be in any order (either C-, Fortran-contiguous, or even | |
673 discontiguous). | |
674 subok : bool, optional | |
675 If True, then sub-classes will be passed-through, otherwise | |
676 the returned array will be forced to be a base-class array (default). | |
677 ndmin : int, optional | |
678 Specifies the minimum number of dimensions that the resulting | |
679 array should have. Ones will be pre-pended to the shape as | |
680 needed to meet this requirement. | |
681 | |
682 Returns | |
683 ------- | |
684 out : ndarray | |
685 An array object satisfying the specified requirements. | |
686 | |
687 See Also | |
688 -------- | |
689 empty, empty_like, zeros, zeros_like, ones, ones_like, fill | |
690 | |
691 Examples | |
692 -------- | |
693 >>> np.array([1, 2, 3]) | |
694 array([1, 2, 3]) | |
695 | |
696 Upcasting: | |
697 | |
698 >>> np.array([1, 2, 3.0]) | |
699 array([ 1., 2., 3.]) | |
700 | |
701 More than one dimension: | |
702 | |
703 >>> np.array([[1, 2], [3, 4]]) | |
704 array([[1, 2], | |
705 [3, 4]]) | |
706 | |
707 Minimum dimensions 2: | |
708 | |
709 >>> np.array([1, 2, 3], ndmin=2) | |
710 array([[1, 2, 3]]) | |
711 | |
712 Type provided: | |
713 | |
714 >>> np.array([1, 2, 3], dtype=complex) | |
715 array([ 1.+0.j, 2.+0.j, 3.+0.j]) | |
716 | |
717 Data-type consisting of more than one element: | |
718 | |
719 >>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')]) | |
720 >>> x['a'] | |
721 array([1, 3]) | |
722 | |
723 Creating an array from sub-classes: | |
724 | |
725 >>> np.array(np.mat('1 2; 3 4')) | |
726 array([[1, 2], | |
727 [3, 4]]) | |
728 | |
729 >>> np.array(np.mat('1 2; 3 4'), subok=True) | |
730 matrix([[1, 2], | |
731 [3, 4]]) | |
732 | |
733 """) | |
734 | |
735 add_newdoc('numpy.core.multiarray', 'empty', | |
736 """ | |
737 empty(shape, dtype=float, order='C') | |
738 | |
739 Return a new array of given shape and type, without initializing entries. | |
740 | |
741 Parameters | |
742 ---------- | |
743 shape : int or tuple of int | |
744 Shape of the empty array | |
745 dtype : data-type, optional | |
746 Desired output data-type. | |
747 order : {'C', 'F'}, optional | |
748 Whether to store multi-dimensional data in C (row-major) or | |
749 Fortran (column-major) order in memory. | |
750 | |
751 Returns | |
752 ------- | |
753 out : ndarray | |
754 Array of uninitialized (arbitrary) data with the given | |
755 shape, dtype, and order. | |
756 | |
757 See Also | |
758 -------- | |
759 empty_like, zeros, ones | |
760 | |
761 Notes | |
762 ----- | |
763 `empty`, unlike `zeros`, does not set the array values to zero, | |
764 and may therefore be marginally faster. On the other hand, it requires | |
765 the user to manually set all the values in the array, and should be | |
766 used with caution. | |
767 | |
768 Examples | |
769 -------- | |
770 >>> np.empty([2, 2]) | |
771 array([[ -9.74499359e+001, 6.69583040e-309], | |
772 [ 2.13182611e-314, 3.06959433e-309]]) #random | |
773 | |
774 >>> np.empty([2, 2], dtype=int) | |
775 array([[-1073741821, -1067949133], | |
776 [ 496041986, 19249760]]) #random | |
777 | |
778 """) | |
779 | |
780 add_newdoc('numpy.core.multiarray', 'empty_like', | |
781 """ | |
782 empty_like(a, dtype=None, order='K', subok=True) | |
783 | |
784 Return a new array with the same shape and type as a given array. | |
785 | |
786 Parameters | |
787 ---------- | |
788 a : array_like | |
789 The shape and data-type of `a` define these same attributes of the | |
790 returned array. | |
791 dtype : data-type, optional | |
792 .. versionadded:: 1.6.0 | |
793 Overrides the data type of the result. | |
794 order : {'C', 'F', 'A', or 'K'}, optional | |
795 .. versionadded:: 1.6.0 | |
796 Overrides the memory layout of the result. 'C' means C-order, | |
797 'F' means F-order, 'A' means 'F' if ``a`` is Fortran contiguous, | |
798 'C' otherwise. 'K' means match the layout of ``a`` as closely | |
799 as possible. | |
800 subok : bool, optional. | |
801 If True, then the newly created array will use the sub-class | |
802 type of 'a', otherwise it will be a base-class array. Defaults | |
803 to True. | |
804 | |
805 Returns | |
806 ------- | |
807 out : ndarray | |
808 Array of uninitialized (arbitrary) data with the same | |
809 shape and type as `a`. | |
810 | |
811 See Also | |
812 -------- | |
813 ones_like : Return an array of ones with shape and type of input. | |
814 zeros_like : Return an array of zeros with shape and type of input. | |
815 empty : Return a new uninitialized array. | |
816 ones : Return a new array setting values to one. | |
817 zeros : Return a new array setting values to zero. | |
818 | |
819 Notes | |
820 ----- | |
821 This function does *not* initialize the returned array; to do that use | |
822 `zeros_like` or `ones_like` instead. It may be marginally faster than | |
823 the functions that do set the array values. | |
824 | |
825 Examples | |
826 -------- | |
827 >>> a = ([1,2,3], [4,5,6]) # a is array-like | |
828 >>> np.empty_like(a) | |
829 array([[-1073741821, -1073741821, 3], #random | |
830 [ 0, 0, -1073741821]]) | |
831 >>> a = np.array([[1., 2., 3.],[4.,5.,6.]]) | |
832 >>> np.empty_like(a) | |
833 array([[ -2.00000715e+000, 1.48219694e-323, -2.00000572e+000],#random | |
834 [ 4.38791518e-305, -2.00000715e+000, 4.17269252e-309]]) | |
835 | |
836 """) | |
837 | |
838 | |
839 add_newdoc('numpy.core.multiarray', 'scalar', | |
840 """ | |
841 scalar(dtype, obj) | |
842 | |
843 Return a new scalar array of the given type initialized with obj. | |
844 | |
845 This function is meant mainly for pickle support. `dtype` must be a | |
846 valid data-type descriptor. If `dtype` corresponds to an object | |
847 descriptor, then `obj` can be any object, otherwise `obj` must be a | |
848 string. If `obj` is not given, it will be interpreted as None for object | |
849 type and as zeros for all other types. | |
850 | |
851 """) | |
852 | |
853 add_newdoc('numpy.core.multiarray', 'zeros', | |
854 """ | |
855 zeros(shape, dtype=float, order='C') | |
856 | |
857 Return a new array of given shape and type, filled with zeros. | |
858 | |
859 Parameters | |
860 ---------- | |
861 shape : int or sequence of ints | |
862 Shape of the new array, e.g., ``(2, 3)`` or ``2``. | |
863 dtype : data-type, optional | |
864 The desired data-type for the array, e.g., `numpy.int8`. Default is | |
865 `numpy.float64`. | |
866 order : {'C', 'F'}, optional | |
867 Whether to store multidimensional data in C- or Fortran-contiguous | |
868 (row- or column-wise) order in memory. | |
869 | |
870 Returns | |
871 ------- | |
872 out : ndarray | |
873 Array of zeros with the given shape, dtype, and order. | |
874 | |
875 See Also | |
876 -------- | |
877 zeros_like : Return an array of zeros with shape and type of input. | |
878 ones_like : Return an array of ones with shape and type of input. | |
879 empty_like : Return an empty array with shape and type of input. | |
880 ones : Return a new array setting values to one. | |
881 empty : Return a new uninitialized array. | |
882 | |
883 Examples | |
884 -------- | |
885 >>> np.zeros(5) | |
886 array([ 0., 0., 0., 0., 0.]) | |
887 | |
888 >>> np.zeros((5,), dtype=numpy.int) | |
889 array([0, 0, 0, 0, 0]) | |
890 | |
891 >>> np.zeros((2, 1)) | |
892 array([[ 0.], | |
893 [ 0.]]) | |
894 | |
895 >>> s = (2,2) | |
896 >>> np.zeros(s) | |
897 array([[ 0., 0.], | |
898 [ 0., 0.]]) | |
899 | |
900 >>> np.zeros((2,), dtype=[('x', 'i4'), ('y', 'i4')]) # custom dtype | |
901 array([(0, 0), (0, 0)], | |
902 dtype=[('x', '<i4'), ('y', '<i4')]) | |
903 | |
904 """) | |
905 | |
906 add_newdoc('numpy.core.multiarray', 'count_nonzero', | |
907 """ | |
908 count_nonzero(a) | |
909 | |
910 Counts the number of non-zero values in the array ``a``. | |
911 | |
912 Parameters | |
913 ---------- | |
914 a : array_like | |
915 The array for which to count non-zeros. | |
916 | |
917 Returns | |
918 ------- | |
919 count : int or array of int | |
920 Number of non-zero values in the array. | |
921 | |
922 See Also | |
923 -------- | |
924 nonzero : Return the coordinates of all the non-zero values. | |
925 | |
926 Examples | |
927 -------- | |
928 >>> np.count_nonzero(np.eye(4)) | |
929 4 | |
930 >>> np.count_nonzero([[0,1,7,0,0],[3,0,0,2,19]]) | |
931 5 | |
932 """) | |
933 | |
934 add_newdoc('numpy.core.multiarray', 'set_typeDict', | |
935 """set_typeDict(dict) | |
936 | |
937 Set the internal dictionary that can look up an array type using a | |
938 registered code. | |
939 | |
940 """) | |
941 | |
942 add_newdoc('numpy.core.multiarray', 'fromstring', | |
943 """ | |
944 fromstring(string, dtype=float, count=-1, sep='') | |
945 | |
946 A new 1-D array initialized from raw binary or text data in a string. | |
947 | |
948 Parameters | |
949 ---------- | |
950 string : str | |
951 A string containing the data. | |
952 dtype : data-type, optional | |
953 The data type of the array; default: float. For binary input data, | |
954 the data must be in exactly this format. | |
955 count : int, optional | |
956 Read this number of `dtype` elements from the data. If this is | |
957 negative (the default), the count will be determined from the | |
958 length of the data. | |
959 sep : str, optional | |
960 If not provided or, equivalently, the empty string, the data will | |
961 be interpreted as binary data; otherwise, as ASCII text with | |
962 decimal numbers. Also in this latter case, this argument is | |
963 interpreted as the string separating numbers in the data; extra | |
964 whitespace between elements is also ignored. | |
965 | |
966 Returns | |
967 ------- | |
968 arr : ndarray | |
969 The constructed array. | |
970 | |
971 Raises | |
972 ------ | |
973 ValueError | |
974 If the string is not the correct size to satisfy the requested | |
975 `dtype` and `count`. | |
976 | |
977 See Also | |
978 -------- | |
979 frombuffer, fromfile, fromiter | |
980 | |
981 Examples | |
982 -------- | |
983 >>> np.fromstring('\\x01\\x02', dtype=np.uint8) | |
984 array([1, 2], dtype=uint8) | |
985 >>> np.fromstring('1 2', dtype=int, sep=' ') | |
986 array([1, 2]) | |
987 >>> np.fromstring('1, 2', dtype=int, sep=',') | |
988 array([1, 2]) | |
989 >>> np.fromstring('\\x01\\x02\\x03\\x04\\x05', dtype=np.uint8, count=3) | |
990 array([1, 2, 3], dtype=uint8) | |
991 | |
992 """) | |
993 | |
994 add_newdoc('numpy.core.multiarray', 'fromiter', | |
995 """ | |
996 fromiter(iterable, dtype, count=-1) | |
997 | |
998 Create a new 1-dimensional array from an iterable object. | |
999 | |
1000 Parameters | |
1001 ---------- | |
1002 iterable : iterable object | |
1003 An iterable object providing data for the array. | |
1004 dtype : data-type | |
1005 The data-type of the returned array. | |
1006 count : int, optional | |
1007 The number of items to read from *iterable*. The default is -1, | |
1008 which means all data is read. | |
1009 | |
1010 Returns | |
1011 ------- | |
1012 out : ndarray | |
1013 The output array. | |
1014 | |
1015 Notes | |
1016 ----- | |
1017 Specify `count` to improve performance. It allows ``fromiter`` to | |
1018 pre-allocate the output array, instead of resizing it on demand. | |
1019 | |
1020 Examples | |
1021 -------- | |
1022 >>> iterable = (x*x for x in range(5)) | |
1023 >>> np.fromiter(iterable, np.float) | |
1024 array([ 0., 1., 4., 9., 16.]) | |
1025 | |
1026 """) | |
1027 | |
1028 add_newdoc('numpy.core.multiarray', 'fromfile', | |
1029 """ | |
1030 fromfile(file, dtype=float, count=-1, sep='') | |
1031 | |
1032 Construct an array from data in a text or binary file. | |
1033 | |
1034 A highly efficient way of reading binary data with a known data-type, | |
1035 as well as parsing simply formatted text files. Data written using the | |
1036 `tofile` method can be read using this function. | |
1037 | |
1038 Parameters | |
1039 ---------- | |
1040 file : file or str | |
1041 Open file object or filename. | |
1042 dtype : data-type | |
1043 Data type of the returned array. | |
1044 For binary files, it is used to determine the size and byte-order | |
1045 of the items in the file. | |
1046 count : int | |
1047 Number of items to read. ``-1`` means all items (i.e., the complete | |
1048 file). | |
1049 sep : str | |
1050 Separator between items if file is a text file. | |
1051 Empty ("") separator means the file should be treated as binary. | |
1052 Spaces (" ") in the separator match zero or more whitespace characters. | |
1053 A separator consisting only of spaces must match at least one | |
1054 whitespace. | |
1055 | |
1056 See also | |
1057 -------- | |
1058 load, save | |
1059 ndarray.tofile | |
1060 loadtxt : More flexible way of loading data from a text file. | |
1061 | |
1062 Notes | |
1063 ----- | |
1064 Do not rely on the combination of `tofile` and `fromfile` for | |
1065 data storage, as the binary files generated are are not platform | |
1066 independent. In particular, no byte-order or data-type information is | |
1067 saved. Data can be stored in the platform independent ``.npy`` format | |
1068 using `save` and `load` instead. | |
1069 | |
1070 Examples | |
1071 -------- | |
1072 Construct an ndarray: | |
1073 | |
1074 >>> dt = np.dtype([('time', [('min', int), ('sec', int)]), | |
1075 ... ('temp', float)]) | |
1076 >>> x = np.zeros((1,), dtype=dt) | |
1077 >>> x['time']['min'] = 10; x['temp'] = 98.25 | |
1078 >>> x | |
1079 array([((10, 0), 98.25)], | |
1080 dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')]) | |
1081 | |
1082 Save the raw data to disk: | |
1083 | |
1084 >>> import os | |
1085 >>> fname = os.tmpnam() | |
1086 >>> x.tofile(fname) | |
1087 | |
1088 Read the raw data from disk: | |
1089 | |
1090 >>> np.fromfile(fname, dtype=dt) | |
1091 array([((10, 0), 98.25)], | |
1092 dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')]) | |
1093 | |
1094 The recommended way to store and load data: | |
1095 | |
1096 >>> np.save(fname, x) | |
1097 >>> np.load(fname + '.npy') | |
1098 array([((10, 0), 98.25)], | |
1099 dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')]) | |
1100 | |
1101 """) | |
1102 | |
1103 add_newdoc('numpy.core.multiarray', 'frombuffer', | |
1104 """ | |
1105 frombuffer(buffer, dtype=float, count=-1, offset=0) | |
1106 | |
1107 Interpret a buffer as a 1-dimensional array. | |
1108 | |
1109 Parameters | |
1110 ---------- | |
1111 buffer : buffer_like | |
1112 An object that exposes the buffer interface. | |
1113 dtype : data-type, optional | |
1114 Data-type of the returned array; default: float. | |
1115 count : int, optional | |
1116 Number of items to read. ``-1`` means all data in the buffer. | |
1117 offset : int, optional | |
1118 Start reading the buffer from this offset; default: 0. | |
1119 | |
1120 Notes | |
1121 ----- | |
1122 If the buffer has data that is not in machine byte-order, this should | |
1123 be specified as part of the data-type, e.g.:: | |
1124 | |
1125 >>> dt = np.dtype(int) | |
1126 >>> dt = dt.newbyteorder('>') | |
1127 >>> np.frombuffer(buf, dtype=dt) | |
1128 | |
1129 The data of the resulting array will not be byteswapped, but will be | |
1130 interpreted correctly. | |
1131 | |
1132 Examples | |
1133 -------- | |
1134 >>> s = 'hello world' | |
1135 >>> np.frombuffer(s, dtype='S1', count=5, offset=6) | |
1136 array(['w', 'o', 'r', 'l', 'd'], | |
1137 dtype='|S1') | |
1138 | |
1139 """) | |
1140 | |
1141 add_newdoc('numpy.core.multiarray', 'concatenate', | |
1142 """ | |
1143 concatenate((a1, a2, ...), axis=0) | |
1144 | |
1145 Join a sequence of arrays together. | |
1146 | |
1147 Parameters | |
1148 ---------- | |
1149 a1, a2, ... : sequence of array_like | |
1150 The arrays must have the same shape, except in the dimension | |
1151 corresponding to `axis` (the first, by default). | |
1152 axis : int, optional | |
1153 The axis along which the arrays will be joined. Default is 0. | |
1154 | |
1155 Returns | |
1156 ------- | |
1157 res : ndarray | |
1158 The concatenated array. | |
1159 | |
1160 See Also | |
1161 -------- | |
1162 ma.concatenate : Concatenate function that preserves input masks. | |
1163 array_split : Split an array into multiple sub-arrays of equal or | |
1164 near-equal size. | |
1165 split : Split array into a list of multiple sub-arrays of equal size. | |
1166 hsplit : Split array into multiple sub-arrays horizontally (column wise) | |
1167 vsplit : Split array into multiple sub-arrays vertically (row wise) | |
1168 dsplit : Split array into multiple sub-arrays along the 3rd axis (depth). | |
1169 hstack : Stack arrays in sequence horizontally (column wise) | |
1170 vstack : Stack arrays in sequence vertically (row wise) | |
1171 dstack : Stack arrays in sequence depth wise (along third dimension) | |
1172 | |
1173 Notes | |
1174 ----- | |
1175 When one or more of the arrays to be concatenated is a MaskedArray, | |
1176 this function will return a MaskedArray object instead of an ndarray, | |
1177 but the input masks are *not* preserved. In cases where a MaskedArray | |
1178 is expected as input, use the ma.concatenate function from the masked | |
1179 array module instead. | |
1180 | |
1181 Examples | |
1182 -------- | |
1183 >>> a = np.array([[1, 2], [3, 4]]) | |
1184 >>> b = np.array([[5, 6]]) | |
1185 >>> np.concatenate((a, b), axis=0) | |
1186 array([[1, 2], | |
1187 [3, 4], | |
1188 [5, 6]]) | |
1189 >>> np.concatenate((a, b.T), axis=1) | |
1190 array([[1, 2, 5], | |
1191 [3, 4, 6]]) | |
1192 | |
1193 This function will not preserve masking of MaskedArray inputs. | |
1194 | |
1195 >>> a = np.ma.arange(3) | |
1196 >>> a[1] = np.ma.masked | |
1197 >>> b = np.arange(2, 5) | |
1198 >>> a | |
1199 masked_array(data = [0 -- 2], | |
1200 mask = [False True False], | |
1201 fill_value = 999999) | |
1202 >>> b | |
1203 array([2, 3, 4]) | |
1204 >>> np.concatenate([a, b]) | |
1205 masked_array(data = [0 1 2 2 3 4], | |
1206 mask = False, | |
1207 fill_value = 999999) | |
1208 >>> np.ma.concatenate([a, b]) | |
1209 masked_array(data = [0 -- 2 2 3 4], | |
1210 mask = [False True False False False False], | |
1211 fill_value = 999999) | |
1212 | |
1213 """) | |
1214 | |
1215 add_newdoc('numpy.core', 'inner', | |
1216 """ | |
1217 inner(a, b) | |
1218 | |
1219 Inner product of two arrays. | |
1220 | |
1221 Ordinary inner product of vectors for 1-D arrays (without complex | |
1222 conjugation), in higher dimensions a sum product over the last axes. | |
1223 | |
1224 Parameters | |
1225 ---------- | |
1226 a, b : array_like | |
1227 If `a` and `b` are nonscalar, their last dimensions of must match. | |
1228 | |
1229 Returns | |
1230 ------- | |
1231 out : ndarray | |
1232 `out.shape = a.shape[:-1] + b.shape[:-1]` | |
1233 | |
1234 Raises | |
1235 ------ | |
1236 ValueError | |
1237 If the last dimension of `a` and `b` has different size. | |
1238 | |
1239 See Also | |
1240 -------- | |
1241 tensordot : Sum products over arbitrary axes. | |
1242 dot : Generalised matrix product, using second last dimension of `b`. | |
1243 einsum : Einstein summation convention. | |
1244 | |
1245 Notes | |
1246 ----- | |
1247 For vectors (1-D arrays) it computes the ordinary inner-product:: | |
1248 | |
1249 np.inner(a, b) = sum(a[:]*b[:]) | |
1250 | |
1251 More generally, if `ndim(a) = r > 0` and `ndim(b) = s > 0`:: | |
1252 | |
1253 np.inner(a, b) = np.tensordot(a, b, axes=(-1,-1)) | |
1254 | |
1255 or explicitly:: | |
1256 | |
1257 np.inner(a, b)[i0,...,ir-1,j0,...,js-1] | |
1258 = sum(a[i0,...,ir-1,:]*b[j0,...,js-1,:]) | |
1259 | |
1260 In addition `a` or `b` may be scalars, in which case:: | |
1261 | |
1262 np.inner(a,b) = a*b | |
1263 | |
1264 Examples | |
1265 -------- | |
1266 Ordinary inner product for vectors: | |
1267 | |
1268 >>> a = np.array([1,2,3]) | |
1269 >>> b = np.array([0,1,0]) | |
1270 >>> np.inner(a, b) | |
1271 2 | |
1272 | |
1273 A multidimensional example: | |
1274 | |
1275 >>> a = np.arange(24).reshape((2,3,4)) | |
1276 >>> b = np.arange(4) | |
1277 >>> np.inner(a, b) | |
1278 array([[ 14, 38, 62], | |
1279 [ 86, 110, 134]]) | |
1280 | |
1281 An example where `b` is a scalar: | |
1282 | |
1283 >>> np.inner(np.eye(2), 7) | |
1284 array([[ 7., 0.], | |
1285 [ 0., 7.]]) | |
1286 | |
1287 """) | |
1288 | |
1289 add_newdoc('numpy.core', 'fastCopyAndTranspose', | |
1290 """_fastCopyAndTranspose(a)""") | |
1291 | |
1292 add_newdoc('numpy.core.multiarray', 'correlate', | |
1293 """cross_correlate(a,v, mode=0)""") | |
1294 | |
1295 add_newdoc('numpy.core.multiarray', 'arange', | |
1296 """ | |
1297 arange([start,] stop[, step,], dtype=None) | |
1298 | |
1299 Return evenly spaced values within a given interval. | |
1300 | |
1301 Values are generated within the half-open interval ``[start, stop)`` | |
1302 (in other words, the interval including `start` but excluding `stop`). | |
1303 For integer arguments the function is equivalent to the Python built-in | |
1304 `range <http://docs.python.org/lib/built-in-funcs.html>`_ function, | |
1305 but returns an ndarray rather than a list. | |
1306 | |
1307 When using a non-integer step, such as 0.1, the results will often not | |
1308 be consistent. It is better to use ``linspace`` for these cases. | |
1309 | |
1310 Parameters | |
1311 ---------- | |
1312 start : number, optional | |
1313 Start of interval. The interval includes this value. The default | |
1314 start value is 0. | |
1315 stop : number | |
1316 End of interval. The interval does not include this value, except | |
1317 in some cases where `step` is not an integer and floating point | |
1318 round-off affects the length of `out`. | |
1319 step : number, optional | |
1320 Spacing between values. For any output `out`, this is the distance | |
1321 between two adjacent values, ``out[i+1] - out[i]``. The default | |
1322 step size is 1. If `step` is specified, `start` must also be given. | |
1323 dtype : dtype | |
1324 The type of the output array. If `dtype` is not given, infer the data | |
1325 type from the other input arguments. | |
1326 | |
1327 Returns | |
1328 ------- | |
1329 arange : ndarray | |
1330 Array of evenly spaced values. | |
1331 | |
1332 For floating point arguments, the length of the result is | |
1333 ``ceil((stop - start)/step)``. Because of floating point overflow, | |
1334 this rule may result in the last element of `out` being greater | |
1335 than `stop`. | |
1336 | |
1337 See Also | |
1338 -------- | |
1339 linspace : Evenly spaced numbers with careful handling of endpoints. | |
1340 ogrid: Arrays of evenly spaced numbers in N-dimensions. | |
1341 mgrid: Grid-shaped arrays of evenly spaced numbers in N-dimensions. | |
1342 | |
1343 Examples | |
1344 -------- | |
1345 >>> np.arange(3) | |
1346 array([0, 1, 2]) | |
1347 >>> np.arange(3.0) | |
1348 array([ 0., 1., 2.]) | |
1349 >>> np.arange(3,7) | |
1350 array([3, 4, 5, 6]) | |
1351 >>> np.arange(3,7,2) | |
1352 array([3, 5]) | |
1353 | |
1354 """) | |
1355 | |
1356 add_newdoc('numpy.core.multiarray', '_get_ndarray_c_version', | |
1357 """_get_ndarray_c_version() | |
1358 | |
1359 Return the compile time NDARRAY_VERSION number. | |
1360 | |
1361 """) | |
1362 | |
1363 add_newdoc('numpy.core.multiarray', '_reconstruct', | |
1364 """_reconstruct(subtype, shape, dtype) | |
1365 | |
1366 Construct an empty array. Used by Pickles. | |
1367 | |
1368 """) | |
1369 | |
1370 | |
1371 add_newdoc('numpy.core.multiarray', 'set_string_function', | |
1372 """ | |
1373 set_string_function(f, repr=1) | |
1374 | |
1375 Internal method to set a function to be used when pretty printing arrays. | |
1376 | |
1377 """) | |
1378 | |
1379 add_newdoc('numpy.core.multiarray', 'set_numeric_ops', | |
1380 """ | |
1381 set_numeric_ops(op1=func1, op2=func2, ...) | |
1382 | |
1383 Set numerical operators for array objects. | |
1384 | |
1385 Parameters | |
1386 ---------- | |
1387 op1, op2, ... : callable | |
1388 Each ``op = func`` pair describes an operator to be replaced. | |
1389 For example, ``add = lambda x, y: np.add(x, y) % 5`` would replace | |
1390 addition by modulus 5 addition. | |
1391 | |
1392 Returns | |
1393 ------- | |
1394 saved_ops : list of callables | |
1395 A list of all operators, stored before making replacements. | |
1396 | |
1397 Notes | |
1398 ----- | |
1399 .. WARNING:: | |
1400 Use with care! Incorrect usage may lead to memory errors. | |
1401 | |
1402 A function replacing an operator cannot make use of that operator. | |
1403 For example, when replacing add, you may not use ``+``. Instead, | |
1404 directly call ufuncs. | |
1405 | |
1406 Examples | |
1407 -------- | |
1408 >>> def add_mod5(x, y): | |
1409 ... return np.add(x, y) % 5 | |
1410 ... | |
1411 >>> old_funcs = np.set_numeric_ops(add=add_mod5) | |
1412 | |
1413 >>> x = np.arange(12).reshape((3, 4)) | |
1414 >>> x + x | |
1415 array([[0, 2, 4, 1], | |
1416 [3, 0, 2, 4], | |
1417 [1, 3, 0, 2]]) | |
1418 | |
1419 >>> ignore = np.set_numeric_ops(**old_funcs) # restore operators | |
1420 | |
1421 """) | |
1422 | |
1423 add_newdoc('numpy.core.multiarray', 'where', | |
1424 """ | |
1425 where(condition, [x, y]) | |
1426 | |
1427 Return elements, either from `x` or `y`, depending on `condition`. | |
1428 | |
1429 If only `condition` is given, return ``condition.nonzero()``. | |
1430 | |
1431 Parameters | |
1432 ---------- | |
1433 condition : array_like, bool | |
1434 When True, yield `x`, otherwise yield `y`. | |
1435 x, y : array_like, optional | |
1436 Values from which to choose. `x` and `y` need to have the same | |
1437 shape as `condition`. | |
1438 | |
1439 Returns | |
1440 ------- | |
1441 out : ndarray or tuple of ndarrays | |
1442 If both `x` and `y` are specified, the output array contains | |
1443 elements of `x` where `condition` is True, and elements from | |
1444 `y` elsewhere. | |
1445 | |
1446 If only `condition` is given, return the tuple | |
1447 ``condition.nonzero()``, the indices where `condition` is True. | |
1448 | |
1449 See Also | |
1450 -------- | |
1451 nonzero, choose | |
1452 | |
1453 Notes | |
1454 ----- | |
1455 If `x` and `y` are given and input arrays are 1-D, `where` is | |
1456 equivalent to:: | |
1457 | |
1458 [xv if c else yv for (c,xv,yv) in zip(condition,x,y)] | |
1459 | |
1460 Examples | |
1461 -------- | |
1462 >>> np.where([[True, False], [True, True]], | |
1463 ... [[1, 2], [3, 4]], | |
1464 ... [[9, 8], [7, 6]]) | |
1465 array([[1, 8], | |
1466 [3, 4]]) | |
1467 | |
1468 >>> np.where([[0, 1], [1, 0]]) | |
1469 (array([0, 1]), array([1, 0])) | |
1470 | |
1471 >>> x = np.arange(9.).reshape(3, 3) | |
1472 >>> np.where( x > 5 ) | |
1473 (array([2, 2, 2]), array([0, 1, 2])) | |
1474 >>> x[np.where( x > 3.0 )] # Note: result is 1D. | |
1475 array([ 4., 5., 6., 7., 8.]) | |
1476 >>> np.where(x < 5, x, -1) # Note: broadcasting. | |
1477 array([[ 0., 1., 2.], | |
1478 [ 3., 4., -1.], | |
1479 [-1., -1., -1.]]) | |
1480 | |
1481 Find the indices of elements of `x` that are in `goodvalues`. | |
1482 | |
1483 >>> goodvalues = [3, 4, 7] | |
1484 >>> ix = np.in1d(x.ravel(), goodvalues).reshape(x.shape) | |
1485 >>> ix | |
1486 array([[False, False, False], | |
1487 [ True, True, False], | |
1488 [False, True, False]], dtype=bool) | |
1489 >>> np.where(ix) | |
1490 (array([1, 1, 2]), array([0, 1, 1])) | |
1491 | |
1492 """) | |
1493 | |
1494 | |
1495 add_newdoc('numpy.core.multiarray', 'lexsort', | |
1496 """ | |
1497 lexsort(keys, axis=-1) | |
1498 | |
1499 Perform an indirect sort using a sequence of keys. | |
1500 | |
1501 Given multiple sorting keys, which can be interpreted as columns in a | |
1502 spreadsheet, lexsort returns an array of integer indices that describes | |
1503 the sort order by multiple columns. The last key in the sequence is used | |
1504 for the primary sort order, the second-to-last key for the secondary sort | |
1505 order, and so on. The keys argument must be a sequence of objects that | |
1506 can be converted to arrays of the same shape. If a 2D array is provided | |
1507 for the keys argument, it's rows are interpreted as the sorting keys and | |
1508 sorting is according to the last row, second last row etc. | |
1509 | |
1510 Parameters | |
1511 ---------- | |
1512 keys : (k, N) array or tuple containing k (N,)-shaped sequences | |
1513 The `k` different "columns" to be sorted. The last column (or row if | |
1514 `keys` is a 2D array) is the primary sort key. | |
1515 axis : int, optional | |
1516 Axis to be indirectly sorted. By default, sort over the last axis. | |
1517 | |
1518 Returns | |
1519 ------- | |
1520 indices : (N,) ndarray of ints | |
1521 Array of indices that sort the keys along the specified axis. | |
1522 | |
1523 See Also | |
1524 -------- | |
1525 argsort : Indirect sort. | |
1526 ndarray.sort : In-place sort. | |
1527 sort : Return a sorted copy of an array. | |
1528 | |
1529 Examples | |
1530 -------- | |
1531 Sort names: first by surname, then by name. | |
1532 | |
1533 >>> surnames = ('Hertz', 'Galilei', 'Hertz') | |
1534 >>> first_names = ('Heinrich', 'Galileo', 'Gustav') | |
1535 >>> ind = np.lexsort((first_names, surnames)) | |
1536 >>> ind | |
1537 array([1, 2, 0]) | |
1538 | |
1539 >>> [surnames[i] + ", " + first_names[i] for i in ind] | |
1540 ['Galilei, Galileo', 'Hertz, Gustav', 'Hertz, Heinrich'] | |
1541 | |
1542 Sort two columns of numbers: | |
1543 | |
1544 >>> a = [1,5,1,4,3,4,4] # First column | |
1545 >>> b = [9,4,0,4,0,2,1] # Second column | |
1546 >>> ind = np.lexsort((b,a)) # Sort by a, then by b | |
1547 >>> print ind | |
1548 [2 0 4 6 5 3 1] | |
1549 | |
1550 >>> [(a[i],b[i]) for i in ind] | |
1551 [(1, 0), (1, 9), (3, 0), (4, 1), (4, 2), (4, 4), (5, 4)] | |
1552 | |
1553 Note that sorting is first according to the elements of ``a``. | |
1554 Secondary sorting is according to the elements of ``b``. | |
1555 | |
1556 A normal ``argsort`` would have yielded: | |
1557 | |
1558 >>> [(a[i],b[i]) for i in np.argsort(a)] | |
1559 [(1, 9), (1, 0), (3, 0), (4, 4), (4, 2), (4, 1), (5, 4)] | |
1560 | |
1561 Structured arrays are sorted lexically by ``argsort``: | |
1562 | |
1563 >>> x = np.array([(1,9), (5,4), (1,0), (4,4), (3,0), (4,2), (4,1)], | |
1564 ... dtype=np.dtype([('x', int), ('y', int)])) | |
1565 | |
1566 >>> np.argsort(x) # or np.argsort(x, order=('x', 'y')) | |
1567 array([2, 0, 4, 6, 5, 3, 1]) | |
1568 | |
1569 """) | |
1570 | |
1571 add_newdoc('numpy.core.multiarray', 'can_cast', | |
1572 """ | |
1573 can_cast(from, totype, casting = 'safe') | |
1574 | |
1575 Returns True if cast between data types can occur according to the | |
1576 casting rule. If from is a scalar or array scalar, also returns | |
1577 True if the scalar value can be cast without overflow or truncation | |
1578 to an integer. | |
1579 | |
1580 Parameters | |
1581 ---------- | |
1582 from : dtype, dtype specifier, scalar, or array | |
1583 Data type, scalar, or array to cast from. | |
1584 totype : dtype or dtype specifier | |
1585 Data type to cast to. | |
1586 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional | |
1587 Controls what kind of data casting may occur. | |
1588 | |
1589 * 'no' means the data types should not be cast at all. | |
1590 * 'equiv' means only byte-order changes are allowed. | |
1591 * 'safe' means only casts which can preserve values are allowed. | |
1592 * 'same_kind' means only safe casts or casts within a kind, | |
1593 like float64 to float32, are allowed. | |
1594 * 'unsafe' means any data conversions may be done. | |
1595 | |
1596 Returns | |
1597 ------- | |
1598 out : bool | |
1599 True if cast can occur according to the casting rule. | |
1600 | |
1601 Notes | |
1602 ----- | |
1603 Starting in NumPy 1.9, can_cast function now returns False in 'safe' | |
1604 casting mode for integer/float dtype and string dtype if the string dtype | |
1605 length is not long enough to store the max integer/float value converted | |
1606 to a string. Previously can_cast in 'safe' mode returned True for | |
1607 integer/float dtype and a string dtype of any length. | |
1608 | |
1609 See also | |
1610 -------- | |
1611 dtype, result_type | |
1612 | |
1613 Examples | |
1614 -------- | |
1615 Basic examples | |
1616 | |
1617 >>> np.can_cast(np.int32, np.int64) | |
1618 True | |
1619 >>> np.can_cast(np.float64, np.complex) | |
1620 True | |
1621 >>> np.can_cast(np.complex, np.float) | |
1622 False | |
1623 | |
1624 >>> np.can_cast('i8', 'f8') | |
1625 True | |
1626 >>> np.can_cast('i8', 'f4') | |
1627 False | |
1628 >>> np.can_cast('i4', 'S4') | |
1629 False | |
1630 | |
1631 Casting scalars | |
1632 | |
1633 >>> np.can_cast(100, 'i1') | |
1634 True | |
1635 >>> np.can_cast(150, 'i1') | |
1636 False | |
1637 >>> np.can_cast(150, 'u1') | |
1638 True | |
1639 | |
1640 >>> np.can_cast(3.5e100, np.float32) | |
1641 False | |
1642 >>> np.can_cast(1000.0, np.float32) | |
1643 True | |
1644 | |
1645 Array scalar checks the value, array does not | |
1646 | |
1647 >>> np.can_cast(np.array(1000.0), np.float32) | |
1648 True | |
1649 >>> np.can_cast(np.array([1000.0]), np.float32) | |
1650 False | |
1651 | |
1652 Using the casting rules | |
1653 | |
1654 >>> np.can_cast('i8', 'i8', 'no') | |
1655 True | |
1656 >>> np.can_cast('<i8', '>i8', 'no') | |
1657 False | |
1658 | |
1659 >>> np.can_cast('<i8', '>i8', 'equiv') | |
1660 True | |
1661 >>> np.can_cast('<i4', '>i8', 'equiv') | |
1662 False | |
1663 | |
1664 >>> np.can_cast('<i4', '>i8', 'safe') | |
1665 True | |
1666 >>> np.can_cast('<i8', '>i4', 'safe') | |
1667 False | |
1668 | |
1669 >>> np.can_cast('<i8', '>i4', 'same_kind') | |
1670 True | |
1671 >>> np.can_cast('<i8', '>u4', 'same_kind') | |
1672 False | |
1673 | |
1674 >>> np.can_cast('<i8', '>u4', 'unsafe') | |
1675 True | |
1676 | |
1677 """) | |
1678 | |
1679 add_newdoc('numpy.core.multiarray', 'promote_types', | |
1680 """ | |
1681 promote_types(type1, type2) | |
1682 | |
1683 Returns the data type with the smallest size and smallest scalar | |
1684 kind to which both ``type1`` and ``type2`` may be safely cast. | |
1685 The returned data type is always in native byte order. | |
1686 | |
1687 This function is symmetric and associative. | |
1688 | |
1689 Parameters | |
1690 ---------- | |
1691 type1 : dtype or dtype specifier | |
1692 First data type. | |
1693 type2 : dtype or dtype specifier | |
1694 Second data type. | |
1695 | |
1696 Returns | |
1697 ------- | |
1698 out : dtype | |
1699 The promoted data type. | |
1700 | |
1701 Notes | |
1702 ----- | |
1703 .. versionadded:: 1.6.0 | |
1704 Starting in NumPy 1.9, promote_types function now returns a valid string | |
1705 length when given an integer or float dtype as one argument and a string | |
1706 dtype as another argument. Previously it always returned the input string | |
1707 dtype, even if it wasn't long enough to store the max integer/float value | |
1708 converted to a string. | |
1709 | |
1710 See Also | |
1711 -------- | |
1712 result_type, dtype, can_cast | |
1713 | |
1714 Examples | |
1715 -------- | |
1716 >>> np.promote_types('f4', 'f8') | |
1717 dtype('float64') | |
1718 | |
1719 >>> np.promote_types('i8', 'f4') | |
1720 dtype('float64') | |
1721 | |
1722 >>> np.promote_types('>i8', '<c8') | |
1723 dtype('complex128') | |
1724 | |
1725 >>> np.promote_types('i4', 'S8') | |
1726 dtype('S11') | |
1727 | |
1728 """) | |
1729 | |
1730 add_newdoc('numpy.core.multiarray', 'min_scalar_type', | |
1731 """ | |
1732 min_scalar_type(a) | |
1733 | |
1734 For scalar ``a``, returns the data type with the smallest size | |
1735 and smallest scalar kind which can hold its value. For non-scalar | |
1736 array ``a``, returns the vector's dtype unmodified. | |
1737 | |
1738 Floating point values are not demoted to integers, | |
1739 and complex values are not demoted to floats. | |
1740 | |
1741 Parameters | |
1742 ---------- | |
1743 a : scalar or array_like | |
1744 The value whose minimal data type is to be found. | |
1745 | |
1746 Returns | |
1747 ------- | |
1748 out : dtype | |
1749 The minimal data type. | |
1750 | |
1751 Notes | |
1752 ----- | |
1753 .. versionadded:: 1.6.0 | |
1754 | |
1755 See Also | |
1756 -------- | |
1757 result_type, promote_types, dtype, can_cast | |
1758 | |
1759 Examples | |
1760 -------- | |
1761 >>> np.min_scalar_type(10) | |
1762 dtype('uint8') | |
1763 | |
1764 >>> np.min_scalar_type(-260) | |
1765 dtype('int16') | |
1766 | |
1767 >>> np.min_scalar_type(3.1) | |
1768 dtype('float16') | |
1769 | |
1770 >>> np.min_scalar_type(1e50) | |
1771 dtype('float64') | |
1772 | |
1773 >>> np.min_scalar_type(np.arange(4,dtype='f8')) | |
1774 dtype('float64') | |
1775 | |
1776 """) | |
1777 | |
1778 add_newdoc('numpy.core.multiarray', 'result_type', | |
1779 """ | |
1780 result_type(*arrays_and_dtypes) | |
1781 | |
1782 Returns the type that results from applying the NumPy | |
1783 type promotion rules to the arguments. | |
1784 | |
1785 Type promotion in NumPy works similarly to the rules in languages | |
1786 like C++, with some slight differences. When both scalars and | |
1787 arrays are used, the array's type takes precedence and the actual value | |
1788 of the scalar is taken into account. | |
1789 | |
1790 For example, calculating 3*a, where a is an array of 32-bit floats, | |
1791 intuitively should result in a 32-bit float output. If the 3 is a | |
1792 32-bit integer, the NumPy rules indicate it can't convert losslessly | |
1793 into a 32-bit float, so a 64-bit float should be the result type. | |
1794 By examining the value of the constant, '3', we see that it fits in | |
1795 an 8-bit integer, which can be cast losslessly into the 32-bit float. | |
1796 | |
1797 Parameters | |
1798 ---------- | |
1799 arrays_and_dtypes : list of arrays and dtypes | |
1800 The operands of some operation whose result type is needed. | |
1801 | |
1802 Returns | |
1803 ------- | |
1804 out : dtype | |
1805 The result type. | |
1806 | |
1807 See also | |
1808 -------- | |
1809 dtype, promote_types, min_scalar_type, can_cast | |
1810 | |
1811 Notes | |
1812 ----- | |
1813 .. versionadded:: 1.6.0 | |
1814 | |
1815 The specific algorithm used is as follows. | |
1816 | |
1817 Categories are determined by first checking which of boolean, | |
1818 integer (int/uint), or floating point (float/complex) the maximum | |
1819 kind of all the arrays and the scalars are. | |
1820 | |
1821 If there are only scalars or the maximum category of the scalars | |
1822 is higher than the maximum category of the arrays, | |
1823 the data types are combined with :func:`promote_types` | |
1824 to produce the return value. | |
1825 | |
1826 Otherwise, `min_scalar_type` is called on each array, and | |
1827 the resulting data types are all combined with :func:`promote_types` | |
1828 to produce the return value. | |
1829 | |
1830 The set of int values is not a subset of the uint values for types | |
1831 with the same number of bits, something not reflected in | |
1832 :func:`min_scalar_type`, but handled as a special case in `result_type`. | |
1833 | |
1834 Examples | |
1835 -------- | |
1836 >>> np.result_type(3, np.arange(7, dtype='i1')) | |
1837 dtype('int8') | |
1838 | |
1839 >>> np.result_type('i4', 'c8') | |
1840 dtype('complex128') | |
1841 | |
1842 >>> np.result_type(3.0, -2) | |
1843 dtype('float64') | |
1844 | |
1845 """) | |
1846 | |
1847 add_newdoc('numpy.core.multiarray', 'newbuffer', | |
1848 """ | |
1849 newbuffer(size) | |
1850 | |
1851 Return a new uninitialized buffer object. | |
1852 | |
1853 Parameters | |
1854 ---------- | |
1855 size : int | |
1856 Size in bytes of returned buffer object. | |
1857 | |
1858 Returns | |
1859 ------- | |
1860 newbuffer : buffer object | |
1861 Returned, uninitialized buffer object of `size` bytes. | |
1862 | |
1863 """) | |
1864 | |
1865 add_newdoc('numpy.core.multiarray', 'getbuffer', | |
1866 """ | |
1867 getbuffer(obj [,offset[, size]]) | |
1868 | |
1869 Create a buffer object from the given object referencing a slice of | |
1870 length size starting at offset. | |
1871 | |
1872 Default is the entire buffer. A read-write buffer is attempted followed | |
1873 by a read-only buffer. | |
1874 | |
1875 Parameters | |
1876 ---------- | |
1877 obj : object | |
1878 | |
1879 offset : int, optional | |
1880 | |
1881 size : int, optional | |
1882 | |
1883 Returns | |
1884 ------- | |
1885 buffer_obj : buffer | |
1886 | |
1887 Examples | |
1888 -------- | |
1889 >>> buf = np.getbuffer(np.ones(5), 1, 3) | |
1890 >>> len(buf) | |
1891 3 | |
1892 >>> buf[0] | |
1893 '\\x00' | |
1894 >>> buf | |
1895 <read-write buffer for 0x8af1e70, size 3, offset 1 at 0x8ba4ec0> | |
1896 | |
1897 """) | |
1898 | |
1899 add_newdoc('numpy.core', 'dot', | |
1900 """ | |
1901 dot(a, b, out=None) | |
1902 | |
1903 Dot product of two arrays. | |
1904 | |
1905 For 2-D arrays it is equivalent to matrix multiplication, and for 1-D | |
1906 arrays to inner product of vectors (without complex conjugation). For | |
1907 N dimensions it is a sum product over the last axis of `a` and | |
1908 the second-to-last of `b`:: | |
1909 | |
1910 dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m]) | |
1911 | |
1912 Parameters | |
1913 ---------- | |
1914 a : array_like | |
1915 First argument. | |
1916 b : array_like | |
1917 Second argument. | |
1918 out : ndarray, optional | |
1919 Output argument. This must have the exact kind that would be returned | |
1920 if it was not used. In particular, it must have the right type, must be | |
1921 C-contiguous, and its dtype must be the dtype that would be returned | |
1922 for `dot(a,b)`. This is a performance feature. Therefore, if these | |
1923 conditions are not met, an exception is raised, instead of attempting | |
1924 to be flexible. | |
1925 | |
1926 Returns | |
1927 ------- | |
1928 output : ndarray | |
1929 Returns the dot product of `a` and `b`. If `a` and `b` are both | |
1930 scalars or both 1-D arrays then a scalar is returned; otherwise | |
1931 an array is returned. | |
1932 If `out` is given, then it is returned. | |
1933 | |
1934 Raises | |
1935 ------ | |
1936 ValueError | |
1937 If the last dimension of `a` is not the same size as | |
1938 the second-to-last dimension of `b`. | |
1939 | |
1940 See Also | |
1941 -------- | |
1942 vdot : Complex-conjugating dot product. | |
1943 tensordot : Sum products over arbitrary axes. | |
1944 einsum : Einstein summation convention. | |
1945 | |
1946 Examples | |
1947 -------- | |
1948 >>> np.dot(3, 4) | |
1949 12 | |
1950 | |
1951 Neither argument is complex-conjugated: | |
1952 | |
1953 >>> np.dot([2j, 3j], [2j, 3j]) | |
1954 (-13+0j) | |
1955 | |
1956 For 2-D arrays it's the matrix product: | |
1957 | |
1958 >>> a = [[1, 0], [0, 1]] | |
1959 >>> b = [[4, 1], [2, 2]] | |
1960 >>> np.dot(a, b) | |
1961 array([[4, 1], | |
1962 [2, 2]]) | |
1963 | |
1964 >>> a = np.arange(3*4*5*6).reshape((3,4,5,6)) | |
1965 >>> b = np.arange(3*4*5*6)[::-1].reshape((5,4,6,3)) | |
1966 >>> np.dot(a, b)[2,3,2,1,2,2] | |
1967 499128 | |
1968 >>> sum(a[2,3,2,:] * b[1,2,:,2]) | |
1969 499128 | |
1970 | |
1971 """) | |
1972 | |
1973 add_newdoc('numpy.core', 'einsum', | |
1974 """ | |
1975 einsum(subscripts, *operands, out=None, dtype=None, order='K', casting='safe') | |
1976 | |
1977 Evaluates the Einstein summation convention on the operands. | |
1978 | |
1979 Using the Einstein summation convention, many common multi-dimensional | |
1980 array operations can be represented in a simple fashion. This function | |
1981 provides a way compute such summations. The best way to understand this | |
1982 function is to try the examples below, which show how many common NumPy | |
1983 functions can be implemented as calls to `einsum`. | |
1984 | |
1985 Parameters | |
1986 ---------- | |
1987 subscripts : str | |
1988 Specifies the subscripts for summation. | |
1989 operands : list of array_like | |
1990 These are the arrays for the operation. | |
1991 out : ndarray, optional | |
1992 If provided, the calculation is done into this array. | |
1993 dtype : data-type, optional | |
1994 If provided, forces the calculation to use the data type specified. | |
1995 Note that you may have to also give a more liberal `casting` | |
1996 parameter to allow the conversions. | |
1997 order : {'C', 'F', 'A', 'K'}, optional | |
1998 Controls the memory layout of the output. 'C' means it should | |
1999 be C contiguous. 'F' means it should be Fortran contiguous, | |
2000 'A' means it should be 'F' if the inputs are all 'F', 'C' otherwise. | |
2001 'K' means it should be as close to the layout as the inputs as | |
2002 is possible, including arbitrarily permuted axes. | |
2003 Default is 'K'. | |
2004 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional | |
2005 Controls what kind of data casting may occur. Setting this to | |
2006 'unsafe' is not recommended, as it can adversely affect accumulations. | |
2007 | |
2008 * 'no' means the data types should not be cast at all. | |
2009 * 'equiv' means only byte-order changes are allowed. | |
2010 * 'safe' means only casts which can preserve values are allowed. | |
2011 * 'same_kind' means only safe casts or casts within a kind, | |
2012 like float64 to float32, are allowed. | |
2013 * 'unsafe' means any data conversions may be done. | |
2014 | |
2015 Returns | |
2016 ------- | |
2017 output : ndarray | |
2018 The calculation based on the Einstein summation convention. | |
2019 | |
2020 See Also | |
2021 -------- | |
2022 dot, inner, outer, tensordot | |
2023 | |
2024 Notes | |
2025 ----- | |
2026 .. versionadded:: 1.6.0 | |
2027 | |
2028 The subscripts string is a comma-separated list of subscript labels, | |
2029 where each label refers to a dimension of the corresponding operand. | |
2030 Repeated subscripts labels in one operand take the diagonal. For example, | |
2031 ``np.einsum('ii', a)`` is equivalent to ``np.trace(a)``. | |
2032 | |
2033 Whenever a label is repeated, it is summed, so ``np.einsum('i,i', a, b)`` | |
2034 is equivalent to ``np.inner(a,b)``. If a label appears only once, | |
2035 it is not summed, so ``np.einsum('i', a)`` produces a view of ``a`` | |
2036 with no changes. | |
2037 | |
2038 The order of labels in the output is by default alphabetical. This | |
2039 means that ``np.einsum('ij', a)`` doesn't affect a 2D array, while | |
2040 ``np.einsum('ji', a)`` takes its transpose. | |
2041 | |
2042 The output can be controlled by specifying output subscript labels | |
2043 as well. This specifies the label order, and allows summing to | |
2044 be disallowed or forced when desired. The call ``np.einsum('i->', a)`` | |
2045 is like ``np.sum(a, axis=-1)``, and ``np.einsum('ii->i', a)`` | |
2046 is like ``np.diag(a)``. The difference is that `einsum` does not | |
2047 allow broadcasting by default. | |
2048 | |
2049 To enable and control broadcasting, use an ellipsis. Default | |
2050 NumPy-style broadcasting is done by adding an ellipsis | |
2051 to the left of each term, like ``np.einsum('...ii->...i', a)``. | |
2052 To take the trace along the first and last axes, | |
2053 you can do ``np.einsum('i...i', a)``, or to do a matrix-matrix | |
2054 product with the left-most indices instead of rightmost, you can do | |
2055 ``np.einsum('ij...,jk...->ik...', a, b)``. | |
2056 | |
2057 When there is only one operand, no axes are summed, and no output | |
2058 parameter is provided, a view into the operand is returned instead | |
2059 of a new array. Thus, taking the diagonal as ``np.einsum('ii->i', a)`` | |
2060 produces a view. | |
2061 | |
2062 An alternative way to provide the subscripts and operands is as | |
2063 ``einsum(op0, sublist0, op1, sublist1, ..., [sublistout])``. The examples | |
2064 below have corresponding `einsum` calls with the two parameter methods. | |
2065 | |
2066 Examples | |
2067 -------- | |
2068 >>> a = np.arange(25).reshape(5,5) | |
2069 >>> b = np.arange(5) | |
2070 >>> c = np.arange(6).reshape(2,3) | |
2071 | |
2072 >>> np.einsum('ii', a) | |
2073 60 | |
2074 >>> np.einsum(a, [0,0]) | |
2075 60 | |
2076 >>> np.trace(a) | |
2077 60 | |
2078 | |
2079 >>> np.einsum('ii->i', a) | |
2080 array([ 0, 6, 12, 18, 24]) | |
2081 >>> np.einsum(a, [0,0], [0]) | |
2082 array([ 0, 6, 12, 18, 24]) | |
2083 >>> np.diag(a) | |
2084 array([ 0, 6, 12, 18, 24]) | |
2085 | |
2086 >>> np.einsum('ij,j', a, b) | |
2087 array([ 30, 80, 130, 180, 230]) | |
2088 >>> np.einsum(a, [0,1], b, [1]) | |
2089 array([ 30, 80, 130, 180, 230]) | |
2090 >>> np.dot(a, b) | |
2091 array([ 30, 80, 130, 180, 230]) | |
2092 >>> np.einsum('...j,j', a, b) | |
2093 array([ 30, 80, 130, 180, 230]) | |
2094 | |
2095 >>> np.einsum('ji', c) | |
2096 array([[0, 3], | |
2097 [1, 4], | |
2098 [2, 5]]) | |
2099 >>> np.einsum(c, [1,0]) | |
2100 array([[0, 3], | |
2101 [1, 4], | |
2102 [2, 5]]) | |
2103 >>> c.T | |
2104 array([[0, 3], | |
2105 [1, 4], | |
2106 [2, 5]]) | |
2107 | |
2108 >>> np.einsum('..., ...', 3, c) | |
2109 array([[ 0, 3, 6], | |
2110 [ 9, 12, 15]]) | |
2111 >>> np.einsum(3, [Ellipsis], c, [Ellipsis]) | |
2112 array([[ 0, 3, 6], | |
2113 [ 9, 12, 15]]) | |
2114 >>> np.multiply(3, c) | |
2115 array([[ 0, 3, 6], | |
2116 [ 9, 12, 15]]) | |
2117 | |
2118 >>> np.einsum('i,i', b, b) | |
2119 30 | |
2120 >>> np.einsum(b, [0], b, [0]) | |
2121 30 | |
2122 >>> np.inner(b,b) | |
2123 30 | |
2124 | |
2125 >>> np.einsum('i,j', np.arange(2)+1, b) | |
2126 array([[0, 1, 2, 3, 4], | |
2127 [0, 2, 4, 6, 8]]) | |
2128 >>> np.einsum(np.arange(2)+1, [0], b, [1]) | |
2129 array([[0, 1, 2, 3, 4], | |
2130 [0, 2, 4, 6, 8]]) | |
2131 >>> np.outer(np.arange(2)+1, b) | |
2132 array([[0, 1, 2, 3, 4], | |
2133 [0, 2, 4, 6, 8]]) | |
2134 | |
2135 >>> np.einsum('i...->...', a) | |
2136 array([50, 55, 60, 65, 70]) | |
2137 >>> np.einsum(a, [0,Ellipsis], [Ellipsis]) | |
2138 array([50, 55, 60, 65, 70]) | |
2139 >>> np.sum(a, axis=0) | |
2140 array([50, 55, 60, 65, 70]) | |
2141 | |
2142 >>> a = np.arange(60.).reshape(3,4,5) | |
2143 >>> b = np.arange(24.).reshape(4,3,2) | |
2144 >>> np.einsum('ijk,jil->kl', a, b) | |
2145 array([[ 4400., 4730.], | |
2146 [ 4532., 4874.], | |
2147 [ 4664., 5018.], | |
2148 [ 4796., 5162.], | |
2149 [ 4928., 5306.]]) | |
2150 >>> np.einsum(a, [0,1,2], b, [1,0,3], [2,3]) | |
2151 array([[ 4400., 4730.], | |
2152 [ 4532., 4874.], | |
2153 [ 4664., 5018.], | |
2154 [ 4796., 5162.], | |
2155 [ 4928., 5306.]]) | |
2156 >>> np.tensordot(a,b, axes=([1,0],[0,1])) | |
2157 array([[ 4400., 4730.], | |
2158 [ 4532., 4874.], | |
2159 [ 4664., 5018.], | |
2160 [ 4796., 5162.], | |
2161 [ 4928., 5306.]]) | |
2162 | |
2163 >>> a = np.arange(6).reshape((3,2)) | |
2164 >>> b = np.arange(12).reshape((4,3)) | |
2165 >>> np.einsum('ki,jk->ij', a, b) | |
2166 array([[10, 28, 46, 64], | |
2167 [13, 40, 67, 94]]) | |
2168 >>> np.einsum('ki,...k->i...', a, b) | |
2169 array([[10, 28, 46, 64], | |
2170 [13, 40, 67, 94]]) | |
2171 >>> np.einsum('k...,jk', a, b) | |
2172 array([[10, 28, 46, 64], | |
2173 [13, 40, 67, 94]]) | |
2174 | |
2175 """) | |
2176 | |
2177 add_newdoc('numpy.core', 'alterdot', | |
2178 """ | |
2179 Change `dot`, `vdot`, and `inner` to use accelerated BLAS functions. | |
2180 | |
2181 Typically, as a user of Numpy, you do not explicitly call this function. If | |
2182 Numpy is built with an accelerated BLAS, this function is automatically | |
2183 called when Numpy is imported. | |
2184 | |
2185 When Numpy is built with an accelerated BLAS like ATLAS, these functions | |
2186 are replaced to make use of the faster implementations. The faster | |
2187 implementations only affect float32, float64, complex64, and complex128 | |
2188 arrays. Furthermore, the BLAS API only includes matrix-matrix, | |
2189 matrix-vector, and vector-vector products. Products of arrays with larger | |
2190 dimensionalities use the built in functions and are not accelerated. | |
2191 | |
2192 See Also | |
2193 -------- | |
2194 restoredot : `restoredot` undoes the effects of `alterdot`. | |
2195 | |
2196 """) | |
2197 | |
2198 add_newdoc('numpy.core', 'restoredot', | |
2199 """ | |
2200 Restore `dot`, `vdot`, and `innerproduct` to the default non-BLAS | |
2201 implementations. | |
2202 | |
2203 Typically, the user will only need to call this when troubleshooting and | |
2204 installation problem, reproducing the conditions of a build without an | |
2205 accelerated BLAS, or when being very careful about benchmarking linear | |
2206 algebra operations. | |
2207 | |
2208 See Also | |
2209 -------- | |
2210 alterdot : `restoredot` undoes the effects of `alterdot`. | |
2211 | |
2212 """) | |
2213 | |
2214 add_newdoc('numpy.core', 'vdot', | |
2215 """ | |
2216 vdot(a, b) | |
2217 | |
2218 Return the dot product of two vectors. | |
2219 | |
2220 The vdot(`a`, `b`) function handles complex numbers differently than | |
2221 dot(`a`, `b`). If the first argument is complex the complex conjugate | |
2222 of the first argument is used for the calculation of the dot product. | |
2223 | |
2224 Note that `vdot` handles multidimensional arrays differently than `dot`: | |
2225 it does *not* perform a matrix product, but flattens input arguments | |
2226 to 1-D vectors first. Consequently, it should only be used for vectors. | |
2227 | |
2228 Parameters | |
2229 ---------- | |
2230 a : array_like | |
2231 If `a` is complex the complex conjugate is taken before calculation | |
2232 of the dot product. | |
2233 b : array_like | |
2234 Second argument to the dot product. | |
2235 | |
2236 Returns | |
2237 ------- | |
2238 output : ndarray | |
2239 Dot product of `a` and `b`. Can be an int, float, or | |
2240 complex depending on the types of `a` and `b`. | |
2241 | |
2242 See Also | |
2243 -------- | |
2244 dot : Return the dot product without using the complex conjugate of the | |
2245 first argument. | |
2246 | |
2247 Examples | |
2248 -------- | |
2249 >>> a = np.array([1+2j,3+4j]) | |
2250 >>> b = np.array([5+6j,7+8j]) | |
2251 >>> np.vdot(a, b) | |
2252 (70-8j) | |
2253 >>> np.vdot(b, a) | |
2254 (70+8j) | |
2255 | |
2256 Note that higher-dimensional arrays are flattened! | |
2257 | |
2258 >>> a = np.array([[1, 4], [5, 6]]) | |
2259 >>> b = np.array([[4, 1], [2, 2]]) | |
2260 >>> np.vdot(a, b) | |
2261 30 | |
2262 >>> np.vdot(b, a) | |
2263 30 | |
2264 >>> 1*4 + 4*1 + 5*2 + 6*2 | |
2265 30 | |
2266 | |
2267 """) | |
2268 | |
2269 | |
2270 ############################################################################## | |
2271 # | |
2272 # Documentation for ndarray attributes and methods | |
2273 # | |
2274 ############################################################################## | |
2275 | |
2276 | |
2277 ############################################################################## | |
2278 # | |
2279 # ndarray object | |
2280 # | |
2281 ############################################################################## | |
2282 | |
2283 | |
2284 add_newdoc('numpy.core.multiarray', 'ndarray', | |
2285 """ | |
2286 ndarray(shape, dtype=float, buffer=None, offset=0, | |
2287 strides=None, order=None) | |
2288 | |
2289 An array object represents a multidimensional, homogeneous array | |
2290 of fixed-size items. An associated data-type object describes the | |
2291 format of each element in the array (its byte-order, how many bytes it | |
2292 occupies in memory, whether it is an integer, a floating point number, | |
2293 or something else, etc.) | |
2294 | |
2295 Arrays should be constructed using `array`, `zeros` or `empty` (refer | |
2296 to the See Also section below). The parameters given here refer to | |
2297 a low-level method (`ndarray(...)`) for instantiating an array. | |
2298 | |
2299 For more information, refer to the `numpy` module and examine the | |
2300 the methods and attributes of an array. | |
2301 | |
2302 Parameters | |
2303 ---------- | |
2304 (for the __new__ method; see Notes below) | |
2305 | |
2306 shape : tuple of ints | |
2307 Shape of created array. | |
2308 dtype : data-type, optional | |
2309 Any object that can be interpreted as a numpy data type. | |
2310 buffer : object exposing buffer interface, optional | |
2311 Used to fill the array with data. | |
2312 offset : int, optional | |
2313 Offset of array data in buffer. | |
2314 strides : tuple of ints, optional | |
2315 Strides of data in memory. | |
2316 order : {'C', 'F'}, optional | |
2317 Row-major or column-major order. | |
2318 | |
2319 Attributes | |
2320 ---------- | |
2321 T : ndarray | |
2322 Transpose of the array. | |
2323 data : buffer | |
2324 The array's elements, in memory. | |
2325 dtype : dtype object | |
2326 Describes the format of the elements in the array. | |
2327 flags : dict | |
2328 Dictionary containing information related to memory use, e.g., | |
2329 'C_CONTIGUOUS', 'OWNDATA', 'WRITEABLE', etc. | |
2330 flat : numpy.flatiter object | |
2331 Flattened version of the array as an iterator. The iterator | |
2332 allows assignments, e.g., ``x.flat = 3`` (See `ndarray.flat` for | |
2333 assignment examples; TODO). | |
2334 imag : ndarray | |
2335 Imaginary part of the array. | |
2336 real : ndarray | |
2337 Real part of the array. | |
2338 size : int | |
2339 Number of elements in the array. | |
2340 itemsize : int | |
2341 The memory use of each array element in bytes. | |
2342 nbytes : int | |
2343 The total number of bytes required to store the array data, | |
2344 i.e., ``itemsize * size``. | |
2345 ndim : int | |
2346 The array's number of dimensions. | |
2347 shape : tuple of ints | |
2348 Shape of the array. | |
2349 strides : tuple of ints | |
2350 The step-size required to move from one element to the next in | |
2351 memory. For example, a contiguous ``(3, 4)`` array of type | |
2352 ``int16`` in C-order has strides ``(8, 2)``. This implies that | |
2353 to move from element to element in memory requires jumps of 2 bytes. | |
2354 To move from row-to-row, one needs to jump 8 bytes at a time | |
2355 (``2 * 4``). | |
2356 ctypes : ctypes object | |
2357 Class containing properties of the array needed for interaction | |
2358 with ctypes. | |
2359 base : ndarray | |
2360 If the array is a view into another array, that array is its `base` | |
2361 (unless that array is also a view). The `base` array is where the | |
2362 array data is actually stored. | |
2363 | |
2364 See Also | |
2365 -------- | |
2366 array : Construct an array. | |
2367 zeros : Create an array, each element of which is zero. | |
2368 empty : Create an array, but leave its allocated memory unchanged (i.e., | |
2369 it contains "garbage"). | |
2370 dtype : Create a data-type. | |
2371 | |
2372 Notes | |
2373 ----- | |
2374 There are two modes of creating an array using ``__new__``: | |
2375 | |
2376 1. If `buffer` is None, then only `shape`, `dtype`, and `order` | |
2377 are used. | |
2378 2. If `buffer` is an object exposing the buffer interface, then | |
2379 all keywords are interpreted. | |
2380 | |
2381 No ``__init__`` method is needed because the array is fully initialized | |
2382 after the ``__new__`` method. | |
2383 | |
2384 Examples | |
2385 -------- | |
2386 These examples illustrate the low-level `ndarray` constructor. Refer | |
2387 to the `See Also` section above for easier ways of constructing an | |
2388 ndarray. | |
2389 | |
2390 First mode, `buffer` is None: | |
2391 | |
2392 >>> np.ndarray(shape=(2,2), dtype=float, order='F') | |
2393 array([[ -1.13698227e+002, 4.25087011e-303], | |
2394 [ 2.88528414e-306, 3.27025015e-309]]) #random | |
2395 | |
2396 Second mode: | |
2397 | |
2398 >>> np.ndarray((2,), buffer=np.array([1,2,3]), | |
2399 ... offset=np.int_().itemsize, | |
2400 ... dtype=int) # offset = 1*itemsize, i.e. skip first element | |
2401 array([2, 3]) | |
2402 | |
2403 """) | |
2404 | |
2405 | |
2406 ############################################################################## | |
2407 # | |
2408 # ndarray attributes | |
2409 # | |
2410 ############################################################################## | |
2411 | |
2412 | |
2413 add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_interface__', | |
2414 """Array protocol: Python side.""")) | |
2415 | |
2416 | |
2417 add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_finalize__', | |
2418 """None.""")) | |
2419 | |
2420 | |
2421 add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_priority__', | |
2422 """Array priority.""")) | |
2423 | |
2424 | |
2425 add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_struct__', | |
2426 """Array protocol: C-struct side.""")) | |
2427 | |
2428 | |
2429 add_newdoc('numpy.core.multiarray', 'ndarray', ('_as_parameter_', | |
2430 """Allow the array to be interpreted as a ctypes object by returning the | |
2431 data-memory location as an integer | |
2432 | |
2433 """)) | |
2434 | |
2435 | |
2436 add_newdoc('numpy.core.multiarray', 'ndarray', ('base', | |
2437 """ | |
2438 Base object if memory is from some other object. | |
2439 | |
2440 Examples | |
2441 -------- | |
2442 The base of an array that owns its memory is None: | |
2443 | |
2444 >>> x = np.array([1,2,3,4]) | |
2445 >>> x.base is None | |
2446 True | |
2447 | |
2448 Slicing creates a view, whose memory is shared with x: | |
2449 | |
2450 >>> y = x[2:] | |
2451 >>> y.base is x | |
2452 True | |
2453 | |
2454 """)) | |
2455 | |
2456 | |
2457 add_newdoc('numpy.core.multiarray', 'ndarray', ('ctypes', | |
2458 """ | |
2459 An object to simplify the interaction of the array with the ctypes | |
2460 module. | |
2461 | |
2462 This attribute creates an object that makes it easier to use arrays | |
2463 when calling shared libraries with the ctypes module. The returned | |
2464 object has, among others, data, shape, and strides attributes (see | |
2465 Notes below) which themselves return ctypes objects that can be used | |
2466 as arguments to a shared library. | |
2467 | |
2468 Parameters | |
2469 ---------- | |
2470 None | |
2471 | |
2472 Returns | |
2473 ------- | |
2474 c : Python object | |
2475 Possessing attributes data, shape, strides, etc. | |
2476 | |
2477 See Also | |
2478 -------- | |
2479 numpy.ctypeslib | |
2480 | |
2481 Notes | |
2482 ----- | |
2483 Below are the public attributes of this object which were documented | |
2484 in "Guide to NumPy" (we have omitted undocumented public attributes, | |
2485 as well as documented private attributes): | |
2486 | |
2487 * data: A pointer to the memory area of the array as a Python integer. | |
2488 This memory area may contain data that is not aligned, or not in correct | |
2489 byte-order. The memory area may not even be writeable. The array | |
2490 flags and data-type of this array should be respected when passing this | |
2491 attribute to arbitrary C-code to avoid trouble that can include Python | |
2492 crashing. User Beware! The value of this attribute is exactly the same | |
2493 as self._array_interface_['data'][0]. | |
2494 | |
2495 * shape (c_intp*self.ndim): A ctypes array of length self.ndim where | |
2496 the basetype is the C-integer corresponding to dtype('p') on this | |
2497 platform. This base-type could be c_int, c_long, or c_longlong | |
2498 depending on the platform. The c_intp type is defined accordingly in | |
2499 numpy.ctypeslib. The ctypes array contains the shape of the underlying | |
2500 array. | |
2501 | |
2502 * strides (c_intp*self.ndim): A ctypes array of length self.ndim where | |
2503 the basetype is the same as for the shape attribute. This ctypes array | |
2504 contains the strides information from the underlying array. This strides | |
2505 information is important for showing how many bytes must be jumped to | |
2506 get to the next element in the array. | |
2507 | |
2508 * data_as(obj): Return the data pointer cast to a particular c-types object. | |
2509 For example, calling self._as_parameter_ is equivalent to | |
2510 self.data_as(ctypes.c_void_p). Perhaps you want to use the data as a | |
2511 pointer to a ctypes array of floating-point data: | |
2512 self.data_as(ctypes.POINTER(ctypes.c_double)). | |
2513 | |
2514 * shape_as(obj): Return the shape tuple as an array of some other c-types | |
2515 type. For example: self.shape_as(ctypes.c_short). | |
2516 | |
2517 * strides_as(obj): Return the strides tuple as an array of some other | |
2518 c-types type. For example: self.strides_as(ctypes.c_longlong). | |
2519 | |
2520 Be careful using the ctypes attribute - especially on temporary | |
2521 arrays or arrays constructed on the fly. For example, calling | |
2522 ``(a+b).ctypes.data_as(ctypes.c_void_p)`` returns a pointer to memory | |
2523 that is invalid because the array created as (a+b) is deallocated | |
2524 before the next Python statement. You can avoid this problem using | |
2525 either ``c=a+b`` or ``ct=(a+b).ctypes``. In the latter case, ct will | |
2526 hold a reference to the array until ct is deleted or re-assigned. | |
2527 | |
2528 If the ctypes module is not available, then the ctypes attribute | |
2529 of array objects still returns something useful, but ctypes objects | |
2530 are not returned and errors may be raised instead. In particular, | |
2531 the object will still have the as parameter attribute which will | |
2532 return an integer equal to the data attribute. | |
2533 | |
2534 Examples | |
2535 -------- | |
2536 >>> import ctypes | |
2537 >>> x | |
2538 array([[0, 1], | |
2539 [2, 3]]) | |
2540 >>> x.ctypes.data | |
2541 30439712 | |
2542 >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_long)) | |
2543 <ctypes.LP_c_long object at 0x01F01300> | |
2544 >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_long)).contents | |
2545 c_long(0) | |
2546 >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_longlong)).contents | |
2547 c_longlong(4294967296L) | |
2548 >>> x.ctypes.shape | |
2549 <numpy.core._internal.c_long_Array_2 object at 0x01FFD580> | |
2550 >>> x.ctypes.shape_as(ctypes.c_long) | |
2551 <numpy.core._internal.c_long_Array_2 object at 0x01FCE620> | |
2552 >>> x.ctypes.strides | |
2553 <numpy.core._internal.c_long_Array_2 object at 0x01FCE620> | |
2554 >>> x.ctypes.strides_as(ctypes.c_longlong) | |
2555 <numpy.core._internal.c_longlong_Array_2 object at 0x01F01300> | |
2556 | |
2557 """)) | |
2558 | |
2559 | |
2560 add_newdoc('numpy.core.multiarray', 'ndarray', ('data', | |
2561 """Python buffer object pointing to the start of the array's data.""")) | |
2562 | |
2563 | |
2564 add_newdoc('numpy.core.multiarray', 'ndarray', ('dtype', | |
2565 """ | |
2566 Data-type of the array's elements. | |
2567 | |
2568 Parameters | |
2569 ---------- | |
2570 None | |
2571 | |
2572 Returns | |
2573 ------- | |
2574 d : numpy dtype object | |
2575 | |
2576 See Also | |
2577 -------- | |
2578 numpy.dtype | |
2579 | |
2580 Examples | |
2581 -------- | |
2582 >>> x | |
2583 array([[0, 1], | |
2584 [2, 3]]) | |
2585 >>> x.dtype | |
2586 dtype('int32') | |
2587 >>> type(x.dtype) | |
2588 <type 'numpy.dtype'> | |
2589 | |
2590 """)) | |
2591 | |
2592 | |
2593 add_newdoc('numpy.core.multiarray', 'ndarray', ('imag', | |
2594 """ | |
2595 The imaginary part of the array. | |
2596 | |
2597 Examples | |
2598 -------- | |
2599 >>> x = np.sqrt([1+0j, 0+1j]) | |
2600 >>> x.imag | |
2601 array([ 0. , 0.70710678]) | |
2602 >>> x.imag.dtype | |
2603 dtype('float64') | |
2604 | |
2605 """)) | |
2606 | |
2607 | |
2608 add_newdoc('numpy.core.multiarray', 'ndarray', ('itemsize', | |
2609 """ | |
2610 Length of one array element in bytes. | |
2611 | |
2612 Examples | |
2613 -------- | |
2614 >>> x = np.array([1,2,3], dtype=np.float64) | |
2615 >>> x.itemsize | |
2616 8 | |
2617 >>> x = np.array([1,2,3], dtype=np.complex128) | |
2618 >>> x.itemsize | |
2619 16 | |
2620 | |
2621 """)) | |
2622 | |
2623 | |
2624 add_newdoc('numpy.core.multiarray', 'ndarray', ('flags', | |
2625 """ | |
2626 Information about the memory layout of the array. | |
2627 | |
2628 Attributes | |
2629 ---------- | |
2630 C_CONTIGUOUS (C) | |
2631 The data is in a single, C-style contiguous segment. | |
2632 F_CONTIGUOUS (F) | |
2633 The data is in a single, Fortran-style contiguous segment. | |
2634 OWNDATA (O) | |
2635 The array owns the memory it uses or borrows it from another object. | |
2636 WRITEABLE (W) | |
2637 The data area can be written to. Setting this to False locks | |
2638 the data, making it read-only. A view (slice, etc.) inherits WRITEABLE | |
2639 from its base array at creation time, but a view of a writeable | |
2640 array may be subsequently locked while the base array remains writeable. | |
2641 (The opposite is not true, in that a view of a locked array may not | |
2642 be made writeable. However, currently, locking a base object does not | |
2643 lock any views that already reference it, so under that circumstance it | |
2644 is possible to alter the contents of a locked array via a previously | |
2645 created writeable view onto it.) Attempting to change a non-writeable | |
2646 array raises a RuntimeError exception. | |
2647 ALIGNED (A) | |
2648 The data and all elements are aligned appropriately for the hardware. | |
2649 UPDATEIFCOPY (U) | |
2650 This array is a copy of some other array. When this array is | |
2651 deallocated, the base array will be updated with the contents of | |
2652 this array. | |
2653 FNC | |
2654 F_CONTIGUOUS and not C_CONTIGUOUS. | |
2655 FORC | |
2656 F_CONTIGUOUS or C_CONTIGUOUS (one-segment test). | |
2657 BEHAVED (B) | |
2658 ALIGNED and WRITEABLE. | |
2659 CARRAY (CA) | |
2660 BEHAVED and C_CONTIGUOUS. | |
2661 FARRAY (FA) | |
2662 BEHAVED and F_CONTIGUOUS and not C_CONTIGUOUS. | |
2663 | |
2664 Notes | |
2665 ----- | |
2666 The `flags` object can be accessed dictionary-like (as in ``a.flags['WRITEABLE']``), | |
2667 or by using lowercased attribute names (as in ``a.flags.writeable``). Short flag | |
2668 names are only supported in dictionary access. | |
2669 | |
2670 Only the UPDATEIFCOPY, WRITEABLE, and ALIGNED flags can be changed by | |
2671 the user, via direct assignment to the attribute or dictionary entry, | |
2672 or by calling `ndarray.setflags`. | |
2673 | |
2674 The array flags cannot be set arbitrarily: | |
2675 | |
2676 - UPDATEIFCOPY can only be set ``False``. | |
2677 - ALIGNED can only be set ``True`` if the data is truly aligned. | |
2678 - WRITEABLE can only be set ``True`` if the array owns its own memory | |
2679 or the ultimate owner of the memory exposes a writeable buffer | |
2680 interface or is a string. | |
2681 | |
2682 Arrays can be both C-style and Fortran-style contiguous simultaneously. | |
2683 This is clear for 1-dimensional arrays, but can also be true for higher | |
2684 dimensional arrays. | |
2685 | |
2686 Even for contiguous arrays a stride for a given dimension | |
2687 ``arr.strides[dim]`` may be *arbitrary* if ``arr.shape[dim] == 1`` | |
2688 or the array has no elements. | |
2689 It does *not* generally hold that ``self.strides[-1] == self.itemsize`` | |
2690 for C-style contiguous arrays or ``self.strides[0] == self.itemsize`` for | |
2691 Fortran-style contiguous arrays is true. | |
2692 """)) | |
2693 | |
2694 | |
2695 add_newdoc('numpy.core.multiarray', 'ndarray', ('flat', | |
2696 """ | |
2697 A 1-D iterator over the array. | |
2698 | |
2699 This is a `numpy.flatiter` instance, which acts similarly to, but is not | |
2700 a subclass of, Python's built-in iterator object. | |
2701 | |
2702 See Also | |
2703 -------- | |
2704 flatten : Return a copy of the array collapsed into one dimension. | |
2705 | |
2706 flatiter | |
2707 | |
2708 Examples | |
2709 -------- | |
2710 >>> x = np.arange(1, 7).reshape(2, 3) | |
2711 >>> x | |
2712 array([[1, 2, 3], | |
2713 [4, 5, 6]]) | |
2714 >>> x.flat[3] | |
2715 4 | |
2716 >>> x.T | |
2717 array([[1, 4], | |
2718 [2, 5], | |
2719 [3, 6]]) | |
2720 >>> x.T.flat[3] | |
2721 5 | |
2722 >>> type(x.flat) | |
2723 <type 'numpy.flatiter'> | |
2724 | |
2725 An assignment example: | |
2726 | |
2727 >>> x.flat = 3; x | |
2728 array([[3, 3, 3], | |
2729 [3, 3, 3]]) | |
2730 >>> x.flat[[1,4]] = 1; x | |
2731 array([[3, 1, 3], | |
2732 [3, 1, 3]]) | |
2733 | |
2734 """)) | |
2735 | |
2736 | |
2737 add_newdoc('numpy.core.multiarray', 'ndarray', ('nbytes', | |
2738 """ | |
2739 Total bytes consumed by the elements of the array. | |
2740 | |
2741 Notes | |
2742 ----- | |
2743 Does not include memory consumed by non-element attributes of the | |
2744 array object. | |
2745 | |
2746 Examples | |
2747 -------- | |
2748 >>> x = np.zeros((3,5,2), dtype=np.complex128) | |
2749 >>> x.nbytes | |
2750 480 | |
2751 >>> np.prod(x.shape) * x.itemsize | |
2752 480 | |
2753 | |
2754 """)) | |
2755 | |
2756 | |
2757 add_newdoc('numpy.core.multiarray', 'ndarray', ('ndim', | |
2758 """ | |
2759 Number of array dimensions. | |
2760 | |
2761 Examples | |
2762 -------- | |
2763 >>> x = np.array([1, 2, 3]) | |
2764 >>> x.ndim | |
2765 1 | |
2766 >>> y = np.zeros((2, 3, 4)) | |
2767 >>> y.ndim | |
2768 3 | |
2769 | |
2770 """)) | |
2771 | |
2772 | |
2773 add_newdoc('numpy.core.multiarray', 'ndarray', ('real', | |
2774 """ | |
2775 The real part of the array. | |
2776 | |
2777 Examples | |
2778 -------- | |
2779 >>> x = np.sqrt([1+0j, 0+1j]) | |
2780 >>> x.real | |
2781 array([ 1. , 0.70710678]) | |
2782 >>> x.real.dtype | |
2783 dtype('float64') | |
2784 | |
2785 See Also | |
2786 -------- | |
2787 numpy.real : equivalent function | |
2788 | |
2789 """)) | |
2790 | |
2791 | |
2792 add_newdoc('numpy.core.multiarray', 'ndarray', ('shape', | |
2793 """ | |
2794 Tuple of array dimensions. | |
2795 | |
2796 Notes | |
2797 ----- | |
2798 May be used to "reshape" the array, as long as this would not | |
2799 require a change in the total number of elements | |
2800 | |
2801 Examples | |
2802 -------- | |
2803 >>> x = np.array([1, 2, 3, 4]) | |
2804 >>> x.shape | |
2805 (4,) | |
2806 >>> y = np.zeros((2, 3, 4)) | |
2807 >>> y.shape | |
2808 (2, 3, 4) | |
2809 >>> y.shape = (3, 8) | |
2810 >>> y | |
2811 array([[ 0., 0., 0., 0., 0., 0., 0., 0.], | |
2812 [ 0., 0., 0., 0., 0., 0., 0., 0.], | |
2813 [ 0., 0., 0., 0., 0., 0., 0., 0.]]) | |
2814 >>> y.shape = (3, 6) | |
2815 Traceback (most recent call last): | |
2816 File "<stdin>", line 1, in <module> | |
2817 ValueError: total size of new array must be unchanged | |
2818 | |
2819 """)) | |
2820 | |
2821 | |
2822 add_newdoc('numpy.core.multiarray', 'ndarray', ('size', | |
2823 """ | |
2824 Number of elements in the array. | |
2825 | |
2826 Equivalent to ``np.prod(a.shape)``, i.e., the product of the array's | |
2827 dimensions. | |
2828 | |
2829 Examples | |
2830 -------- | |
2831 >>> x = np.zeros((3, 5, 2), dtype=np.complex128) | |
2832 >>> x.size | |
2833 30 | |
2834 >>> np.prod(x.shape) | |
2835 30 | |
2836 | |
2837 """)) | |
2838 | |
2839 | |
2840 add_newdoc('numpy.core.multiarray', 'ndarray', ('strides', | |
2841 """ | |
2842 Tuple of bytes to step in each dimension when traversing an array. | |
2843 | |
2844 The byte offset of element ``(i[0], i[1], ..., i[n])`` in an array `a` | |
2845 is:: | |
2846 | |
2847 offset = sum(np.array(i) * a.strides) | |
2848 | |
2849 A more detailed explanation of strides can be found in the | |
2850 "ndarray.rst" file in the NumPy reference guide. | |
2851 | |
2852 Notes | |
2853 ----- | |
2854 Imagine an array of 32-bit integers (each 4 bytes):: | |
2855 | |
2856 x = np.array([[0, 1, 2, 3, 4], | |
2857 [5, 6, 7, 8, 9]], dtype=np.int32) | |
2858 | |
2859 This array is stored in memory as 40 bytes, one after the other | |
2860 (known as a contiguous block of memory). The strides of an array tell | |
2861 us how many bytes we have to skip in memory to move to the next position | |
2862 along a certain axis. For example, we have to skip 4 bytes (1 value) to | |
2863 move to the next column, but 20 bytes (5 values) to get to the same | |
2864 position in the next row. As such, the strides for the array `x` will be | |
2865 ``(20, 4)``. | |
2866 | |
2867 See Also | |
2868 -------- | |
2869 numpy.lib.stride_tricks.as_strided | |
2870 | |
2871 Examples | |
2872 -------- | |
2873 >>> y = np.reshape(np.arange(2*3*4), (2,3,4)) | |
2874 >>> y | |
2875 array([[[ 0, 1, 2, 3], | |
2876 [ 4, 5, 6, 7], | |
2877 [ 8, 9, 10, 11]], | |
2878 [[12, 13, 14, 15], | |
2879 [16, 17, 18, 19], | |
2880 [20, 21, 22, 23]]]) | |
2881 >>> y.strides | |
2882 (48, 16, 4) | |
2883 >>> y[1,1,1] | |
2884 17 | |
2885 >>> offset=sum(y.strides * np.array((1,1,1))) | |
2886 >>> offset/y.itemsize | |
2887 17 | |
2888 | |
2889 >>> x = np.reshape(np.arange(5*6*7*8), (5,6,7,8)).transpose(2,3,1,0) | |
2890 >>> x.strides | |
2891 (32, 4, 224, 1344) | |
2892 >>> i = np.array([3,5,2,2]) | |
2893 >>> offset = sum(i * x.strides) | |
2894 >>> x[3,5,2,2] | |
2895 813 | |
2896 >>> offset / x.itemsize | |
2897 813 | |
2898 | |
2899 """)) | |
2900 | |
2901 | |
2902 add_newdoc('numpy.core.multiarray', 'ndarray', ('T', | |
2903 """ | |
2904 Same as self.transpose(), except that self is returned if | |
2905 self.ndim < 2. | |
2906 | |
2907 Examples | |
2908 -------- | |
2909 >>> x = np.array([[1.,2.],[3.,4.]]) | |
2910 >>> x | |
2911 array([[ 1., 2.], | |
2912 [ 3., 4.]]) | |
2913 >>> x.T | |
2914 array([[ 1., 3.], | |
2915 [ 2., 4.]]) | |
2916 >>> x = np.array([1.,2.,3.,4.]) | |
2917 >>> x | |
2918 array([ 1., 2., 3., 4.]) | |
2919 >>> x.T | |
2920 array([ 1., 2., 3., 4.]) | |
2921 | |
2922 """)) | |
2923 | |
2924 | |
2925 ############################################################################## | |
2926 # | |
2927 # ndarray methods | |
2928 # | |
2929 ############################################################################## | |
2930 | |
2931 | |
2932 add_newdoc('numpy.core.multiarray', 'ndarray', ('__array__', | |
2933 """ a.__array__(|dtype) -> reference if type unchanged, copy otherwise. | |
2934 | |
2935 Returns either a new reference to self if dtype is not given or a new array | |
2936 of provided data type if dtype is different from the current dtype of the | |
2937 array. | |
2938 | |
2939 """)) | |
2940 | |
2941 | |
2942 add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_prepare__', | |
2943 """a.__array_prepare__(obj) -> Object of same type as ndarray object obj. | |
2944 | |
2945 """)) | |
2946 | |
2947 | |
2948 add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_wrap__', | |
2949 """a.__array_wrap__(obj) -> Object of same type as ndarray object a. | |
2950 | |
2951 """)) | |
2952 | |
2953 | |
2954 add_newdoc('numpy.core.multiarray', 'ndarray', ('__copy__', | |
2955 """a.__copy__([order]) | |
2956 | |
2957 Return a copy of the array. | |
2958 | |
2959 Parameters | |
2960 ---------- | |
2961 order : {'C', 'F', 'A'}, optional | |
2962 If order is 'C' (False) then the result is contiguous (default). | |
2963 If order is 'Fortran' (True) then the result has fortran order. | |
2964 If order is 'Any' (None) then the result has fortran order | |
2965 only if the array already is in fortran order. | |
2966 | |
2967 """)) | |
2968 | |
2969 | |
2970 add_newdoc('numpy.core.multiarray', 'ndarray', ('__deepcopy__', | |
2971 """a.__deepcopy__() -> Deep copy of array. | |
2972 | |
2973 Used if copy.deepcopy is called on an array. | |
2974 | |
2975 """)) | |
2976 | |
2977 | |
2978 add_newdoc('numpy.core.multiarray', 'ndarray', ('__reduce__', | |
2979 """a.__reduce__() | |
2980 | |
2981 For pickling. | |
2982 | |
2983 """)) | |
2984 | |
2985 | |
2986 add_newdoc('numpy.core.multiarray', 'ndarray', ('__setstate__', | |
2987 """a.__setstate__(version, shape, dtype, isfortran, rawdata) | |
2988 | |
2989 For unpickling. | |
2990 | |
2991 Parameters | |
2992 ---------- | |
2993 version : int | |
2994 optional pickle version. If omitted defaults to 0. | |
2995 shape : tuple | |
2996 dtype : data-type | |
2997 isFortran : bool | |
2998 rawdata : string or list | |
2999 a binary string with the data (or a list if 'a' is an object array) | |
3000 | |
3001 """)) | |
3002 | |
3003 | |
3004 add_newdoc('numpy.core.multiarray', 'ndarray', ('all', | |
3005 """ | |
3006 a.all(axis=None, out=None) | |
3007 | |
3008 Returns True if all elements evaluate to True. | |
3009 | |
3010 Refer to `numpy.all` for full documentation. | |
3011 | |
3012 See Also | |
3013 -------- | |
3014 numpy.all : equivalent function | |
3015 | |
3016 """)) | |
3017 | |
3018 | |
3019 add_newdoc('numpy.core.multiarray', 'ndarray', ('any', | |
3020 """ | |
3021 a.any(axis=None, out=None) | |
3022 | |
3023 Returns True if any of the elements of `a` evaluate to True. | |
3024 | |
3025 Refer to `numpy.any` for full documentation. | |
3026 | |
3027 See Also | |
3028 -------- | |
3029 numpy.any : equivalent function | |
3030 | |
3031 """)) | |
3032 | |
3033 | |
3034 add_newdoc('numpy.core.multiarray', 'ndarray', ('argmax', | |
3035 """ | |
3036 a.argmax(axis=None, out=None) | |
3037 | |
3038 Return indices of the maximum values along the given axis. | |
3039 | |
3040 Refer to `numpy.argmax` for full documentation. | |
3041 | |
3042 See Also | |
3043 -------- | |
3044 numpy.argmax : equivalent function | |
3045 | |
3046 """)) | |
3047 | |
3048 | |
3049 add_newdoc('numpy.core.multiarray', 'ndarray', ('argmin', | |
3050 """ | |
3051 a.argmin(axis=None, out=None) | |
3052 | |
3053 Return indices of the minimum values along the given axis of `a`. | |
3054 | |
3055 Refer to `numpy.argmin` for detailed documentation. | |
3056 | |
3057 See Also | |
3058 -------- | |
3059 numpy.argmin : equivalent function | |
3060 | |
3061 """)) | |
3062 | |
3063 | |
3064 add_newdoc('numpy.core.multiarray', 'ndarray', ('argsort', | |
3065 """ | |
3066 a.argsort(axis=-1, kind='quicksort', order=None) | |
3067 | |
3068 Returns the indices that would sort this array. | |
3069 | |
3070 Refer to `numpy.argsort` for full documentation. | |
3071 | |
3072 See Also | |
3073 -------- | |
3074 numpy.argsort : equivalent function | |
3075 | |
3076 """)) | |
3077 | |
3078 | |
3079 add_newdoc('numpy.core.multiarray', 'ndarray', ('argpartition', | |
3080 """ | |
3081 a.argpartition(kth, axis=-1, kind='introselect', order=None) | |
3082 | |
3083 Returns the indices that would partition this array. | |
3084 | |
3085 Refer to `numpy.argpartition` for full documentation. | |
3086 | |
3087 .. versionadded:: 1.8.0 | |
3088 | |
3089 See Also | |
3090 -------- | |
3091 numpy.argpartition : equivalent function | |
3092 | |
3093 """)) | |
3094 | |
3095 | |
3096 add_newdoc('numpy.core.multiarray', 'ndarray', ('astype', | |
3097 """ | |
3098 a.astype(dtype, order='K', casting='unsafe', subok=True, copy=True) | |
3099 | |
3100 Copy of the array, cast to a specified type. | |
3101 | |
3102 Parameters | |
3103 ---------- | |
3104 dtype : str or dtype | |
3105 Typecode or data-type to which the array is cast. | |
3106 order : {'C', 'F', 'A', 'K'}, optional | |
3107 Controls the memory layout order of the result. | |
3108 'C' means C order, 'F' means Fortran order, 'A' | |
3109 means 'F' order if all the arrays are Fortran contiguous, | |
3110 'C' order otherwise, and 'K' means as close to the | |
3111 order the array elements appear in memory as possible. | |
3112 Default is 'K'. | |
3113 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional | |
3114 Controls what kind of data casting may occur. Defaults to 'unsafe' | |
3115 for backwards compatibility. | |
3116 | |
3117 * 'no' means the data types should not be cast at all. | |
3118 * 'equiv' means only byte-order changes are allowed. | |
3119 * 'safe' means only casts which can preserve values are allowed. | |
3120 * 'same_kind' means only safe casts or casts within a kind, | |
3121 like float64 to float32, are allowed. | |
3122 * 'unsafe' means any data conversions may be done. | |
3123 subok : bool, optional | |
3124 If True, then sub-classes will be passed-through (default), otherwise | |
3125 the returned array will be forced to be a base-class array. | |
3126 copy : bool, optional | |
3127 By default, astype always returns a newly allocated array. If this | |
3128 is set to false, and the `dtype`, `order`, and `subok` | |
3129 requirements are satisfied, the input array is returned instead | |
3130 of a copy. | |
3131 | |
3132 Returns | |
3133 ------- | |
3134 arr_t : ndarray | |
3135 Unless `copy` is False and the other conditions for returning the input | |
3136 array are satisfied (see description for `copy` input paramter), `arr_t` | |
3137 is a new array of the same shape as the input array, with dtype, order | |
3138 given by `dtype`, `order`. | |
3139 | |
3140 Notes | |
3141 ----- | |
3142 Starting in NumPy 1.9, astype method now returns an error if the string | |
3143 dtype to cast to is not long enough in 'safe' casting mode to hold the max | |
3144 value of integer/float array that is being casted. Previously the casting | |
3145 was allowed even if the result was truncated. | |
3146 | |
3147 Raises | |
3148 ------ | |
3149 ComplexWarning | |
3150 When casting from complex to float or int. To avoid this, | |
3151 one should use ``a.real.astype(t)``. | |
3152 | |
3153 Examples | |
3154 -------- | |
3155 >>> x = np.array([1, 2, 2.5]) | |
3156 >>> x | |
3157 array([ 1. , 2. , 2.5]) | |
3158 | |
3159 >>> x.astype(int) | |
3160 array([1, 2, 2]) | |
3161 | |
3162 """)) | |
3163 | |
3164 | |
3165 add_newdoc('numpy.core.multiarray', 'ndarray', ('byteswap', | |
3166 """ | |
3167 a.byteswap(inplace) | |
3168 | |
3169 Swap the bytes of the array elements | |
3170 | |
3171 Toggle between low-endian and big-endian data representation by | |
3172 returning a byteswapped array, optionally swapped in-place. | |
3173 | |
3174 Parameters | |
3175 ---------- | |
3176 inplace : bool, optional | |
3177 If ``True``, swap bytes in-place, default is ``False``. | |
3178 | |
3179 Returns | |
3180 ------- | |
3181 out : ndarray | |
3182 The byteswapped array. If `inplace` is ``True``, this is | |
3183 a view to self. | |
3184 | |
3185 Examples | |
3186 -------- | |
3187 >>> A = np.array([1, 256, 8755], dtype=np.int16) | |
3188 >>> map(hex, A) | |
3189 ['0x1', '0x100', '0x2233'] | |
3190 >>> A.byteswap(True) | |
3191 array([ 256, 1, 13090], dtype=int16) | |
3192 >>> map(hex, A) | |
3193 ['0x100', '0x1', '0x3322'] | |
3194 | |
3195 Arrays of strings are not swapped | |
3196 | |
3197 >>> A = np.array(['ceg', 'fac']) | |
3198 >>> A.byteswap() | |
3199 array(['ceg', 'fac'], | |
3200 dtype='|S3') | |
3201 | |
3202 """)) | |
3203 | |
3204 | |
3205 add_newdoc('numpy.core.multiarray', 'ndarray', ('choose', | |
3206 """ | |
3207 a.choose(choices, out=None, mode='raise') | |
3208 | |
3209 Use an index array to construct a new array from a set of choices. | |
3210 | |
3211 Refer to `numpy.choose` for full documentation. | |
3212 | |
3213 See Also | |
3214 -------- | |
3215 numpy.choose : equivalent function | |
3216 | |
3217 """)) | |
3218 | |
3219 | |
3220 add_newdoc('numpy.core.multiarray', 'ndarray', ('clip', | |
3221 """ | |
3222 a.clip(a_min, a_max, out=None) | |
3223 | |
3224 Return an array whose values are limited to ``[a_min, a_max]``. | |
3225 | |
3226 Refer to `numpy.clip` for full documentation. | |
3227 | |
3228 See Also | |
3229 -------- | |
3230 numpy.clip : equivalent function | |
3231 | |
3232 """)) | |
3233 | |
3234 | |
3235 add_newdoc('numpy.core.multiarray', 'ndarray', ('compress', | |
3236 """ | |
3237 a.compress(condition, axis=None, out=None) | |
3238 | |
3239 Return selected slices of this array along given axis. | |
3240 | |
3241 Refer to `numpy.compress` for full documentation. | |
3242 | |
3243 See Also | |
3244 -------- | |
3245 numpy.compress : equivalent function | |
3246 | |
3247 """)) | |
3248 | |
3249 | |
3250 add_newdoc('numpy.core.multiarray', 'ndarray', ('conj', | |
3251 """ | |
3252 a.conj() | |
3253 | |
3254 Complex-conjugate all elements. | |
3255 | |
3256 Refer to `numpy.conjugate` for full documentation. | |
3257 | |
3258 See Also | |
3259 -------- | |
3260 numpy.conjugate : equivalent function | |
3261 | |
3262 """)) | |
3263 | |
3264 | |
3265 add_newdoc('numpy.core.multiarray', 'ndarray', ('conjugate', | |
3266 """ | |
3267 a.conjugate() | |
3268 | |
3269 Return the complex conjugate, element-wise. | |
3270 | |
3271 Refer to `numpy.conjugate` for full documentation. | |
3272 | |
3273 See Also | |
3274 -------- | |
3275 numpy.conjugate : equivalent function | |
3276 | |
3277 """)) | |
3278 | |
3279 | |
3280 add_newdoc('numpy.core.multiarray', 'ndarray', ('copy', | |
3281 """ | |
3282 a.copy(order='C') | |
3283 | |
3284 Return a copy of the array. | |
3285 | |
3286 Parameters | |
3287 ---------- | |
3288 order : {'C', 'F', 'A', 'K'}, optional | |
3289 Controls the memory layout of the copy. 'C' means C-order, | |
3290 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, | |
3291 'C' otherwise. 'K' means match the layout of `a` as closely | |
3292 as possible. (Note that this function and :func:numpy.copy are very | |
3293 similar, but have different default values for their order= | |
3294 arguments.) | |
3295 | |
3296 See also | |
3297 -------- | |
3298 numpy.copy | |
3299 numpy.copyto | |
3300 | |
3301 Examples | |
3302 -------- | |
3303 >>> x = np.array([[1,2,3],[4,5,6]], order='F') | |
3304 | |
3305 >>> y = x.copy() | |
3306 | |
3307 >>> x.fill(0) | |
3308 | |
3309 >>> x | |
3310 array([[0, 0, 0], | |
3311 [0, 0, 0]]) | |
3312 | |
3313 >>> y | |
3314 array([[1, 2, 3], | |
3315 [4, 5, 6]]) | |
3316 | |
3317 >>> y.flags['C_CONTIGUOUS'] | |
3318 True | |
3319 | |
3320 """)) | |
3321 | |
3322 | |
3323 add_newdoc('numpy.core.multiarray', 'ndarray', ('cumprod', | |
3324 """ | |
3325 a.cumprod(axis=None, dtype=None, out=None) | |
3326 | |
3327 Return the cumulative product of the elements along the given axis. | |
3328 | |
3329 Refer to `numpy.cumprod` for full documentation. | |
3330 | |
3331 See Also | |
3332 -------- | |
3333 numpy.cumprod : equivalent function | |
3334 | |
3335 """)) | |
3336 | |
3337 | |
3338 add_newdoc('numpy.core.multiarray', 'ndarray', ('cumsum', | |
3339 """ | |
3340 a.cumsum(axis=None, dtype=None, out=None) | |
3341 | |
3342 Return the cumulative sum of the elements along the given axis. | |
3343 | |
3344 Refer to `numpy.cumsum` for full documentation. | |
3345 | |
3346 See Also | |
3347 -------- | |
3348 numpy.cumsum : equivalent function | |
3349 | |
3350 """)) | |
3351 | |
3352 | |
3353 add_newdoc('numpy.core.multiarray', 'ndarray', ('diagonal', | |
3354 """ | |
3355 a.diagonal(offset=0, axis1=0, axis2=1) | |
3356 | |
3357 Return specified diagonals. In NumPy 1.9 the returned array is a | |
3358 read-only view instead of a copy as in previous NumPy versions. In | |
3359 NumPy 1.10 the read-only restriction will be removed. | |
3360 | |
3361 Refer to :func:`numpy.diagonal` for full documentation. | |
3362 | |
3363 See Also | |
3364 -------- | |
3365 numpy.diagonal : equivalent function | |
3366 | |
3367 """)) | |
3368 | |
3369 | |
3370 add_newdoc('numpy.core.multiarray', 'ndarray', ('dot', | |
3371 """ | |
3372 a.dot(b, out=None) | |
3373 | |
3374 Dot product of two arrays. | |
3375 | |
3376 Refer to `numpy.dot` for full documentation. | |
3377 | |
3378 See Also | |
3379 -------- | |
3380 numpy.dot : equivalent function | |
3381 | |
3382 Examples | |
3383 -------- | |
3384 >>> a = np.eye(2) | |
3385 >>> b = np.ones((2, 2)) * 2 | |
3386 >>> a.dot(b) | |
3387 array([[ 2., 2.], | |
3388 [ 2., 2.]]) | |
3389 | |
3390 This array method can be conveniently chained: | |
3391 | |
3392 >>> a.dot(b).dot(b) | |
3393 array([[ 8., 8.], | |
3394 [ 8., 8.]]) | |
3395 | |
3396 """)) | |
3397 | |
3398 | |
3399 add_newdoc('numpy.core.multiarray', 'ndarray', ('dump', | |
3400 """a.dump(file) | |
3401 | |
3402 Dump a pickle of the array to the specified file. | |
3403 The array can be read back with pickle.load or numpy.load. | |
3404 | |
3405 Parameters | |
3406 ---------- | |
3407 file : str | |
3408 A string naming the dump file. | |
3409 | |
3410 """)) | |
3411 | |
3412 | |
3413 add_newdoc('numpy.core.multiarray', 'ndarray', ('dumps', | |
3414 """ | |
3415 a.dumps() | |
3416 | |
3417 Returns the pickle of the array as a string. | |
3418 pickle.loads or numpy.loads will convert the string back to an array. | |
3419 | |
3420 Parameters | |
3421 ---------- | |
3422 None | |
3423 | |
3424 """)) | |
3425 | |
3426 | |
3427 add_newdoc('numpy.core.multiarray', 'ndarray', ('fill', | |
3428 """ | |
3429 a.fill(value) | |
3430 | |
3431 Fill the array with a scalar value. | |
3432 | |
3433 Parameters | |
3434 ---------- | |
3435 value : scalar | |
3436 All elements of `a` will be assigned this value. | |
3437 | |
3438 Examples | |
3439 -------- | |
3440 >>> a = np.array([1, 2]) | |
3441 >>> a.fill(0) | |
3442 >>> a | |
3443 array([0, 0]) | |
3444 >>> a = np.empty(2) | |
3445 >>> a.fill(1) | |
3446 >>> a | |
3447 array([ 1., 1.]) | |
3448 | |
3449 """)) | |
3450 | |
3451 | |
3452 add_newdoc('numpy.core.multiarray', 'ndarray', ('flatten', | |
3453 """ | |
3454 a.flatten(order='C') | |
3455 | |
3456 Return a copy of the array collapsed into one dimension. | |
3457 | |
3458 Parameters | |
3459 ---------- | |
3460 order : {'C', 'F', 'A'}, optional | |
3461 Whether to flatten in C (row-major), Fortran (column-major) order, | |
3462 or preserve the C/Fortran ordering from `a`. | |
3463 The default is 'C'. | |
3464 | |
3465 Returns | |
3466 ------- | |
3467 y : ndarray | |
3468 A copy of the input array, flattened to one dimension. | |
3469 | |
3470 See Also | |
3471 -------- | |
3472 ravel : Return a flattened array. | |
3473 flat : A 1-D flat iterator over the array. | |
3474 | |
3475 Examples | |
3476 -------- | |
3477 >>> a = np.array([[1,2], [3,4]]) | |
3478 >>> a.flatten() | |
3479 array([1, 2, 3, 4]) | |
3480 >>> a.flatten('F') | |
3481 array([1, 3, 2, 4]) | |
3482 | |
3483 """)) | |
3484 | |
3485 | |
3486 add_newdoc('numpy.core.multiarray', 'ndarray', ('getfield', | |
3487 """ | |
3488 a.getfield(dtype, offset=0) | |
3489 | |
3490 Returns a field of the given array as a certain type. | |
3491 | |
3492 A field is a view of the array data with a given data-type. The values in | |
3493 the view are determined by the given type and the offset into the current | |
3494 array in bytes. The offset needs to be such that the view dtype fits in the | |
3495 array dtype; for example an array of dtype complex128 has 16-byte elements. | |
3496 If taking a view with a 32-bit integer (4 bytes), the offset needs to be | |
3497 between 0 and 12 bytes. | |
3498 | |
3499 Parameters | |
3500 ---------- | |
3501 dtype : str or dtype | |
3502 The data type of the view. The dtype size of the view can not be larger | |
3503 than that of the array itself. | |
3504 offset : int | |
3505 Number of bytes to skip before beginning the element view. | |
3506 | |
3507 Examples | |
3508 -------- | |
3509 >>> x = np.diag([1.+1.j]*2) | |
3510 >>> x[1, 1] = 2 + 4.j | |
3511 >>> x | |
3512 array([[ 1.+1.j, 0.+0.j], | |
3513 [ 0.+0.j, 2.+4.j]]) | |
3514 >>> x.getfield(np.float64) | |
3515 array([[ 1., 0.], | |
3516 [ 0., 2.]]) | |
3517 | |
3518 By choosing an offset of 8 bytes we can select the complex part of the | |
3519 array for our view: | |
3520 | |
3521 >>> x.getfield(np.float64, offset=8) | |
3522 array([[ 1., 0.], | |
3523 [ 0., 4.]]) | |
3524 | |
3525 """)) | |
3526 | |
3527 | |
3528 add_newdoc('numpy.core.multiarray', 'ndarray', ('item', | |
3529 """ | |
3530 a.item(*args) | |
3531 | |
3532 Copy an element of an array to a standard Python scalar and return it. | |
3533 | |
3534 Parameters | |
3535 ---------- | |
3536 \\*args : Arguments (variable number and type) | |
3537 | |
3538 * none: in this case, the method only works for arrays | |
3539 with one element (`a.size == 1`), which element is | |
3540 copied into a standard Python scalar object and returned. | |
3541 | |
3542 * int_type: this argument is interpreted as a flat index into | |
3543 the array, specifying which element to copy and return. | |
3544 | |
3545 * tuple of int_types: functions as does a single int_type argument, | |
3546 except that the argument is interpreted as an nd-index into the | |
3547 array. | |
3548 | |
3549 Returns | |
3550 ------- | |
3551 z : Standard Python scalar object | |
3552 A copy of the specified element of the array as a suitable | |
3553 Python scalar | |
3554 | |
3555 Notes | |
3556 ----- | |
3557 When the data type of `a` is longdouble or clongdouble, item() returns | |
3558 a scalar array object because there is no available Python scalar that | |
3559 would not lose information. Void arrays return a buffer object for item(), | |
3560 unless fields are defined, in which case a tuple is returned. | |
3561 | |
3562 `item` is very similar to a[args], except, instead of an array scalar, | |
3563 a standard Python scalar is returned. This can be useful for speeding up | |
3564 access to elements of the array and doing arithmetic on elements of the | |
3565 array using Python's optimized math. | |
3566 | |
3567 Examples | |
3568 -------- | |
3569 >>> x = np.random.randint(9, size=(3, 3)) | |
3570 >>> x | |
3571 array([[3, 1, 7], | |
3572 [2, 8, 3], | |
3573 [8, 5, 3]]) | |
3574 >>> x.item(3) | |
3575 2 | |
3576 >>> x.item(7) | |
3577 5 | |
3578 >>> x.item((0, 1)) | |
3579 1 | |
3580 >>> x.item((2, 2)) | |
3581 3 | |
3582 | |
3583 """)) | |
3584 | |
3585 | |
3586 add_newdoc('numpy.core.multiarray', 'ndarray', ('itemset', | |
3587 """ | |
3588 a.itemset(*args) | |
3589 | |
3590 Insert scalar into an array (scalar is cast to array's dtype, if possible) | |
3591 | |
3592 There must be at least 1 argument, and define the last argument | |
3593 as *item*. Then, ``a.itemset(*args)`` is equivalent to but faster | |
3594 than ``a[args] = item``. The item should be a scalar value and `args` | |
3595 must select a single item in the array `a`. | |
3596 | |
3597 Parameters | |
3598 ---------- | |
3599 \*args : Arguments | |
3600 If one argument: a scalar, only used in case `a` is of size 1. | |
3601 If two arguments: the last argument is the value to be set | |
3602 and must be a scalar, the first argument specifies a single array | |
3603 element location. It is either an int or a tuple. | |
3604 | |
3605 Notes | |
3606 ----- | |
3607 Compared to indexing syntax, `itemset` provides some speed increase | |
3608 for placing a scalar into a particular location in an `ndarray`, | |
3609 if you must do this. However, generally this is discouraged: | |
3610 among other problems, it complicates the appearance of the code. | |
3611 Also, when using `itemset` (and `item`) inside a loop, be sure | |
3612 to assign the methods to a local variable to avoid the attribute | |
3613 look-up at each loop iteration. | |
3614 | |
3615 Examples | |
3616 -------- | |
3617 >>> x = np.random.randint(9, size=(3, 3)) | |
3618 >>> x | |
3619 array([[3, 1, 7], | |
3620 [2, 8, 3], | |
3621 [8, 5, 3]]) | |
3622 >>> x.itemset(4, 0) | |
3623 >>> x.itemset((2, 2), 9) | |
3624 >>> x | |
3625 array([[3, 1, 7], | |
3626 [2, 0, 3], | |
3627 [8, 5, 9]]) | |
3628 | |
3629 """)) | |
3630 | |
3631 | |
3632 add_newdoc('numpy.core.multiarray', 'ndarray', ('setasflat', | |
3633 """ | |
3634 a.setasflat(arr) | |
3635 | |
3636 Equivalent to a.flat = arr.flat, but is generally more efficient. | |
3637 This function does not check for overlap, so if ``arr`` and ``a`` | |
3638 are viewing the same data with different strides, the results will | |
3639 be unpredictable. | |
3640 | |
3641 Parameters | |
3642 ---------- | |
3643 arr : array_like | |
3644 The array to copy into a. | |
3645 | |
3646 Examples | |
3647 -------- | |
3648 >>> a = np.arange(2*4).reshape(2,4)[:,:-1]; a | |
3649 array([[0, 1, 2], | |
3650 [4, 5, 6]]) | |
3651 >>> b = np.arange(3*3, dtype='f4').reshape(3,3).T[::-1,:-1]; b | |
3652 array([[ 2., 5.], | |
3653 [ 1., 4.], | |
3654 [ 0., 3.]], dtype=float32) | |
3655 >>> a.setasflat(b) | |
3656 >>> a | |
3657 array([[2, 5, 1], | |
3658 [4, 0, 3]]) | |
3659 | |
3660 """)) | |
3661 | |
3662 | |
3663 add_newdoc('numpy.core.multiarray', 'ndarray', ('max', | |
3664 """ | |
3665 a.max(axis=None, out=None) | |
3666 | |
3667 Return the maximum along a given axis. | |
3668 | |
3669 Refer to `numpy.amax` for full documentation. | |
3670 | |
3671 See Also | |
3672 -------- | |
3673 numpy.amax : equivalent function | |
3674 | |
3675 """)) | |
3676 | |
3677 | |
3678 add_newdoc('numpy.core.multiarray', 'ndarray', ('mean', | |
3679 """ | |
3680 a.mean(axis=None, dtype=None, out=None) | |
3681 | |
3682 Returns the average of the array elements along given axis. | |
3683 | |
3684 Refer to `numpy.mean` for full documentation. | |
3685 | |
3686 See Also | |
3687 -------- | |
3688 numpy.mean : equivalent function | |
3689 | |
3690 """)) | |
3691 | |
3692 | |
3693 add_newdoc('numpy.core.multiarray', 'ndarray', ('min', | |
3694 """ | |
3695 a.min(axis=None, out=None) | |
3696 | |
3697 Return the minimum along a given axis. | |
3698 | |
3699 Refer to `numpy.amin` for full documentation. | |
3700 | |
3701 See Also | |
3702 -------- | |
3703 numpy.amin : equivalent function | |
3704 | |
3705 """)) | |
3706 | |
3707 | |
3708 add_newdoc('numpy.core.multiarray', 'may_share_memory', | |
3709 """ | |
3710 Determine if two arrays can share memory | |
3711 | |
3712 The memory-bounds of a and b are computed. If they overlap then | |
3713 this function returns True. Otherwise, it returns False. | |
3714 | |
3715 A return of True does not necessarily mean that the two arrays | |
3716 share any element. It just means that they *might*. | |
3717 | |
3718 Parameters | |
3719 ---------- | |
3720 a, b : ndarray | |
3721 | |
3722 Returns | |
3723 ------- | |
3724 out : bool | |
3725 | |
3726 Examples | |
3727 -------- | |
3728 >>> np.may_share_memory(np.array([1,2]), np.array([5,8,9])) | |
3729 False | |
3730 | |
3731 """) | |
3732 | |
3733 | |
3734 add_newdoc('numpy.core.multiarray', 'ndarray', ('newbyteorder', | |
3735 """ | |
3736 arr.newbyteorder(new_order='S') | |
3737 | |
3738 Return the array with the same data viewed with a different byte order. | |
3739 | |
3740 Equivalent to:: | |
3741 | |
3742 arr.view(arr.dtype.newbytorder(new_order)) | |
3743 | |
3744 Changes are also made in all fields and sub-arrays of the array data | |
3745 type. | |
3746 | |
3747 | |
3748 | |
3749 Parameters | |
3750 ---------- | |
3751 new_order : string, optional | |
3752 Byte order to force; a value from the byte order specifications | |
3753 above. `new_order` codes can be any of:: | |
3754 | |
3755 * 'S' - swap dtype from current to opposite endian | |
3756 * {'<', 'L'} - little endian | |
3757 * {'>', 'B'} - big endian | |
3758 * {'=', 'N'} - native order | |
3759 * {'|', 'I'} - ignore (no change to byte order) | |
3760 | |
3761 The default value ('S') results in swapping the current | |
3762 byte order. The code does a case-insensitive check on the first | |
3763 letter of `new_order` for the alternatives above. For example, | |
3764 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. | |
3765 | |
3766 | |
3767 Returns | |
3768 ------- | |
3769 new_arr : array | |
3770 New array object with the dtype reflecting given change to the | |
3771 byte order. | |
3772 | |
3773 """)) | |
3774 | |
3775 | |
3776 add_newdoc('numpy.core.multiarray', 'ndarray', ('nonzero', | |
3777 """ | |
3778 a.nonzero() | |
3779 | |
3780 Return the indices of the elements that are non-zero. | |
3781 | |
3782 Refer to `numpy.nonzero` for full documentation. | |
3783 | |
3784 See Also | |
3785 -------- | |
3786 numpy.nonzero : equivalent function | |
3787 | |
3788 """)) | |
3789 | |
3790 | |
3791 add_newdoc('numpy.core.multiarray', 'ndarray', ('prod', | |
3792 """ | |
3793 a.prod(axis=None, dtype=None, out=None) | |
3794 | |
3795 Return the product of the array elements over the given axis | |
3796 | |
3797 Refer to `numpy.prod` for full documentation. | |
3798 | |
3799 See Also | |
3800 -------- | |
3801 numpy.prod : equivalent function | |
3802 | |
3803 """)) | |
3804 | |
3805 | |
3806 add_newdoc('numpy.core.multiarray', 'ndarray', ('ptp', | |
3807 """ | |
3808 a.ptp(axis=None, out=None) | |
3809 | |
3810 Peak to peak (maximum - minimum) value along a given axis. | |
3811 | |
3812 Refer to `numpy.ptp` for full documentation. | |
3813 | |
3814 See Also | |
3815 -------- | |
3816 numpy.ptp : equivalent function | |
3817 | |
3818 """)) | |
3819 | |
3820 | |
3821 add_newdoc('numpy.core.multiarray', 'ndarray', ('put', | |
3822 """ | |
3823 a.put(indices, values, mode='raise') | |
3824 | |
3825 Set ``a.flat[n] = values[n]`` for all `n` in indices. | |
3826 | |
3827 Refer to `numpy.put` for full documentation. | |
3828 | |
3829 See Also | |
3830 -------- | |
3831 numpy.put : equivalent function | |
3832 | |
3833 """)) | |
3834 | |
3835 add_newdoc('numpy.core.multiarray', 'copyto', | |
3836 """ | |
3837 copyto(dst, src, casting='same_kind', where=None) | |
3838 | |
3839 Copies values from one array to another, broadcasting as necessary. | |
3840 | |
3841 Raises a TypeError if the `casting` rule is violated, and if | |
3842 `where` is provided, it selects which elements to copy. | |
3843 | |
3844 .. versionadded:: 1.7.0 | |
3845 | |
3846 Parameters | |
3847 ---------- | |
3848 dst : ndarray | |
3849 The array into which values are copied. | |
3850 src : array_like | |
3851 The array from which values are copied. | |
3852 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional | |
3853 Controls what kind of data casting may occur when copying. | |
3854 | |
3855 * 'no' means the data types should not be cast at all. | |
3856 * 'equiv' means only byte-order changes are allowed. | |
3857 * 'safe' means only casts which can preserve values are allowed. | |
3858 * 'same_kind' means only safe casts or casts within a kind, | |
3859 like float64 to float32, are allowed. | |
3860 * 'unsafe' means any data conversions may be done. | |
3861 where : array_like of bool, optional | |
3862 A boolean array which is broadcasted to match the dimensions | |
3863 of `dst`, and selects elements to copy from `src` to `dst` | |
3864 wherever it contains the value True. | |
3865 | |
3866 """) | |
3867 | |
3868 add_newdoc('numpy.core.multiarray', 'putmask', | |
3869 """ | |
3870 putmask(a, mask, values) | |
3871 | |
3872 Changes elements of an array based on conditional and input values. | |
3873 | |
3874 Sets ``a.flat[n] = values[n]`` for each n where ``mask.flat[n]==True``. | |
3875 | |
3876 If `values` is not the same size as `a` and `mask` then it will repeat. | |
3877 This gives behavior different from ``a[mask] = values``. | |
3878 | |
3879 Parameters | |
3880 ---------- | |
3881 a : array_like | |
3882 Target array. | |
3883 mask : array_like | |
3884 Boolean mask array. It has to be the same shape as `a`. | |
3885 values : array_like | |
3886 Values to put into `a` where `mask` is True. If `values` is smaller | |
3887 than `a` it will be repeated. | |
3888 | |
3889 See Also | |
3890 -------- | |
3891 place, put, take, copyto | |
3892 | |
3893 Examples | |
3894 -------- | |
3895 >>> x = np.arange(6).reshape(2, 3) | |
3896 >>> np.putmask(x, x>2, x**2) | |
3897 >>> x | |
3898 array([[ 0, 1, 2], | |
3899 [ 9, 16, 25]]) | |
3900 | |
3901 If `values` is smaller than `a` it is repeated: | |
3902 | |
3903 >>> x = np.arange(5) | |
3904 >>> np.putmask(x, x>1, [-33, -44]) | |
3905 >>> x | |
3906 array([ 0, 1, -33, -44, -33]) | |
3907 | |
3908 """) | |
3909 | |
3910 | |
3911 add_newdoc('numpy.core.multiarray', 'ndarray', ('ravel', | |
3912 """ | |
3913 a.ravel([order]) | |
3914 | |
3915 Return a flattened array. | |
3916 | |
3917 Refer to `numpy.ravel` for full documentation. | |
3918 | |
3919 See Also | |
3920 -------- | |
3921 numpy.ravel : equivalent function | |
3922 | |
3923 ndarray.flat : a flat iterator on the array. | |
3924 | |
3925 """)) | |
3926 | |
3927 | |
3928 add_newdoc('numpy.core.multiarray', 'ndarray', ('repeat', | |
3929 """ | |
3930 a.repeat(repeats, axis=None) | |
3931 | |
3932 Repeat elements of an array. | |
3933 | |
3934 Refer to `numpy.repeat` for full documentation. | |
3935 | |
3936 See Also | |
3937 -------- | |
3938 numpy.repeat : equivalent function | |
3939 | |
3940 """)) | |
3941 | |
3942 | |
3943 add_newdoc('numpy.core.multiarray', 'ndarray', ('reshape', | |
3944 """ | |
3945 a.reshape(shape, order='C') | |
3946 | |
3947 Returns an array containing the same data with a new shape. | |
3948 | |
3949 Refer to `numpy.reshape` for full documentation. | |
3950 | |
3951 See Also | |
3952 -------- | |
3953 numpy.reshape : equivalent function | |
3954 | |
3955 """)) | |
3956 | |
3957 | |
3958 add_newdoc('numpy.core.multiarray', 'ndarray', ('resize', | |
3959 """ | |
3960 a.resize(new_shape, refcheck=True) | |
3961 | |
3962 Change shape and size of array in-place. | |
3963 | |
3964 Parameters | |
3965 ---------- | |
3966 new_shape : tuple of ints, or `n` ints | |
3967 Shape of resized array. | |
3968 refcheck : bool, optional | |
3969 If False, reference count will not be checked. Default is True. | |
3970 | |
3971 Returns | |
3972 ------- | |
3973 None | |
3974 | |
3975 Raises | |
3976 ------ | |
3977 ValueError | |
3978 If `a` does not own its own data or references or views to it exist, | |
3979 and the data memory must be changed. | |
3980 | |
3981 SystemError | |
3982 If the `order` keyword argument is specified. This behaviour is a | |
3983 bug in NumPy. | |
3984 | |
3985 See Also | |
3986 -------- | |
3987 resize : Return a new array with the specified shape. | |
3988 | |
3989 Notes | |
3990 ----- | |
3991 This reallocates space for the data area if necessary. | |
3992 | |
3993 Only contiguous arrays (data elements consecutive in memory) can be | |
3994 resized. | |
3995 | |
3996 The purpose of the reference count check is to make sure you | |
3997 do not use this array as a buffer for another Python object and then | |
3998 reallocate the memory. However, reference counts can increase in | |
3999 other ways so if you are sure that you have not shared the memory | |
4000 for this array with another Python object, then you may safely set | |
4001 `refcheck` to False. | |
4002 | |
4003 Examples | |
4004 -------- | |
4005 Shrinking an array: array is flattened (in the order that the data are | |
4006 stored in memory), resized, and reshaped: | |
4007 | |
4008 >>> a = np.array([[0, 1], [2, 3]], order='C') | |
4009 >>> a.resize((2, 1)) | |
4010 >>> a | |
4011 array([[0], | |
4012 [1]]) | |
4013 | |
4014 >>> a = np.array([[0, 1], [2, 3]], order='F') | |
4015 >>> a.resize((2, 1)) | |
4016 >>> a | |
4017 array([[0], | |
4018 [2]]) | |
4019 | |
4020 Enlarging an array: as above, but missing entries are filled with zeros: | |
4021 | |
4022 >>> b = np.array([[0, 1], [2, 3]]) | |
4023 >>> b.resize(2, 3) # new_shape parameter doesn't have to be a tuple | |
4024 >>> b | |
4025 array([[0, 1, 2], | |
4026 [3, 0, 0]]) | |
4027 | |
4028 Referencing an array prevents resizing... | |
4029 | |
4030 >>> c = a | |
4031 >>> a.resize((1, 1)) | |
4032 Traceback (most recent call last): | |
4033 ... | |
4034 ValueError: cannot resize an array that has been referenced ... | |
4035 | |
4036 Unless `refcheck` is False: | |
4037 | |
4038 >>> a.resize((1, 1), refcheck=False) | |
4039 >>> a | |
4040 array([[0]]) | |
4041 >>> c | |
4042 array([[0]]) | |
4043 | |
4044 """)) | |
4045 | |
4046 | |
4047 add_newdoc('numpy.core.multiarray', 'ndarray', ('round', | |
4048 """ | |
4049 a.round(decimals=0, out=None) | |
4050 | |
4051 Return `a` with each element rounded to the given number of decimals. | |
4052 | |
4053 Refer to `numpy.around` for full documentation. | |
4054 | |
4055 See Also | |
4056 -------- | |
4057 numpy.around : equivalent function | |
4058 | |
4059 """)) | |
4060 | |
4061 | |
4062 add_newdoc('numpy.core.multiarray', 'ndarray', ('searchsorted', | |
4063 """ | |
4064 a.searchsorted(v, side='left', sorter=None) | |
4065 | |
4066 Find indices where elements of v should be inserted in a to maintain order. | |
4067 | |
4068 For full documentation, see `numpy.searchsorted` | |
4069 | |
4070 See Also | |
4071 -------- | |
4072 numpy.searchsorted : equivalent function | |
4073 | |
4074 """)) | |
4075 | |
4076 | |
4077 add_newdoc('numpy.core.multiarray', 'ndarray', ('setfield', | |
4078 """ | |
4079 a.setfield(val, dtype, offset=0) | |
4080 | |
4081 Put a value into a specified place in a field defined by a data-type. | |
4082 | |
4083 Place `val` into `a`'s field defined by `dtype` and beginning `offset` | |
4084 bytes into the field. | |
4085 | |
4086 Parameters | |
4087 ---------- | |
4088 val : object | |
4089 Value to be placed in field. | |
4090 dtype : dtype object | |
4091 Data-type of the field in which to place `val`. | |
4092 offset : int, optional | |
4093 The number of bytes into the field at which to place `val`. | |
4094 | |
4095 Returns | |
4096 ------- | |
4097 None | |
4098 | |
4099 See Also | |
4100 -------- | |
4101 getfield | |
4102 | |
4103 Examples | |
4104 -------- | |
4105 >>> x = np.eye(3) | |
4106 >>> x.getfield(np.float64) | |
4107 array([[ 1., 0., 0.], | |
4108 [ 0., 1., 0.], | |
4109 [ 0., 0., 1.]]) | |
4110 >>> x.setfield(3, np.int32) | |
4111 >>> x.getfield(np.int32) | |
4112 array([[3, 3, 3], | |
4113 [3, 3, 3], | |
4114 [3, 3, 3]]) | |
4115 >>> x | |
4116 array([[ 1.00000000e+000, 1.48219694e-323, 1.48219694e-323], | |
4117 [ 1.48219694e-323, 1.00000000e+000, 1.48219694e-323], | |
4118 [ 1.48219694e-323, 1.48219694e-323, 1.00000000e+000]]) | |
4119 >>> x.setfield(np.eye(3), np.int32) | |
4120 >>> x | |
4121 array([[ 1., 0., 0.], | |
4122 [ 0., 1., 0.], | |
4123 [ 0., 0., 1.]]) | |
4124 | |
4125 """)) | |
4126 | |
4127 | |
4128 add_newdoc('numpy.core.multiarray', 'ndarray', ('setflags', | |
4129 """ | |
4130 a.setflags(write=None, align=None, uic=None) | |
4131 | |
4132 Set array flags WRITEABLE, ALIGNED, and UPDATEIFCOPY, respectively. | |
4133 | |
4134 These Boolean-valued flags affect how numpy interprets the memory | |
4135 area used by `a` (see Notes below). The ALIGNED flag can only | |
4136 be set to True if the data is actually aligned according to the type. | |
4137 The UPDATEIFCOPY flag can never be set to True. The flag WRITEABLE | |
4138 can only be set to True if the array owns its own memory, or the | |
4139 ultimate owner of the memory exposes a writeable buffer interface, | |
4140 or is a string. (The exception for string is made so that unpickling | |
4141 can be done without copying memory.) | |
4142 | |
4143 Parameters | |
4144 ---------- | |
4145 write : bool, optional | |
4146 Describes whether or not `a` can be written to. | |
4147 align : bool, optional | |
4148 Describes whether or not `a` is aligned properly for its type. | |
4149 uic : bool, optional | |
4150 Describes whether or not `a` is a copy of another "base" array. | |
4151 | |
4152 Notes | |
4153 ----- | |
4154 Array flags provide information about how the memory area used | |
4155 for the array is to be interpreted. There are 6 Boolean flags | |
4156 in use, only three of which can be changed by the user: | |
4157 UPDATEIFCOPY, WRITEABLE, and ALIGNED. | |
4158 | |
4159 WRITEABLE (W) the data area can be written to; | |
4160 | |
4161 ALIGNED (A) the data and strides are aligned appropriately for the hardware | |
4162 (as determined by the compiler); | |
4163 | |
4164 UPDATEIFCOPY (U) this array is a copy of some other array (referenced | |
4165 by .base). When this array is deallocated, the base array will be | |
4166 updated with the contents of this array. | |
4167 | |
4168 All flags can be accessed using their first (upper case) letter as well | |
4169 as the full name. | |
4170 | |
4171 Examples | |
4172 -------- | |
4173 >>> y | |
4174 array([[3, 1, 7], | |
4175 [2, 0, 0], | |
4176 [8, 5, 9]]) | |
4177 >>> y.flags | |
4178 C_CONTIGUOUS : True | |
4179 F_CONTIGUOUS : False | |
4180 OWNDATA : True | |
4181 WRITEABLE : True | |
4182 ALIGNED : True | |
4183 UPDATEIFCOPY : False | |
4184 >>> y.setflags(write=0, align=0) | |
4185 >>> y.flags | |
4186 C_CONTIGUOUS : True | |
4187 F_CONTIGUOUS : False | |
4188 OWNDATA : True | |
4189 WRITEABLE : False | |
4190 ALIGNED : False | |
4191 UPDATEIFCOPY : False | |
4192 >>> y.setflags(uic=1) | |
4193 Traceback (most recent call last): | |
4194 File "<stdin>", line 1, in <module> | |
4195 ValueError: cannot set UPDATEIFCOPY flag to True | |
4196 | |
4197 """)) | |
4198 | |
4199 | |
4200 add_newdoc('numpy.core.multiarray', 'ndarray', ('sort', | |
4201 """ | |
4202 a.sort(axis=-1, kind='quicksort', order=None) | |
4203 | |
4204 Sort an array, in-place. | |
4205 | |
4206 Parameters | |
4207 ---------- | |
4208 axis : int, optional | |
4209 Axis along which to sort. Default is -1, which means sort along the | |
4210 last axis. | |
4211 kind : {'quicksort', 'mergesort', 'heapsort'}, optional | |
4212 Sorting algorithm. Default is 'quicksort'. | |
4213 order : list, optional | |
4214 When `a` is an array with fields defined, this argument specifies | |
4215 which fields to compare first, second, etc. Not all fields need be | |
4216 specified. | |
4217 | |
4218 See Also | |
4219 -------- | |
4220 numpy.sort : Return a sorted copy of an array. | |
4221 argsort : Indirect sort. | |
4222 lexsort : Indirect stable sort on multiple keys. | |
4223 searchsorted : Find elements in sorted array. | |
4224 partition: Partial sort. | |
4225 | |
4226 Notes | |
4227 ----- | |
4228 See ``sort`` for notes on the different sorting algorithms. | |
4229 | |
4230 Examples | |
4231 -------- | |
4232 >>> a = np.array([[1,4], [3,1]]) | |
4233 >>> a.sort(axis=1) | |
4234 >>> a | |
4235 array([[1, 4], | |
4236 [1, 3]]) | |
4237 >>> a.sort(axis=0) | |
4238 >>> a | |
4239 array([[1, 3], | |
4240 [1, 4]]) | |
4241 | |
4242 Use the `order` keyword to specify a field to use when sorting a | |
4243 structured array: | |
4244 | |
4245 >>> a = np.array([('a', 2), ('c', 1)], dtype=[('x', 'S1'), ('y', int)]) | |
4246 >>> a.sort(order='y') | |
4247 >>> a | |
4248 array([('c', 1), ('a', 2)], | |
4249 dtype=[('x', '|S1'), ('y', '<i4')]) | |
4250 | |
4251 """)) | |
4252 | |
4253 | |
4254 add_newdoc('numpy.core.multiarray', 'ndarray', ('partition', | |
4255 """ | |
4256 a.partition(kth, axis=-1, kind='introselect', order=None) | |
4257 | |
4258 Rearranges the elements in the array in such a way that value of the | |
4259 element in kth position is in the position it would be in a sorted array. | |
4260 All elements smaller than the kth element are moved before this element and | |
4261 all equal or greater are moved behind it. The ordering of the elements in | |
4262 the two partitions is undefined. | |
4263 | |
4264 .. versionadded:: 1.8.0 | |
4265 | |
4266 Parameters | |
4267 ---------- | |
4268 kth : int or sequence of ints | |
4269 Element index to partition by. The kth element value will be in its | |
4270 final sorted position and all smaller elements will be moved before it | |
4271 and all equal or greater elements behind it. | |
4272 The order all elements in the partitions is undefined. | |
4273 If provided with a sequence of kth it will partition all elements | |
4274 indexed by kth of them into their sorted position at once. | |
4275 axis : int, optional | |
4276 Axis along which to sort. Default is -1, which means sort along the | |
4277 last axis. | |
4278 kind : {'introselect'}, optional | |
4279 Selection algorithm. Default is 'introselect'. | |
4280 order : list, optional | |
4281 When `a` is an array with fields defined, this argument specifies | |
4282 which fields to compare first, second, etc. Not all fields need be | |
4283 specified. | |
4284 | |
4285 See Also | |
4286 -------- | |
4287 numpy.partition : Return a parititioned copy of an array. | |
4288 argpartition : Indirect partition. | |
4289 sort : Full sort. | |
4290 | |
4291 Notes | |
4292 ----- | |
4293 See ``np.partition`` for notes on the different algorithms. | |
4294 | |
4295 Examples | |
4296 -------- | |
4297 >>> a = np.array([3, 4, 2, 1]) | |
4298 >>> a.partition(a, 3) | |
4299 >>> a | |
4300 array([2, 1, 3, 4]) | |
4301 | |
4302 >>> a.partition((1, 3)) | |
4303 array([1, 2, 3, 4]) | |
4304 """)) | |
4305 | |
4306 | |
4307 add_newdoc('numpy.core.multiarray', 'ndarray', ('squeeze', | |
4308 """ | |
4309 a.squeeze(axis=None) | |
4310 | |
4311 Remove single-dimensional entries from the shape of `a`. | |
4312 | |
4313 Refer to `numpy.squeeze` for full documentation. | |
4314 | |
4315 See Also | |
4316 -------- | |
4317 numpy.squeeze : equivalent function | |
4318 | |
4319 """)) | |
4320 | |
4321 | |
4322 add_newdoc('numpy.core.multiarray', 'ndarray', ('std', | |
4323 """ | |
4324 a.std(axis=None, dtype=None, out=None, ddof=0) | |
4325 | |
4326 Returns the standard deviation of the array elements along given axis. | |
4327 | |
4328 Refer to `numpy.std` for full documentation. | |
4329 | |
4330 See Also | |
4331 -------- | |
4332 numpy.std : equivalent function | |
4333 | |
4334 """)) | |
4335 | |
4336 | |
4337 add_newdoc('numpy.core.multiarray', 'ndarray', ('sum', | |
4338 """ | |
4339 a.sum(axis=None, dtype=None, out=None) | |
4340 | |
4341 Return the sum of the array elements over the given axis. | |
4342 | |
4343 Refer to `numpy.sum` for full documentation. | |
4344 | |
4345 See Also | |
4346 -------- | |
4347 numpy.sum : equivalent function | |
4348 | |
4349 """)) | |
4350 | |
4351 | |
4352 add_newdoc('numpy.core.multiarray', 'ndarray', ('swapaxes', | |
4353 """ | |
4354 a.swapaxes(axis1, axis2) | |
4355 | |
4356 Return a view of the array with `axis1` and `axis2` interchanged. | |
4357 | |
4358 Refer to `numpy.swapaxes` for full documentation. | |
4359 | |
4360 See Also | |
4361 -------- | |
4362 numpy.swapaxes : equivalent function | |
4363 | |
4364 """)) | |
4365 | |
4366 | |
4367 add_newdoc('numpy.core.multiarray', 'ndarray', ('take', | |
4368 """ | |
4369 a.take(indices, axis=None, out=None, mode='raise') | |
4370 | |
4371 Return an array formed from the elements of `a` at the given indices. | |
4372 | |
4373 Refer to `numpy.take` for full documentation. | |
4374 | |
4375 See Also | |
4376 -------- | |
4377 numpy.take : equivalent function | |
4378 | |
4379 """)) | |
4380 | |
4381 | |
4382 add_newdoc('numpy.core.multiarray', 'ndarray', ('tofile', | |
4383 """ | |
4384 a.tofile(fid, sep="", format="%s") | |
4385 | |
4386 Write array to a file as text or binary (default). | |
4387 | |
4388 Data is always written in 'C' order, independent of the order of `a`. | |
4389 The data produced by this method can be recovered using the function | |
4390 fromfile(). | |
4391 | |
4392 Parameters | |
4393 ---------- | |
4394 fid : file or str | |
4395 An open file object, or a string containing a filename. | |
4396 sep : str | |
4397 Separator between array items for text output. | |
4398 If "" (empty), a binary file is written, equivalent to | |
4399 ``file.write(a.tobytes())``. | |
4400 format : str | |
4401 Format string for text file output. | |
4402 Each entry in the array is formatted to text by first converting | |
4403 it to the closest Python type, and then using "format" % item. | |
4404 | |
4405 Notes | |
4406 ----- | |
4407 This is a convenience function for quick storage of array data. | |
4408 Information on endianness and precision is lost, so this method is not a | |
4409 good choice for files intended to archive data or transport data between | |
4410 machines with different endianness. Some of these problems can be overcome | |
4411 by outputting the data as text files, at the expense of speed and file | |
4412 size. | |
4413 | |
4414 """)) | |
4415 | |
4416 | |
4417 add_newdoc('numpy.core.multiarray', 'ndarray', ('tolist', | |
4418 """ | |
4419 a.tolist() | |
4420 | |
4421 Return the array as a (possibly nested) list. | |
4422 | |
4423 Return a copy of the array data as a (nested) Python list. | |
4424 Data items are converted to the nearest compatible Python type. | |
4425 | |
4426 Parameters | |
4427 ---------- | |
4428 none | |
4429 | |
4430 Returns | |
4431 ------- | |
4432 y : list | |
4433 The possibly nested list of array elements. | |
4434 | |
4435 Notes | |
4436 ----- | |
4437 The array may be recreated, ``a = np.array(a.tolist())``. | |
4438 | |
4439 Examples | |
4440 -------- | |
4441 >>> a = np.array([1, 2]) | |
4442 >>> a.tolist() | |
4443 [1, 2] | |
4444 >>> a = np.array([[1, 2], [3, 4]]) | |
4445 >>> list(a) | |
4446 [array([1, 2]), array([3, 4])] | |
4447 >>> a.tolist() | |
4448 [[1, 2], [3, 4]] | |
4449 | |
4450 """)) | |
4451 | |
4452 | |
4453 tobytesdoc = """ | |
4454 a.{name}(order='C') | |
4455 | |
4456 Construct Python bytes containing the raw data bytes in the array. | |
4457 | |
4458 Constructs Python bytes showing a copy of the raw contents of | |
4459 data memory. The bytes object can be produced in either 'C' or 'Fortran', | |
4460 or 'Any' order (the default is 'C'-order). 'Any' order means C-order | |
4461 unless the F_CONTIGUOUS flag in the array is set, in which case it | |
4462 means 'Fortran' order. | |
4463 | |
4464 {deprecated} | |
4465 | |
4466 Parameters | |
4467 ---------- | |
4468 order : {{'C', 'F', None}}, optional | |
4469 Order of the data for multidimensional arrays: | |
4470 C, Fortran, or the same as for the original array. | |
4471 | |
4472 Returns | |
4473 ------- | |
4474 s : bytes | |
4475 Python bytes exhibiting a copy of `a`'s raw data. | |
4476 | |
4477 Examples | |
4478 -------- | |
4479 >>> x = np.array([[0, 1], [2, 3]]) | |
4480 >>> x.tobytes() | |
4481 b'\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x03\\x00\\x00\\x00' | |
4482 >>> x.tobytes('C') == x.tobytes() | |
4483 True | |
4484 >>> x.tobytes('F') | |
4485 b'\\x00\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x03\\x00\\x00\\x00' | |
4486 | |
4487 """ | |
4488 | |
4489 add_newdoc('numpy.core.multiarray', 'ndarray', | |
4490 ('tostring', tobytesdoc.format(name='tostring', | |
4491 deprecated= | |
4492 'This function is a compatibility ' | |
4493 'alias for tobytes. Despite its ' | |
4494 'name it returns bytes not ' | |
4495 'strings.'))) | |
4496 add_newdoc('numpy.core.multiarray', 'ndarray', | |
4497 ('tobytes', tobytesdoc.format(name='tobytes', | |
4498 deprecated='.. versionadded:: 1.9.0'))) | |
4499 | |
4500 add_newdoc('numpy.core.multiarray', 'ndarray', ('trace', | |
4501 """ | |
4502 a.trace(offset=0, axis1=0, axis2=1, dtype=None, out=None) | |
4503 | |
4504 Return the sum along diagonals of the array. | |
4505 | |
4506 Refer to `numpy.trace` for full documentation. | |
4507 | |
4508 See Also | |
4509 -------- | |
4510 numpy.trace : equivalent function | |
4511 | |
4512 """)) | |
4513 | |
4514 | |
4515 add_newdoc('numpy.core.multiarray', 'ndarray', ('transpose', | |
4516 """ | |
4517 a.transpose(*axes) | |
4518 | |
4519 Returns a view of the array with axes transposed. | |
4520 | |
4521 For a 1-D array, this has no effect. (To change between column and | |
4522 row vectors, first cast the 1-D array into a matrix object.) | |
4523 For a 2-D array, this is the usual matrix transpose. | |
4524 For an n-D array, if axes are given, their order indicates how the | |
4525 axes are permuted (see Examples). If axes are not provided and | |
4526 ``a.shape = (i[0], i[1], ... i[n-2], i[n-1])``, then | |
4527 ``a.transpose().shape = (i[n-1], i[n-2], ... i[1], i[0])``. | |
4528 | |
4529 Parameters | |
4530 ---------- | |
4531 axes : None, tuple of ints, or `n` ints | |
4532 | |
4533 * None or no argument: reverses the order of the axes. | |
4534 | |
4535 * tuple of ints: `i` in the `j`-th place in the tuple means `a`'s | |
4536 `i`-th axis becomes `a.transpose()`'s `j`-th axis. | |
4537 | |
4538 * `n` ints: same as an n-tuple of the same ints (this form is | |
4539 intended simply as a "convenience" alternative to the tuple form) | |
4540 | |
4541 Returns | |
4542 ------- | |
4543 out : ndarray | |
4544 View of `a`, with axes suitably permuted. | |
4545 | |
4546 See Also | |
4547 -------- | |
4548 ndarray.T : Array property returning the array transposed. | |
4549 | |
4550 Examples | |
4551 -------- | |
4552 >>> a = np.array([[1, 2], [3, 4]]) | |
4553 >>> a | |
4554 array([[1, 2], | |
4555 [3, 4]]) | |
4556 >>> a.transpose() | |
4557 array([[1, 3], | |
4558 [2, 4]]) | |
4559 >>> a.transpose((1, 0)) | |
4560 array([[1, 3], | |
4561 [2, 4]]) | |
4562 >>> a.transpose(1, 0) | |
4563 array([[1, 3], | |
4564 [2, 4]]) | |
4565 | |
4566 """)) | |
4567 | |
4568 | |
4569 add_newdoc('numpy.core.multiarray', 'ndarray', ('var', | |
4570 """ | |
4571 a.var(axis=None, dtype=None, out=None, ddof=0) | |
4572 | |
4573 Returns the variance of the array elements, along given axis. | |
4574 | |
4575 Refer to `numpy.var` for full documentation. | |
4576 | |
4577 See Also | |
4578 -------- | |
4579 numpy.var : equivalent function | |
4580 | |
4581 """)) | |
4582 | |
4583 | |
4584 add_newdoc('numpy.core.multiarray', 'ndarray', ('view', | |
4585 """ | |
4586 a.view(dtype=None, type=None) | |
4587 | |
4588 New view of array with the same data. | |
4589 | |
4590 Parameters | |
4591 ---------- | |
4592 dtype : data-type or ndarray sub-class, optional | |
4593 Data-type descriptor of the returned view, e.g., float32 or int16. The | |
4594 default, None, results in the view having the same data-type as `a`. | |
4595 This argument can also be specified as an ndarray sub-class, which | |
4596 then specifies the type of the returned object (this is equivalent to | |
4597 setting the ``type`` parameter). | |
4598 type : Python type, optional | |
4599 Type of the returned view, e.g., ndarray or matrix. Again, the | |
4600 default None results in type preservation. | |
4601 | |
4602 Notes | |
4603 ----- | |
4604 ``a.view()`` is used two different ways: | |
4605 | |
4606 ``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view | |
4607 of the array's memory with a different data-type. This can cause a | |
4608 reinterpretation of the bytes of memory. | |
4609 | |
4610 ``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just | |
4611 returns an instance of `ndarray_subclass` that looks at the same array | |
4612 (same shape, dtype, etc.) This does not cause a reinterpretation of the | |
4613 memory. | |
4614 | |
4615 For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of | |
4616 bytes per entry than the previous dtype (for example, converting a | |
4617 regular array to a structured array), then the behavior of the view | |
4618 cannot be predicted just from the superficial appearance of ``a`` (shown | |
4619 by ``print(a)``). It also depends on exactly how ``a`` is stored in | |
4620 memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus | |
4621 defined as a slice or transpose, etc., the view may give different | |
4622 results. | |
4623 | |
4624 | |
4625 Examples | |
4626 -------- | |
4627 >>> x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)]) | |
4628 | |
4629 Viewing array data using a different type and dtype: | |
4630 | |
4631 >>> y = x.view(dtype=np.int16, type=np.matrix) | |
4632 >>> y | |
4633 matrix([[513]], dtype=int16) | |
4634 >>> print type(y) | |
4635 <class 'numpy.matrixlib.defmatrix.matrix'> | |
4636 | |
4637 Creating a view on a structured array so it can be used in calculations | |
4638 | |
4639 >>> x = np.array([(1, 2),(3,4)], dtype=[('a', np.int8), ('b', np.int8)]) | |
4640 >>> xv = x.view(dtype=np.int8).reshape(-1,2) | |
4641 >>> xv | |
4642 array([[1, 2], | |
4643 [3, 4]], dtype=int8) | |
4644 >>> xv.mean(0) | |
4645 array([ 2., 3.]) | |
4646 | |
4647 Making changes to the view changes the underlying array | |
4648 | |
4649 >>> xv[0,1] = 20 | |
4650 >>> print x | |
4651 [(1, 20) (3, 4)] | |
4652 | |
4653 Using a view to convert an array to a record array: | |
4654 | |
4655 >>> z = x.view(np.recarray) | |
4656 >>> z.a | |
4657 array([1], dtype=int8) | |
4658 | |
4659 Views share data: | |
4660 | |
4661 >>> x[0] = (9, 10) | |
4662 >>> z[0] | |
4663 (9, 10) | |
4664 | |
4665 Views that change the dtype size (bytes per entry) should normally be | |
4666 avoided on arrays defined by slices, transposes, fortran-ordering, etc.: | |
4667 | |
4668 >>> x = np.array([[1,2,3],[4,5,6]], dtype=np.int16) | |
4669 >>> y = x[:, 0:2] | |
4670 >>> y | |
4671 array([[1, 2], | |
4672 [4, 5]], dtype=int16) | |
4673 >>> y.view(dtype=[('width', np.int16), ('length', np.int16)]) | |
4674 Traceback (most recent call last): | |
4675 File "<stdin>", line 1, in <module> | |
4676 ValueError: new type not compatible with array. | |
4677 >>> z = y.copy() | |
4678 >>> z.view(dtype=[('width', np.int16), ('length', np.int16)]) | |
4679 array([[(1, 2)], | |
4680 [(4, 5)]], dtype=[('width', '<i2'), ('length', '<i2')]) | |
4681 """)) | |
4682 | |
4683 | |
4684 ############################################################################## | |
4685 # | |
4686 # umath functions | |
4687 # | |
4688 ############################################################################## | |
4689 | |
4690 add_newdoc('numpy.core.umath', 'frompyfunc', | |
4691 """ | |
4692 frompyfunc(func, nin, nout) | |
4693 | |
4694 Takes an arbitrary Python function and returns a Numpy ufunc. | |
4695 | |
4696 Can be used, for example, to add broadcasting to a built-in Python | |
4697 function (see Examples section). | |
4698 | |
4699 Parameters | |
4700 ---------- | |
4701 func : Python function object | |
4702 An arbitrary Python function. | |
4703 nin : int | |
4704 The number of input arguments. | |
4705 nout : int | |
4706 The number of objects returned by `func`. | |
4707 | |
4708 Returns | |
4709 ------- | |
4710 out : ufunc | |
4711 Returns a Numpy universal function (``ufunc``) object. | |
4712 | |
4713 Notes | |
4714 ----- | |
4715 The returned ufunc always returns PyObject arrays. | |
4716 | |
4717 Examples | |
4718 -------- | |
4719 Use frompyfunc to add broadcasting to the Python function ``oct``: | |
4720 | |
4721 >>> oct_array = np.frompyfunc(oct, 1, 1) | |
4722 >>> oct_array(np.array((10, 30, 100))) | |
4723 array([012, 036, 0144], dtype=object) | |
4724 >>> np.array((oct(10), oct(30), oct(100))) # for comparison | |
4725 array(['012', '036', '0144'], | |
4726 dtype='|S4') | |
4727 | |
4728 """) | |
4729 | |
4730 add_newdoc('numpy.core.umath', 'geterrobj', | |
4731 """ | |
4732 geterrobj() | |
4733 | |
4734 Return the current object that defines floating-point error handling. | |
4735 | |
4736 The error object contains all information that defines the error handling | |
4737 behavior in Numpy. `geterrobj` is used internally by the other | |
4738 functions that get and set error handling behavior (`geterr`, `seterr`, | |
4739 `geterrcall`, `seterrcall`). | |
4740 | |
4741 Returns | |
4742 ------- | |
4743 errobj : list | |
4744 The error object, a list containing three elements: | |
4745 [internal numpy buffer size, error mask, error callback function]. | |
4746 | |
4747 The error mask is a single integer that holds the treatment information | |
4748 on all four floating point errors. The information for each error type | |
4749 is contained in three bits of the integer. If we print it in base 8, we | |
4750 can see what treatment is set for "invalid", "under", "over", and | |
4751 "divide" (in that order). The printed string can be interpreted with | |
4752 | |
4753 * 0 : 'ignore' | |
4754 * 1 : 'warn' | |
4755 * 2 : 'raise' | |
4756 * 3 : 'call' | |
4757 * 4 : 'print' | |
4758 * 5 : 'log' | |
4759 | |
4760 See Also | |
4761 -------- | |
4762 seterrobj, seterr, geterr, seterrcall, geterrcall | |
4763 getbufsize, setbufsize | |
4764 | |
4765 Notes | |
4766 ----- | |
4767 For complete documentation of the types of floating-point exceptions and | |
4768 treatment options, see `seterr`. | |
4769 | |
4770 Examples | |
4771 -------- | |
4772 >>> np.geterrobj() # first get the defaults | |
4773 [10000, 0, None] | |
4774 | |
4775 >>> def err_handler(type, flag): | |
4776 ... print "Floating point error (%s), with flag %s" % (type, flag) | |
4777 ... | |
4778 >>> old_bufsize = np.setbufsize(20000) | |
4779 >>> old_err = np.seterr(divide='raise') | |
4780 >>> old_handler = np.seterrcall(err_handler) | |
4781 >>> np.geterrobj() | |
4782 [20000, 2, <function err_handler at 0x91dcaac>] | |
4783 | |
4784 >>> old_err = np.seterr(all='ignore') | |
4785 >>> np.base_repr(np.geterrobj()[1], 8) | |
4786 '0' | |
4787 >>> old_err = np.seterr(divide='warn', over='log', under='call', | |
4788 invalid='print') | |
4789 >>> np.base_repr(np.geterrobj()[1], 8) | |
4790 '4351' | |
4791 | |
4792 """) | |
4793 | |
4794 add_newdoc('numpy.core.umath', 'seterrobj', | |
4795 """ | |
4796 seterrobj(errobj) | |
4797 | |
4798 Set the object that defines floating-point error handling. | |
4799 | |
4800 The error object contains all information that defines the error handling | |
4801 behavior in Numpy. `seterrobj` is used internally by the other | |
4802 functions that set error handling behavior (`seterr`, `seterrcall`). | |
4803 | |
4804 Parameters | |
4805 ---------- | |
4806 errobj : list | |
4807 The error object, a list containing three elements: | |
4808 [internal numpy buffer size, error mask, error callback function]. | |
4809 | |
4810 The error mask is a single integer that holds the treatment information | |
4811 on all four floating point errors. The information for each error type | |
4812 is contained in three bits of the integer. If we print it in base 8, we | |
4813 can see what treatment is set for "invalid", "under", "over", and | |
4814 "divide" (in that order). The printed string can be interpreted with | |
4815 | |
4816 * 0 : 'ignore' | |
4817 * 1 : 'warn' | |
4818 * 2 : 'raise' | |
4819 * 3 : 'call' | |
4820 * 4 : 'print' | |
4821 * 5 : 'log' | |
4822 | |
4823 See Also | |
4824 -------- | |
4825 geterrobj, seterr, geterr, seterrcall, geterrcall | |
4826 getbufsize, setbufsize | |
4827 | |
4828 Notes | |
4829 ----- | |
4830 For complete documentation of the types of floating-point exceptions and | |
4831 treatment options, see `seterr`. | |
4832 | |
4833 Examples | |
4834 -------- | |
4835 >>> old_errobj = np.geterrobj() # first get the defaults | |
4836 >>> old_errobj | |
4837 [10000, 0, None] | |
4838 | |
4839 >>> def err_handler(type, flag): | |
4840 ... print "Floating point error (%s), with flag %s" % (type, flag) | |
4841 ... | |
4842 >>> new_errobj = [20000, 12, err_handler] | |
4843 >>> np.seterrobj(new_errobj) | |
4844 >>> np.base_repr(12, 8) # int for divide=4 ('print') and over=1 ('warn') | |
4845 '14' | |
4846 >>> np.geterr() | |
4847 {'over': 'warn', 'divide': 'print', 'invalid': 'ignore', 'under': 'ignore'} | |
4848 >>> np.geterrcall() is err_handler | |
4849 True | |
4850 | |
4851 """) | |
4852 | |
4853 | |
4854 ############################################################################## | |
4855 # | |
4856 # lib._compiled_base functions | |
4857 # | |
4858 ############################################################################## | |
4859 | |
4860 add_newdoc('numpy.lib._compiled_base', 'digitize', | |
4861 """ | |
4862 digitize(x, bins, right=False) | |
4863 | |
4864 Return the indices of the bins to which each value in input array belongs. | |
4865 | |
4866 Each index ``i`` returned is such that ``bins[i-1] <= x < bins[i]`` if | |
4867 `bins` is monotonically increasing, or ``bins[i-1] > x >= bins[i]`` if | |
4868 `bins` is monotonically decreasing. If values in `x` are beyond the | |
4869 bounds of `bins`, 0 or ``len(bins)`` is returned as appropriate. If right | |
4870 is True, then the right bin is closed so that the index ``i`` is such | |
4871 that ``bins[i-1] < x <= bins[i]`` or bins[i-1] >= x > bins[i]`` if `bins` | |
4872 is monotonically increasing or decreasing, respectively. | |
4873 | |
4874 Parameters | |
4875 ---------- | |
4876 x : array_like | |
4877 Input array to be binned. It has to be 1-dimensional. | |
4878 bins : array_like | |
4879 Array of bins. It has to be 1-dimensional and monotonic. | |
4880 right : bool, optional | |
4881 Indicating whether the intervals include the right or the left bin | |
4882 edge. Default behavior is (right==False) indicating that the interval | |
4883 does not include the right edge. The left bin and is open in this | |
4884 case. Ie., bins[i-1] <= x < bins[i] is the default behavior for | |
4885 monotonically increasing bins. | |
4886 | |
4887 Returns | |
4888 ------- | |
4889 out : ndarray of ints | |
4890 Output array of indices, of same shape as `x`. | |
4891 | |
4892 Raises | |
4893 ------ | |
4894 ValueError | |
4895 If the input is not 1-dimensional, or if `bins` is not monotonic. | |
4896 TypeError | |
4897 If the type of the input is complex. | |
4898 | |
4899 See Also | |
4900 -------- | |
4901 bincount, histogram, unique | |
4902 | |
4903 Notes | |
4904 ----- | |
4905 If values in `x` are such that they fall outside the bin range, | |
4906 attempting to index `bins` with the indices that `digitize` returns | |
4907 will result in an IndexError. | |
4908 | |
4909 Examples | |
4910 -------- | |
4911 >>> x = np.array([0.2, 6.4, 3.0, 1.6]) | |
4912 >>> bins = np.array([0.0, 1.0, 2.5, 4.0, 10.0]) | |
4913 >>> inds = np.digitize(x, bins) | |
4914 >>> inds | |
4915 array([1, 4, 3, 2]) | |
4916 >>> for n in range(x.size): | |
4917 ... print bins[inds[n]-1], "<=", x[n], "<", bins[inds[n]] | |
4918 ... | |
4919 0.0 <= 0.2 < 1.0 | |
4920 4.0 <= 6.4 < 10.0 | |
4921 2.5 <= 3.0 < 4.0 | |
4922 1.0 <= 1.6 < 2.5 | |
4923 | |
4924 >>> x = np.array([1.2, 10.0, 12.4, 15.5, 20.]) | |
4925 >>> bins = np.array([0,5,10,15,20]) | |
4926 >>> np.digitize(x,bins,right=True) | |
4927 array([1, 2, 3, 4, 4]) | |
4928 >>> np.digitize(x,bins,right=False) | |
4929 array([1, 3, 3, 4, 5]) | |
4930 """) | |
4931 | |
4932 add_newdoc('numpy.lib._compiled_base', 'bincount', | |
4933 """ | |
4934 bincount(x, weights=None, minlength=None) | |
4935 | |
4936 Count number of occurrences of each value in array of non-negative ints. | |
4937 | |
4938 The number of bins (of size 1) is one larger than the largest value in | |
4939 `x`. If `minlength` is specified, there will be at least this number | |
4940 of bins in the output array (though it will be longer if necessary, | |
4941 depending on the contents of `x`). | |
4942 Each bin gives the number of occurrences of its index value in `x`. | |
4943 If `weights` is specified the input array is weighted by it, i.e. if a | |
4944 value ``n`` is found at position ``i``, ``out[n] += weight[i]`` instead | |
4945 of ``out[n] += 1``. | |
4946 | |
4947 Parameters | |
4948 ---------- | |
4949 x : array_like, 1 dimension, nonnegative ints | |
4950 Input array. | |
4951 weights : array_like, optional | |
4952 Weights, array of the same shape as `x`. | |
4953 minlength : int, optional | |
4954 .. versionadded:: 1.6.0 | |
4955 | |
4956 A minimum number of bins for the output array. | |
4957 | |
4958 Returns | |
4959 ------- | |
4960 out : ndarray of ints | |
4961 The result of binning the input array. | |
4962 The length of `out` is equal to ``np.amax(x)+1``. | |
4963 | |
4964 Raises | |
4965 ------ | |
4966 ValueError | |
4967 If the input is not 1-dimensional, or contains elements with negative | |
4968 values, or if `minlength` is non-positive. | |
4969 TypeError | |
4970 If the type of the input is float or complex. | |
4971 | |
4972 See Also | |
4973 -------- | |
4974 histogram, digitize, unique | |
4975 | |
4976 Examples | |
4977 -------- | |
4978 >>> np.bincount(np.arange(5)) | |
4979 array([1, 1, 1, 1, 1]) | |
4980 >>> np.bincount(np.array([0, 1, 1, 3, 2, 1, 7])) | |
4981 array([1, 3, 1, 1, 0, 0, 0, 1]) | |
4982 | |
4983 >>> x = np.array([0, 1, 1, 3, 2, 1, 7, 23]) | |
4984 >>> np.bincount(x).size == np.amax(x)+1 | |
4985 True | |
4986 | |
4987 The input array needs to be of integer dtype, otherwise a | |
4988 TypeError is raised: | |
4989 | |
4990 >>> np.bincount(np.arange(5, dtype=np.float)) | |
4991 Traceback (most recent call last): | |
4992 File "<stdin>", line 1, in <module> | |
4993 TypeError: array cannot be safely cast to required type | |
4994 | |
4995 A possible use of ``bincount`` is to perform sums over | |
4996 variable-size chunks of an array, using the ``weights`` keyword. | |
4997 | |
4998 >>> w = np.array([0.3, 0.5, 0.2, 0.7, 1., -0.6]) # weights | |
4999 >>> x = np.array([0, 1, 1, 2, 2, 2]) | |
5000 >>> np.bincount(x, weights=w) | |
5001 array([ 0.3, 0.7, 1.1]) | |
5002 | |
5003 """) | |
5004 | |
5005 add_newdoc('numpy.lib._compiled_base', 'ravel_multi_index', | |
5006 """ | |
5007 ravel_multi_index(multi_index, dims, mode='raise', order='C') | |
5008 | |
5009 Converts a tuple of index arrays into an array of flat | |
5010 indices, applying boundary modes to the multi-index. | |
5011 | |
5012 Parameters | |
5013 ---------- | |
5014 multi_index : tuple of array_like | |
5015 A tuple of integer arrays, one array for each dimension. | |
5016 dims : tuple of ints | |
5017 The shape of array into which the indices from ``multi_index`` apply. | |
5018 mode : {'raise', 'wrap', 'clip'}, optional | |
5019 Specifies how out-of-bounds indices are handled. Can specify | |
5020 either one mode or a tuple of modes, one mode per index. | |
5021 | |
5022 * 'raise' -- raise an error (default) | |
5023 * 'wrap' -- wrap around | |
5024 * 'clip' -- clip to the range | |
5025 | |
5026 In 'clip' mode, a negative index which would normally | |
5027 wrap will clip to 0 instead. | |
5028 order : {'C', 'F'}, optional | |
5029 Determines whether the multi-index should be viewed as indexing in | |
5030 C (row-major) order or FORTRAN (column-major) order. | |
5031 | |
5032 Returns | |
5033 ------- | |
5034 raveled_indices : ndarray | |
5035 An array of indices into the flattened version of an array | |
5036 of dimensions ``dims``. | |
5037 | |
5038 See Also | |
5039 -------- | |
5040 unravel_index | |
5041 | |
5042 Notes | |
5043 ----- | |
5044 .. versionadded:: 1.6.0 | |
5045 | |
5046 Examples | |
5047 -------- | |
5048 >>> arr = np.array([[3,6,6],[4,5,1]]) | |
5049 >>> np.ravel_multi_index(arr, (7,6)) | |
5050 array([22, 41, 37]) | |
5051 >>> np.ravel_multi_index(arr, (7,6), order='F') | |
5052 array([31, 41, 13]) | |
5053 >>> np.ravel_multi_index(arr, (4,6), mode='clip') | |
5054 array([22, 23, 19]) | |
5055 >>> np.ravel_multi_index(arr, (4,4), mode=('clip','wrap')) | |
5056 array([12, 13, 13]) | |
5057 | |
5058 >>> np.ravel_multi_index((3,1,4,1), (6,7,8,9)) | |
5059 1621 | |
5060 """) | |
5061 | |
5062 add_newdoc('numpy.lib._compiled_base', 'unravel_index', | |
5063 """ | |
5064 unravel_index(indices, dims, order='C') | |
5065 | |
5066 Converts a flat index or array of flat indices into a tuple | |
5067 of coordinate arrays. | |
5068 | |
5069 Parameters | |
5070 ---------- | |
5071 indices : array_like | |
5072 An integer array whose elements are indices into the flattened | |
5073 version of an array of dimensions ``dims``. Before version 1.6.0, | |
5074 this function accepted just one index value. | |
5075 dims : tuple of ints | |
5076 The shape of the array to use for unraveling ``indices``. | |
5077 order : {'C', 'F'}, optional | |
5078 .. versionadded:: 1.6.0 | |
5079 | |
5080 Determines whether the indices should be viewed as indexing in | |
5081 C (row-major) order or FORTRAN (column-major) order. | |
5082 | |
5083 Returns | |
5084 ------- | |
5085 unraveled_coords : tuple of ndarray | |
5086 Each array in the tuple has the same shape as the ``indices`` | |
5087 array. | |
5088 | |
5089 See Also | |
5090 -------- | |
5091 ravel_multi_index | |
5092 | |
5093 Examples | |
5094 -------- | |
5095 >>> np.unravel_index([22, 41, 37], (7,6)) | |
5096 (array([3, 6, 6]), array([4, 5, 1])) | |
5097 >>> np.unravel_index([31, 41, 13], (7,6), order='F') | |
5098 (array([3, 6, 6]), array([4, 5, 1])) | |
5099 | |
5100 >>> np.unravel_index(1621, (6,7,8,9)) | |
5101 (3, 1, 4, 1) | |
5102 | |
5103 """) | |
5104 | |
5105 add_newdoc('numpy.lib._compiled_base', 'add_docstring', | |
5106 """ | |
5107 add_docstring(obj, docstring) | |
5108 | |
5109 Add a docstring to a built-in obj if possible. | |
5110 If the obj already has a docstring raise a RuntimeError | |
5111 If this routine does not know how to add a docstring to the object | |
5112 raise a TypeError | |
5113 """) | |
5114 | |
5115 add_newdoc('numpy.lib._compiled_base', 'add_newdoc_ufunc', | |
5116 """ | |
5117 add_ufunc_docstring(ufunc, new_docstring) | |
5118 | |
5119 Replace the docstring for a ufunc with new_docstring. | |
5120 This method will only work if the current docstring for | |
5121 the ufunc is NULL. (At the C level, i.e. when ufunc->doc is NULL.) | |
5122 | |
5123 Parameters | |
5124 ---------- | |
5125 ufunc : numpy.ufunc | |
5126 A ufunc whose current doc is NULL. | |
5127 new_docstring : string | |
5128 The new docstring for the ufunc. | |
5129 | |
5130 Notes | |
5131 ----- | |
5132 This method allocates memory for new_docstring on | |
5133 the heap. Technically this creates a mempory leak, since this | |
5134 memory will not be reclaimed until the end of the program | |
5135 even if the ufunc itself is removed. However this will only | |
5136 be a problem if the user is repeatedly creating ufuncs with | |
5137 no documentation, adding documentation via add_newdoc_ufunc, | |
5138 and then throwing away the ufunc. | |
5139 """) | |
5140 | |
5141 add_newdoc('numpy.lib._compiled_base', 'packbits', | |
5142 """ | |
5143 packbits(myarray, axis=None) | |
5144 | |
5145 Packs the elements of a binary-valued array into bits in a uint8 array. | |
5146 | |
5147 The result is padded to full bytes by inserting zero bits at the end. | |
5148 | |
5149 Parameters | |
5150 ---------- | |
5151 myarray : array_like | |
5152 An integer type array whose elements should be packed to bits. | |
5153 axis : int, optional | |
5154 The dimension over which bit-packing is done. | |
5155 ``None`` implies packing the flattened array. | |
5156 | |
5157 Returns | |
5158 ------- | |
5159 packed : ndarray | |
5160 Array of type uint8 whose elements represent bits corresponding to the | |
5161 logical (0 or nonzero) value of the input elements. The shape of | |
5162 `packed` has the same number of dimensions as the input (unless `axis` | |
5163 is None, in which case the output is 1-D). | |
5164 | |
5165 See Also | |
5166 -------- | |
5167 unpackbits: Unpacks elements of a uint8 array into a binary-valued output | |
5168 array. | |
5169 | |
5170 Examples | |
5171 -------- | |
5172 >>> a = np.array([[[1,0,1], | |
5173 ... [0,1,0]], | |
5174 ... [[1,1,0], | |
5175 ... [0,0,1]]]) | |
5176 >>> b = np.packbits(a, axis=-1) | |
5177 >>> b | |
5178 array([[[160],[64]],[[192],[32]]], dtype=uint8) | |
5179 | |
5180 Note that in binary 160 = 1010 0000, 64 = 0100 0000, 192 = 1100 0000, | |
5181 and 32 = 0010 0000. | |
5182 | |
5183 """) | |
5184 | |
5185 add_newdoc('numpy.lib._compiled_base', 'unpackbits', | |
5186 """ | |
5187 unpackbits(myarray, axis=None) | |
5188 | |
5189 Unpacks elements of a uint8 array into a binary-valued output array. | |
5190 | |
5191 Each element of `myarray` represents a bit-field that should be unpacked | |
5192 into a binary-valued output array. The shape of the output array is either | |
5193 1-D (if `axis` is None) or the same shape as the input array with unpacking | |
5194 done along the axis specified. | |
5195 | |
5196 Parameters | |
5197 ---------- | |
5198 myarray : ndarray, uint8 type | |
5199 Input array. | |
5200 axis : int, optional | |
5201 Unpacks along this axis. | |
5202 | |
5203 Returns | |
5204 ------- | |
5205 unpacked : ndarray, uint8 type | |
5206 The elements are binary-valued (0 or 1). | |
5207 | |
5208 See Also | |
5209 -------- | |
5210 packbits : Packs the elements of a binary-valued array into bits in a uint8 | |
5211 array. | |
5212 | |
5213 Examples | |
5214 -------- | |
5215 >>> a = np.array([[2], [7], [23]], dtype=np.uint8) | |
5216 >>> a | |
5217 array([[ 2], | |
5218 [ 7], | |
5219 [23]], dtype=uint8) | |
5220 >>> b = np.unpackbits(a, axis=1) | |
5221 >>> b | |
5222 array([[0, 0, 0, 0, 0, 0, 1, 0], | |
5223 [0, 0, 0, 0, 0, 1, 1, 1], | |
5224 [0, 0, 0, 1, 0, 1, 1, 1]], dtype=uint8) | |
5225 | |
5226 """) | |
5227 | |
5228 | |
5229 ############################################################################## | |
5230 # | |
5231 # Documentation for ufunc attributes and methods | |
5232 # | |
5233 ############################################################################## | |
5234 | |
5235 | |
5236 ############################################################################## | |
5237 # | |
5238 # ufunc object | |
5239 # | |
5240 ############################################################################## | |
5241 | |
5242 add_newdoc('numpy.core', 'ufunc', | |
5243 """ | |
5244 Functions that operate element by element on whole arrays. | |
5245 | |
5246 To see the documentation for a specific ufunc, use np.info(). For | |
5247 example, np.info(np.sin). Because ufuncs are written in C | |
5248 (for speed) and linked into Python with NumPy's ufunc facility, | |
5249 Python's help() function finds this page whenever help() is called | |
5250 on a ufunc. | |
5251 | |
5252 A detailed explanation of ufuncs can be found in the "ufuncs.rst" | |
5253 file in the NumPy reference guide. | |
5254 | |
5255 Unary ufuncs: | |
5256 ============= | |
5257 | |
5258 op(X, out=None) | |
5259 Apply op to X elementwise | |
5260 | |
5261 Parameters | |
5262 ---------- | |
5263 X : array_like | |
5264 Input array. | |
5265 out : array_like | |
5266 An array to store the output. Must be the same shape as `X`. | |
5267 | |
5268 Returns | |
5269 ------- | |
5270 r : array_like | |
5271 `r` will have the same shape as `X`; if out is provided, `r` | |
5272 will be equal to out. | |
5273 | |
5274 Binary ufuncs: | |
5275 ============== | |
5276 | |
5277 op(X, Y, out=None) | |
5278 Apply `op` to `X` and `Y` elementwise. May "broadcast" to make | |
5279 the shapes of `X` and `Y` congruent. | |
5280 | |
5281 The broadcasting rules are: | |
5282 | |
5283 * Dimensions of length 1 may be prepended to either array. | |
5284 * Arrays may be repeated along dimensions of length 1. | |
5285 | |
5286 Parameters | |
5287 ---------- | |
5288 X : array_like | |
5289 First input array. | |
5290 Y : array_like | |
5291 Second input array. | |
5292 out : array_like | |
5293 An array to store the output. Must be the same shape as the | |
5294 output would have. | |
5295 | |
5296 Returns | |
5297 ------- | |
5298 r : array_like | |
5299 The return value; if out is provided, `r` will be equal to out. | |
5300 | |
5301 """) | |
5302 | |
5303 | |
5304 ############################################################################## | |
5305 # | |
5306 # ufunc attributes | |
5307 # | |
5308 ############################################################################## | |
5309 | |
5310 add_newdoc('numpy.core', 'ufunc', ('identity', | |
5311 """ | |
5312 The identity value. | |
5313 | |
5314 Data attribute containing the identity element for the ufunc, if it has one. | |
5315 If it does not, the attribute value is None. | |
5316 | |
5317 Examples | |
5318 -------- | |
5319 >>> np.add.identity | |
5320 0 | |
5321 >>> np.multiply.identity | |
5322 1 | |
5323 >>> np.power.identity | |
5324 1 | |
5325 >>> print np.exp.identity | |
5326 None | |
5327 """)) | |
5328 | |
5329 add_newdoc('numpy.core', 'ufunc', ('nargs', | |
5330 """ | |
5331 The number of arguments. | |
5332 | |
5333 Data attribute containing the number of arguments the ufunc takes, including | |
5334 optional ones. | |
5335 | |
5336 Notes | |
5337 ----- | |
5338 Typically this value will be one more than what you might expect because all | |
5339 ufuncs take the optional "out" argument. | |
5340 | |
5341 Examples | |
5342 -------- | |
5343 >>> np.add.nargs | |
5344 3 | |
5345 >>> np.multiply.nargs | |
5346 3 | |
5347 >>> np.power.nargs | |
5348 3 | |
5349 >>> np.exp.nargs | |
5350 2 | |
5351 """)) | |
5352 | |
5353 add_newdoc('numpy.core', 'ufunc', ('nin', | |
5354 """ | |
5355 The number of inputs. | |
5356 | |
5357 Data attribute containing the number of arguments the ufunc treats as input. | |
5358 | |
5359 Examples | |
5360 -------- | |
5361 >>> np.add.nin | |
5362 2 | |
5363 >>> np.multiply.nin | |
5364 2 | |
5365 >>> np.power.nin | |
5366 2 | |
5367 >>> np.exp.nin | |
5368 1 | |
5369 """)) | |
5370 | |
5371 add_newdoc('numpy.core', 'ufunc', ('nout', | |
5372 """ | |
5373 The number of outputs. | |
5374 | |
5375 Data attribute containing the number of arguments the ufunc treats as output. | |
5376 | |
5377 Notes | |
5378 ----- | |
5379 Since all ufuncs can take output arguments, this will always be (at least) 1. | |
5380 | |
5381 Examples | |
5382 -------- | |
5383 >>> np.add.nout | |
5384 1 | |
5385 >>> np.multiply.nout | |
5386 1 | |
5387 >>> np.power.nout | |
5388 1 | |
5389 >>> np.exp.nout | |
5390 1 | |
5391 | |
5392 """)) | |
5393 | |
5394 add_newdoc('numpy.core', 'ufunc', ('ntypes', | |
5395 """ | |
5396 The number of types. | |
5397 | |
5398 The number of numerical NumPy types - of which there are 18 total - on which | |
5399 the ufunc can operate. | |
5400 | |
5401 See Also | |
5402 -------- | |
5403 numpy.ufunc.types | |
5404 | |
5405 Examples | |
5406 -------- | |
5407 >>> np.add.ntypes | |
5408 18 | |
5409 >>> np.multiply.ntypes | |
5410 18 | |
5411 >>> np.power.ntypes | |
5412 17 | |
5413 >>> np.exp.ntypes | |
5414 7 | |
5415 >>> np.remainder.ntypes | |
5416 14 | |
5417 | |
5418 """)) | |
5419 | |
5420 add_newdoc('numpy.core', 'ufunc', ('types', | |
5421 """ | |
5422 Returns a list with types grouped input->output. | |
5423 | |
5424 Data attribute listing the data-type "Domain-Range" groupings the ufunc can | |
5425 deliver. The data-types are given using the character codes. | |
5426 | |
5427 See Also | |
5428 -------- | |
5429 numpy.ufunc.ntypes | |
5430 | |
5431 Examples | |
5432 -------- | |
5433 >>> np.add.types | |
5434 ['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', | |
5435 'LL->L', 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D', | |
5436 'GG->G', 'OO->O'] | |
5437 | |
5438 >>> np.multiply.types | |
5439 ['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', | |
5440 'LL->L', 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D', | |
5441 'GG->G', 'OO->O'] | |
5442 | |
5443 >>> np.power.types | |
5444 ['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', 'LL->L', | |
5445 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D', 'GG->G', | |
5446 'OO->O'] | |
5447 | |
5448 >>> np.exp.types | |
5449 ['f->f', 'd->d', 'g->g', 'F->F', 'D->D', 'G->G', 'O->O'] | |
5450 | |
5451 >>> np.remainder.types | |
5452 ['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', 'LL->L', | |
5453 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'OO->O'] | |
5454 | |
5455 """)) | |
5456 | |
5457 | |
5458 ############################################################################## | |
5459 # | |
5460 # ufunc methods | |
5461 # | |
5462 ############################################################################## | |
5463 | |
5464 add_newdoc('numpy.core', 'ufunc', ('reduce', | |
5465 """ | |
5466 reduce(a, axis=0, dtype=None, out=None, keepdims=False) | |
5467 | |
5468 Reduces `a`'s dimension by one, by applying ufunc along one axis. | |
5469 | |
5470 Let :math:`a.shape = (N_0, ..., N_i, ..., N_{M-1})`. Then | |
5471 :math:`ufunc.reduce(a, axis=i)[k_0, ..,k_{i-1}, k_{i+1}, .., k_{M-1}]` = | |
5472 the result of iterating `j` over :math:`range(N_i)`, cumulatively applying | |
5473 ufunc to each :math:`a[k_0, ..,k_{i-1}, j, k_{i+1}, .., k_{M-1}]`. | |
5474 For a one-dimensional array, reduce produces results equivalent to: | |
5475 :: | |
5476 | |
5477 r = op.identity # op = ufunc | |
5478 for i in range(len(A)): | |
5479 r = op(r, A[i]) | |
5480 return r | |
5481 | |
5482 For example, add.reduce() is equivalent to sum(). | |
5483 | |
5484 Parameters | |
5485 ---------- | |
5486 a : array_like | |
5487 The array to act on. | |
5488 axis : None or int or tuple of ints, optional | |
5489 Axis or axes along which a reduction is performed. | |
5490 The default (`axis` = 0) is perform a reduction over the first | |
5491 dimension of the input array. `axis` may be negative, in | |
5492 which case it counts from the last to the first axis. | |
5493 | |
5494 .. versionadded:: 1.7.0 | |
5495 | |
5496 If this is `None`, a reduction is performed over all the axes. | |
5497 If this is a tuple of ints, a reduction is performed on multiple | |
5498 axes, instead of a single axis or all the axes as before. | |
5499 | |
5500 For operations which are either not commutative or not associative, | |
5501 doing a reduction over multiple axes is not well-defined. The | |
5502 ufuncs do not currently raise an exception in this case, but will | |
5503 likely do so in the future. | |
5504 dtype : data-type code, optional | |
5505 The type used to represent the intermediate results. Defaults | |
5506 to the data-type of the output array if this is provided, or | |
5507 the data-type of the input array if no output array is provided. | |
5508 out : ndarray, optional | |
5509 A location into which the result is stored. If not provided, a | |
5510 freshly-allocated array is returned. | |
5511 keepdims : bool, optional | |
5512 If this is set to True, the axes which are reduced are left | |
5513 in the result as dimensions with size one. With this option, | |
5514 the result will broadcast correctly against the original `arr`. | |
5515 | |
5516 .. versionadded:: 1.7.0 | |
5517 | |
5518 Returns | |
5519 ------- | |
5520 r : ndarray | |
5521 The reduced array. If `out` was supplied, `r` is a reference to it. | |
5522 | |
5523 Examples | |
5524 -------- | |
5525 >>> np.multiply.reduce([2,3,5]) | |
5526 30 | |
5527 | |
5528 A multi-dimensional array example: | |
5529 | |
5530 >>> X = np.arange(8).reshape((2,2,2)) | |
5531 >>> X | |
5532 array([[[0, 1], | |
5533 [2, 3]], | |
5534 [[4, 5], | |
5535 [6, 7]]]) | |
5536 >>> np.add.reduce(X, 0) | |
5537 array([[ 4, 6], | |
5538 [ 8, 10]]) | |
5539 >>> np.add.reduce(X) # confirm: default axis value is 0 | |
5540 array([[ 4, 6], | |
5541 [ 8, 10]]) | |
5542 >>> np.add.reduce(X, 1) | |
5543 array([[ 2, 4], | |
5544 [10, 12]]) | |
5545 >>> np.add.reduce(X, 2) | |
5546 array([[ 1, 5], | |
5547 [ 9, 13]]) | |
5548 | |
5549 """)) | |
5550 | |
5551 add_newdoc('numpy.core', 'ufunc', ('accumulate', | |
5552 """ | |
5553 accumulate(array, axis=0, dtype=None, out=None) | |
5554 | |
5555 Accumulate the result of applying the operator to all elements. | |
5556 | |
5557 For a one-dimensional array, accumulate produces results equivalent to:: | |
5558 | |
5559 r = np.empty(len(A)) | |
5560 t = op.identity # op = the ufunc being applied to A's elements | |
5561 for i in range(len(A)): | |
5562 t = op(t, A[i]) | |
5563 r[i] = t | |
5564 return r | |
5565 | |
5566 For example, add.accumulate() is equivalent to np.cumsum(). | |
5567 | |
5568 For a multi-dimensional array, accumulate is applied along only one | |
5569 axis (axis zero by default; see Examples below) so repeated use is | |
5570 necessary if one wants to accumulate over multiple axes. | |
5571 | |
5572 Parameters | |
5573 ---------- | |
5574 array : array_like | |
5575 The array to act on. | |
5576 axis : int, optional | |
5577 The axis along which to apply the accumulation; default is zero. | |
5578 dtype : data-type code, optional | |
5579 The data-type used to represent the intermediate results. Defaults | |
5580 to the data-type of the output array if such is provided, or the | |
5581 the data-type of the input array if no output array is provided. | |
5582 out : ndarray, optional | |
5583 A location into which the result is stored. If not provided a | |
5584 freshly-allocated array is returned. | |
5585 | |
5586 Returns | |
5587 ------- | |
5588 r : ndarray | |
5589 The accumulated values. If `out` was supplied, `r` is a reference to | |
5590 `out`. | |
5591 | |
5592 Examples | |
5593 -------- | |
5594 1-D array examples: | |
5595 | |
5596 >>> np.add.accumulate([2, 3, 5]) | |
5597 array([ 2, 5, 10]) | |
5598 >>> np.multiply.accumulate([2, 3, 5]) | |
5599 array([ 2, 6, 30]) | |
5600 | |
5601 2-D array examples: | |
5602 | |
5603 >>> I = np.eye(2) | |
5604 >>> I | |
5605 array([[ 1., 0.], | |
5606 [ 0., 1.]]) | |
5607 | |
5608 Accumulate along axis 0 (rows), down columns: | |
5609 | |
5610 >>> np.add.accumulate(I, 0) | |
5611 array([[ 1., 0.], | |
5612 [ 1., 1.]]) | |
5613 >>> np.add.accumulate(I) # no axis specified = axis zero | |
5614 array([[ 1., 0.], | |
5615 [ 1., 1.]]) | |
5616 | |
5617 Accumulate along axis 1 (columns), through rows: | |
5618 | |
5619 >>> np.add.accumulate(I, 1) | |
5620 array([[ 1., 1.], | |
5621 [ 0., 1.]]) | |
5622 | |
5623 """)) | |
5624 | |
5625 add_newdoc('numpy.core', 'ufunc', ('reduceat', | |
5626 """ | |
5627 reduceat(a, indices, axis=0, dtype=None, out=None) | |
5628 | |
5629 Performs a (local) reduce with specified slices over a single axis. | |
5630 | |
5631 For i in ``range(len(indices))``, `reduceat` computes | |
5632 ``ufunc.reduce(a[indices[i]:indices[i+1]])``, which becomes the i-th | |
5633 generalized "row" parallel to `axis` in the final result (i.e., in a | |
5634 2-D array, for example, if `axis = 0`, it becomes the i-th row, but if | |
5635 `axis = 1`, it becomes the i-th column). There are three exceptions to this: | |
5636 | |
5637 * when ``i = len(indices) - 1`` (so for the last index), | |
5638 ``indices[i+1] = a.shape[axis]``. | |
5639 * if ``indices[i] >= indices[i + 1]``, the i-th generalized "row" is | |
5640 simply ``a[indices[i]]``. | |
5641 * if ``indices[i] >= len(a)`` or ``indices[i] < 0``, an error is raised. | |
5642 | |
5643 The shape of the output depends on the size of `indices`, and may be | |
5644 larger than `a` (this happens if ``len(indices) > a.shape[axis]``). | |
5645 | |
5646 Parameters | |
5647 ---------- | |
5648 a : array_like | |
5649 The array to act on. | |
5650 indices : array_like | |
5651 Paired indices, comma separated (not colon), specifying slices to | |
5652 reduce. | |
5653 axis : int, optional | |
5654 The axis along which to apply the reduceat. | |
5655 dtype : data-type code, optional | |
5656 The type used to represent the intermediate results. Defaults | |
5657 to the data type of the output array if this is provided, or | |
5658 the data type of the input array if no output array is provided. | |
5659 out : ndarray, optional | |
5660 A location into which the result is stored. If not provided a | |
5661 freshly-allocated array is returned. | |
5662 | |
5663 Returns | |
5664 ------- | |
5665 r : ndarray | |
5666 The reduced values. If `out` was supplied, `r` is a reference to | |
5667 `out`. | |
5668 | |
5669 Notes | |
5670 ----- | |
5671 A descriptive example: | |
5672 | |
5673 If `a` is 1-D, the function `ufunc.accumulate(a)` is the same as | |
5674 ``ufunc.reduceat(a, indices)[::2]`` where `indices` is | |
5675 ``range(len(array) - 1)`` with a zero placed | |
5676 in every other element: | |
5677 ``indices = zeros(2 * len(a) - 1)``, ``indices[1::2] = range(1, len(a))``. | |
5678 | |
5679 Don't be fooled by this attribute's name: `reduceat(a)` is not | |
5680 necessarily smaller than `a`. | |
5681 | |
5682 Examples | |
5683 -------- | |
5684 To take the running sum of four successive values: | |
5685 | |
5686 >>> np.add.reduceat(np.arange(8),[0,4, 1,5, 2,6, 3,7])[::2] | |
5687 array([ 6, 10, 14, 18]) | |
5688 | |
5689 A 2-D example: | |
5690 | |
5691 >>> x = np.linspace(0, 15, 16).reshape(4,4) | |
5692 >>> x | |
5693 array([[ 0., 1., 2., 3.], | |
5694 [ 4., 5., 6., 7.], | |
5695 [ 8., 9., 10., 11.], | |
5696 [ 12., 13., 14., 15.]]) | |
5697 | |
5698 :: | |
5699 | |
5700 # reduce such that the result has the following five rows: | |
5701 # [row1 + row2 + row3] | |
5702 # [row4] | |
5703 # [row2] | |
5704 # [row3] | |
5705 # [row1 + row2 + row3 + row4] | |
5706 | |
5707 >>> np.add.reduceat(x, [0, 3, 1, 2, 0]) | |
5708 array([[ 12., 15., 18., 21.], | |
5709 [ 12., 13., 14., 15.], | |
5710 [ 4., 5., 6., 7.], | |
5711 [ 8., 9., 10., 11.], | |
5712 [ 24., 28., 32., 36.]]) | |
5713 | |
5714 :: | |
5715 | |
5716 # reduce such that result has the following two columns: | |
5717 # [col1 * col2 * col3, col4] | |
5718 | |
5719 >>> np.multiply.reduceat(x, [0, 3], 1) | |
5720 array([[ 0., 3.], | |
5721 [ 120., 7.], | |
5722 [ 720., 11.], | |
5723 [ 2184., 15.]]) | |
5724 | |
5725 """)) | |
5726 | |
5727 add_newdoc('numpy.core', 'ufunc', ('outer', | |
5728 """ | |
5729 outer(A, B) | |
5730 | |
5731 Apply the ufunc `op` to all pairs (a, b) with a in `A` and b in `B`. | |
5732 | |
5733 Let ``M = A.ndim``, ``N = B.ndim``. Then the result, `C`, of | |
5734 ``op.outer(A, B)`` is an array of dimension M + N such that: | |
5735 | |
5736 .. math:: C[i_0, ..., i_{M-1}, j_0, ..., j_{N-1}] = | |
5737 op(A[i_0, ..., i_{M-1}], B[j_0, ..., j_{N-1}]) | |
5738 | |
5739 For `A` and `B` one-dimensional, this is equivalent to:: | |
5740 | |
5741 r = empty(len(A),len(B)) | |
5742 for i in range(len(A)): | |
5743 for j in range(len(B)): | |
5744 r[i,j] = op(A[i], B[j]) # op = ufunc in question | |
5745 | |
5746 Parameters | |
5747 ---------- | |
5748 A : array_like | |
5749 First array | |
5750 B : array_like | |
5751 Second array | |
5752 | |
5753 Returns | |
5754 ------- | |
5755 r : ndarray | |
5756 Output array | |
5757 | |
5758 See Also | |
5759 -------- | |
5760 numpy.outer | |
5761 | |
5762 Examples | |
5763 -------- | |
5764 >>> np.multiply.outer([1, 2, 3], [4, 5, 6]) | |
5765 array([[ 4, 5, 6], | |
5766 [ 8, 10, 12], | |
5767 [12, 15, 18]]) | |
5768 | |
5769 A multi-dimensional example: | |
5770 | |
5771 >>> A = np.array([[1, 2, 3], [4, 5, 6]]) | |
5772 >>> A.shape | |
5773 (2, 3) | |
5774 >>> B = np.array([[1, 2, 3, 4]]) | |
5775 >>> B.shape | |
5776 (1, 4) | |
5777 >>> C = np.multiply.outer(A, B) | |
5778 >>> C.shape; C | |
5779 (2, 3, 1, 4) | |
5780 array([[[[ 1, 2, 3, 4]], | |
5781 [[ 2, 4, 6, 8]], | |
5782 [[ 3, 6, 9, 12]]], | |
5783 [[[ 4, 8, 12, 16]], | |
5784 [[ 5, 10, 15, 20]], | |
5785 [[ 6, 12, 18, 24]]]]) | |
5786 | |
5787 """)) | |
5788 | |
5789 add_newdoc('numpy.core', 'ufunc', ('at', | |
5790 """ | |
5791 at(a, indices, b=None) | |
5792 | |
5793 Performs unbuffered in place operation on operand 'a' for elements | |
5794 specified by 'indices'. For addition ufunc, this method is equivalent to | |
5795 `a[indices] += b`, except that results are accumulated for elements that | |
5796 are indexed more than once. For example, `a[[0,0]] += 1` will only | |
5797 increment the first element once because of buffering, whereas | |
5798 `add.at(a, [0,0], 1)` will increment the first element twice. | |
5799 | |
5800 .. versionadded:: 1.8.0 | |
5801 | |
5802 Parameters | |
5803 ---------- | |
5804 a : array_like | |
5805 The array to perform in place operation on. | |
5806 indices : array_like or tuple | |
5807 Array like index object or slice object for indexing into first | |
5808 operand. If first operand has multiple dimensions, indices can be a | |
5809 tuple of array like index objects or slice objects. | |
5810 b : array_like | |
5811 Second operand for ufuncs requiring two operands. Operand must be | |
5812 broadcastable over first operand after indexing or slicing. | |
5813 | |
5814 Examples | |
5815 -------- | |
5816 Set items 0 and 1 to their negative values: | |
5817 | |
5818 >>> a = np.array([1, 2, 3, 4]) | |
5819 >>> np.negative.at(a, [0, 1]) | |
5820 >>> print(a) | |
5821 array([-1, -2, 3, 4]) | |
5822 | |
5823 :: | |
5824 | |
5825 Increment items 0 and 1, and increment item 2 twice: | |
5826 | |
5827 >>> a = np.array([1, 2, 3, 4]) | |
5828 >>> np.add.at(a, [0, 1, 2, 2], 1) | |
5829 >>> print(a) | |
5830 array([2, 3, 5, 4]) | |
5831 | |
5832 :: | |
5833 | |
5834 Add items 0 and 1 in first array to second array, | |
5835 and store results in first array: | |
5836 | |
5837 >>> a = np.array([1, 2, 3, 4]) | |
5838 >>> b = np.array([1, 2]) | |
5839 >>> np.add.at(a, [0, 1], b) | |
5840 >>> print(a) | |
5841 array([2, 4, 3, 4]) | |
5842 | |
5843 """)) | |
5844 | |
5845 ############################################################################## | |
5846 # | |
5847 # Documentation for dtype attributes and methods | |
5848 # | |
5849 ############################################################################## | |
5850 | |
5851 ############################################################################## | |
5852 # | |
5853 # dtype object | |
5854 # | |
5855 ############################################################################## | |
5856 | |
5857 add_newdoc('numpy.core.multiarray', 'dtype', | |
5858 """ | |
5859 dtype(obj, align=False, copy=False) | |
5860 | |
5861 Create a data type object. | |
5862 | |
5863 A numpy array is homogeneous, and contains elements described by a | |
5864 dtype object. A dtype object can be constructed from different | |
5865 combinations of fundamental numeric types. | |
5866 | |
5867 Parameters | |
5868 ---------- | |
5869 obj | |
5870 Object to be converted to a data type object. | |
5871 align : bool, optional | |
5872 Add padding to the fields to match what a C compiler would output | |
5873 for a similar C-struct. Can be ``True`` only if `obj` is a dictionary | |
5874 or a comma-separated string. If a struct dtype is being created, | |
5875 this also sets a sticky alignment flag ``isalignedstruct``. | |
5876 copy : bool, optional | |
5877 Make a new copy of the data-type object. If ``False``, the result | |
5878 may just be a reference to a built-in data-type object. | |
5879 | |
5880 See also | |
5881 -------- | |
5882 result_type | |
5883 | |
5884 Examples | |
5885 -------- | |
5886 Using array-scalar type: | |
5887 | |
5888 >>> np.dtype(np.int16) | |
5889 dtype('int16') | |
5890 | |
5891 Record, one field name 'f1', containing int16: | |
5892 | |
5893 >>> np.dtype([('f1', np.int16)]) | |
5894 dtype([('f1', '<i2')]) | |
5895 | |
5896 Record, one field named 'f1', in itself containing a record with one field: | |
5897 | |
5898 >>> np.dtype([('f1', [('f1', np.int16)])]) | |
5899 dtype([('f1', [('f1', '<i2')])]) | |
5900 | |
5901 Record, two fields: the first field contains an unsigned int, the | |
5902 second an int32: | |
5903 | |
5904 >>> np.dtype([('f1', np.uint), ('f2', np.int32)]) | |
5905 dtype([('f1', '<u4'), ('f2', '<i4')]) | |
5906 | |
5907 Using array-protocol type strings: | |
5908 | |
5909 >>> np.dtype([('a','f8'),('b','S10')]) | |
5910 dtype([('a', '<f8'), ('b', '|S10')]) | |
5911 | |
5912 Using comma-separated field formats. The shape is (2,3): | |
5913 | |
5914 >>> np.dtype("i4, (2,3)f8") | |
5915 dtype([('f0', '<i4'), ('f1', '<f8', (2, 3))]) | |
5916 | |
5917 Using tuples. ``int`` is a fixed type, 3 the field's shape. ``void`` | |
5918 is a flexible type, here of size 10: | |
5919 | |
5920 >>> np.dtype([('hello',(np.int,3)),('world',np.void,10)]) | |
5921 dtype([('hello', '<i4', 3), ('world', '|V10')]) | |
5922 | |
5923 Subdivide ``int16`` into 2 ``int8``'s, called x and y. 0 and 1 are | |
5924 the offsets in bytes: | |
5925 | |
5926 >>> np.dtype((np.int16, {'x':(np.int8,0), 'y':(np.int8,1)})) | |
5927 dtype(('<i2', [('x', '|i1'), ('y', '|i1')])) | |
5928 | |
5929 Using dictionaries. Two fields named 'gender' and 'age': | |
5930 | |
5931 >>> np.dtype({'names':['gender','age'], 'formats':['S1',np.uint8]}) | |
5932 dtype([('gender', '|S1'), ('age', '|u1')]) | |
5933 | |
5934 Offsets in bytes, here 0 and 25: | |
5935 | |
5936 >>> np.dtype({'surname':('S25',0),'age':(np.uint8,25)}) | |
5937 dtype([('surname', '|S25'), ('age', '|u1')]) | |
5938 | |
5939 """) | |
5940 | |
5941 ############################################################################## | |
5942 # | |
5943 # dtype attributes | |
5944 # | |
5945 ############################################################################## | |
5946 | |
5947 add_newdoc('numpy.core.multiarray', 'dtype', ('alignment', | |
5948 """ | |
5949 The required alignment (bytes) of this data-type according to the compiler. | |
5950 | |
5951 More information is available in the C-API section of the manual. | |
5952 | |
5953 """)) | |
5954 | |
5955 add_newdoc('numpy.core.multiarray', 'dtype', ('byteorder', | |
5956 """ | |
5957 A character indicating the byte-order of this data-type object. | |
5958 | |
5959 One of: | |
5960 | |
5961 === ============== | |
5962 '=' native | |
5963 '<' little-endian | |
5964 '>' big-endian | |
5965 '|' not applicable | |
5966 === ============== | |
5967 | |
5968 All built-in data-type objects have byteorder either '=' or '|'. | |
5969 | |
5970 Examples | |
5971 -------- | |
5972 | |
5973 >>> dt = np.dtype('i2') | |
5974 >>> dt.byteorder | |
5975 '=' | |
5976 >>> # endian is not relevant for 8 bit numbers | |
5977 >>> np.dtype('i1').byteorder | |
5978 '|' | |
5979 >>> # or ASCII strings | |
5980 >>> np.dtype('S2').byteorder | |
5981 '|' | |
5982 >>> # Even if specific code is given, and it is native | |
5983 >>> # '=' is the byteorder | |
5984 >>> import sys | |
5985 >>> sys_is_le = sys.byteorder == 'little' | |
5986 >>> native_code = sys_is_le and '<' or '>' | |
5987 >>> swapped_code = sys_is_le and '>' or '<' | |
5988 >>> dt = np.dtype(native_code + 'i2') | |
5989 >>> dt.byteorder | |
5990 '=' | |
5991 >>> # Swapped code shows up as itself | |
5992 >>> dt = np.dtype(swapped_code + 'i2') | |
5993 >>> dt.byteorder == swapped_code | |
5994 True | |
5995 | |
5996 """)) | |
5997 | |
5998 add_newdoc('numpy.core.multiarray', 'dtype', ('char', | |
5999 """A unique character code for each of the 21 different built-in types.""")) | |
6000 | |
6001 add_newdoc('numpy.core.multiarray', 'dtype', ('descr', | |
6002 """ | |
6003 Array-interface compliant full description of the data-type. | |
6004 | |
6005 The format is that required by the 'descr' key in the | |
6006 `__array_interface__` attribute. | |
6007 | |
6008 """)) | |
6009 | |
6010 add_newdoc('numpy.core.multiarray', 'dtype', ('fields', | |
6011 """ | |
6012 Dictionary of named fields defined for this data type, or ``None``. | |
6013 | |
6014 The dictionary is indexed by keys that are the names of the fields. | |
6015 Each entry in the dictionary is a tuple fully describing the field:: | |
6016 | |
6017 (dtype, offset[, title]) | |
6018 | |
6019 If present, the optional title can be any object (if it is a string | |
6020 or unicode then it will also be a key in the fields dictionary, | |
6021 otherwise it's meta-data). Notice also that the first two elements | |
6022 of the tuple can be passed directly as arguments to the ``ndarray.getfield`` | |
6023 and ``ndarray.setfield`` methods. | |
6024 | |
6025 See Also | |
6026 -------- | |
6027 ndarray.getfield, ndarray.setfield | |
6028 | |
6029 Examples | |
6030 -------- | |
6031 >>> dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))]) | |
6032 >>> print dt.fields | |
6033 {'grades': (dtype(('float64',(2,))), 16), 'name': (dtype('|S16'), 0)} | |
6034 | |
6035 """)) | |
6036 | |
6037 add_newdoc('numpy.core.multiarray', 'dtype', ('flags', | |
6038 """ | |
6039 Bit-flags describing how this data type is to be interpreted. | |
6040 | |
6041 Bit-masks are in `numpy.core.multiarray` as the constants | |
6042 `ITEM_HASOBJECT`, `LIST_PICKLE`, `ITEM_IS_POINTER`, `NEEDS_INIT`, | |
6043 `NEEDS_PYAPI`, `USE_GETITEM`, `USE_SETITEM`. A full explanation | |
6044 of these flags is in C-API documentation; they are largely useful | |
6045 for user-defined data-types. | |
6046 | |
6047 """)) | |
6048 | |
6049 add_newdoc('numpy.core.multiarray', 'dtype', ('hasobject', | |
6050 """ | |
6051 Boolean indicating whether this dtype contains any reference-counted | |
6052 objects in any fields or sub-dtypes. | |
6053 | |
6054 Recall that what is actually in the ndarray memory representing | |
6055 the Python object is the memory address of that object (a pointer). | |
6056 Special handling may be required, and this attribute is useful for | |
6057 distinguishing data types that may contain arbitrary Python objects | |
6058 and data-types that won't. | |
6059 | |
6060 """)) | |
6061 | |
6062 add_newdoc('numpy.core.multiarray', 'dtype', ('isbuiltin', | |
6063 """ | |
6064 Integer indicating how this dtype relates to the built-in dtypes. | |
6065 | |
6066 Read-only. | |
6067 | |
6068 = ======================================================================== | |
6069 0 if this is a structured array type, with fields | |
6070 1 if this is a dtype compiled into numpy (such as ints, floats etc) | |
6071 2 if the dtype is for a user-defined numpy type | |
6072 A user-defined type uses the numpy C-API machinery to extend | |
6073 numpy to handle a new array type. See | |
6074 :ref:`user.user-defined-data-types` in the Numpy manual. | |
6075 = ======================================================================== | |
6076 | |
6077 Examples | |
6078 -------- | |
6079 >>> dt = np.dtype('i2') | |
6080 >>> dt.isbuiltin | |
6081 1 | |
6082 >>> dt = np.dtype('f8') | |
6083 >>> dt.isbuiltin | |
6084 1 | |
6085 >>> dt = np.dtype([('field1', 'f8')]) | |
6086 >>> dt.isbuiltin | |
6087 0 | |
6088 | |
6089 """)) | |
6090 | |
6091 add_newdoc('numpy.core.multiarray', 'dtype', ('isnative', | |
6092 """ | |
6093 Boolean indicating whether the byte order of this dtype is native | |
6094 to the platform. | |
6095 | |
6096 """)) | |
6097 | |
6098 add_newdoc('numpy.core.multiarray', 'dtype', ('isalignedstruct', | |
6099 """ | |
6100 Boolean indicating whether the dtype is a struct which maintains | |
6101 field alignment. This flag is sticky, so when combining multiple | |
6102 structs together, it is preserved and produces new dtypes which | |
6103 are also aligned. | |
6104 """)) | |
6105 | |
6106 add_newdoc('numpy.core.multiarray', 'dtype', ('itemsize', | |
6107 """ | |
6108 The element size of this data-type object. | |
6109 | |
6110 For 18 of the 21 types this number is fixed by the data-type. | |
6111 For the flexible data-types, this number can be anything. | |
6112 | |
6113 """)) | |
6114 | |
6115 add_newdoc('numpy.core.multiarray', 'dtype', ('kind', | |
6116 """ | |
6117 A character code (one of 'biufcOSUV') identifying the general kind of data. | |
6118 | |
6119 = ====================== | |
6120 b boolean | |
6121 i signed integer | |
6122 u unsigned integer | |
6123 f floating-point | |
6124 c complex floating-point | |
6125 O object | |
6126 S (byte-)string | |
6127 U Unicode | |
6128 V void | |
6129 = ====================== | |
6130 | |
6131 """)) | |
6132 | |
6133 add_newdoc('numpy.core.multiarray', 'dtype', ('name', | |
6134 """ | |
6135 A bit-width name for this data-type. | |
6136 | |
6137 Un-sized flexible data-type objects do not have this attribute. | |
6138 | |
6139 """)) | |
6140 | |
6141 add_newdoc('numpy.core.multiarray', 'dtype', ('names', | |
6142 """ | |
6143 Ordered list of field names, or ``None`` if there are no fields. | |
6144 | |
6145 The names are ordered according to increasing byte offset. This can be | |
6146 used, for example, to walk through all of the named fields in offset order. | |
6147 | |
6148 Examples | |
6149 -------- | |
6150 >>> dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))]) | |
6151 >>> dt.names | |
6152 ('name', 'grades') | |
6153 | |
6154 """)) | |
6155 | |
6156 add_newdoc('numpy.core.multiarray', 'dtype', ('num', | |
6157 """ | |
6158 A unique number for each of the 21 different built-in types. | |
6159 | |
6160 These are roughly ordered from least-to-most precision. | |
6161 | |
6162 """)) | |
6163 | |
6164 add_newdoc('numpy.core.multiarray', 'dtype', ('shape', | |
6165 """ | |
6166 Shape tuple of the sub-array if this data type describes a sub-array, | |
6167 and ``()`` otherwise. | |
6168 | |
6169 """)) | |
6170 | |
6171 add_newdoc('numpy.core.multiarray', 'dtype', ('str', | |
6172 """The array-protocol typestring of this data-type object.""")) | |
6173 | |
6174 add_newdoc('numpy.core.multiarray', 'dtype', ('subdtype', | |
6175 """ | |
6176 Tuple ``(item_dtype, shape)`` if this `dtype` describes a sub-array, and | |
6177 None otherwise. | |
6178 | |
6179 The *shape* is the fixed shape of the sub-array described by this | |
6180 data type, and *item_dtype* the data type of the array. | |
6181 | |
6182 If a field whose dtype object has this attribute is retrieved, | |
6183 then the extra dimensions implied by *shape* are tacked on to | |
6184 the end of the retrieved array. | |
6185 | |
6186 """)) | |
6187 | |
6188 add_newdoc('numpy.core.multiarray', 'dtype', ('type', | |
6189 """The type object used to instantiate a scalar of this data-type.""")) | |
6190 | |
6191 ############################################################################## | |
6192 # | |
6193 # dtype methods | |
6194 # | |
6195 ############################################################################## | |
6196 | |
6197 add_newdoc('numpy.core.multiarray', 'dtype', ('newbyteorder', | |
6198 """ | |
6199 newbyteorder(new_order='S') | |
6200 | |
6201 Return a new dtype with a different byte order. | |
6202 | |
6203 Changes are also made in all fields and sub-arrays of the data type. | |
6204 | |
6205 Parameters | |
6206 ---------- | |
6207 new_order : string, optional | |
6208 Byte order to force; a value from the byte order | |
6209 specifications below. The default value ('S') results in | |
6210 swapping the current byte order. | |
6211 `new_order` codes can be any of:: | |
6212 | |
6213 * 'S' - swap dtype from current to opposite endian | |
6214 * {'<', 'L'} - little endian | |
6215 * {'>', 'B'} - big endian | |
6216 * {'=', 'N'} - native order | |
6217 * {'|', 'I'} - ignore (no change to byte order) | |
6218 | |
6219 The code does a case-insensitive check on the first letter of | |
6220 `new_order` for these alternatives. For example, any of '>' | |
6221 or 'B' or 'b' or 'brian' are valid to specify big-endian. | |
6222 | |
6223 Returns | |
6224 ------- | |
6225 new_dtype : dtype | |
6226 New dtype object with the given change to the byte order. | |
6227 | |
6228 Notes | |
6229 ----- | |
6230 Changes are also made in all fields and sub-arrays of the data type. | |
6231 | |
6232 Examples | |
6233 -------- | |
6234 >>> import sys | |
6235 >>> sys_is_le = sys.byteorder == 'little' | |
6236 >>> native_code = sys_is_le and '<' or '>' | |
6237 >>> swapped_code = sys_is_le and '>' or '<' | |
6238 >>> native_dt = np.dtype(native_code+'i2') | |
6239 >>> swapped_dt = np.dtype(swapped_code+'i2') | |
6240 >>> native_dt.newbyteorder('S') == swapped_dt | |
6241 True | |
6242 >>> native_dt.newbyteorder() == swapped_dt | |
6243 True | |
6244 >>> native_dt == swapped_dt.newbyteorder('S') | |
6245 True | |
6246 >>> native_dt == swapped_dt.newbyteorder('=') | |
6247 True | |
6248 >>> native_dt == swapped_dt.newbyteorder('N') | |
6249 True | |
6250 >>> native_dt == native_dt.newbyteorder('|') | |
6251 True | |
6252 >>> np.dtype('<i2') == native_dt.newbyteorder('<') | |
6253 True | |
6254 >>> np.dtype('<i2') == native_dt.newbyteorder('L') | |
6255 True | |
6256 >>> np.dtype('>i2') == native_dt.newbyteorder('>') | |
6257 True | |
6258 >>> np.dtype('>i2') == native_dt.newbyteorder('B') | |
6259 True | |
6260 | |
6261 """)) | |
6262 | |
6263 | |
6264 ############################################################################## | |
6265 # | |
6266 # Datetime-related Methods | |
6267 # | |
6268 ############################################################################## | |
6269 | |
6270 add_newdoc('numpy.core.multiarray', 'busdaycalendar', | |
6271 """ | |
6272 busdaycalendar(weekmask='1111100', holidays=None) | |
6273 | |
6274 A business day calendar object that efficiently stores information | |
6275 defining valid days for the busday family of functions. | |
6276 | |
6277 The default valid days are Monday through Friday ("business days"). | |
6278 A busdaycalendar object can be specified with any set of weekly | |
6279 valid days, plus an optional "holiday" dates that always will be invalid. | |
6280 | |
6281 Once a busdaycalendar object is created, the weekmask and holidays | |
6282 cannot be modified. | |
6283 | |
6284 .. versionadded:: 1.7.0 | |
6285 | |
6286 Parameters | |
6287 ---------- | |
6288 weekmask : str or array_like of bool, optional | |
6289 A seven-element array indicating which of Monday through Sunday are | |
6290 valid days. May be specified as a length-seven list or array, like | |
6291 [1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string | |
6292 like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for | |
6293 weekdays, optionally separated by white space. Valid abbreviations | |
6294 are: Mon Tue Wed Thu Fri Sat Sun | |
6295 holidays : array_like of datetime64[D], optional | |
6296 An array of dates to consider as invalid dates, no matter which | |
6297 weekday they fall upon. Holiday dates may be specified in any | |
6298 order, and NaT (not-a-time) dates are ignored. This list is | |
6299 saved in a normalized form that is suited for fast calculations | |
6300 of valid days. | |
6301 | |
6302 Returns | |
6303 ------- | |
6304 out : busdaycalendar | |
6305 A business day calendar object containing the specified | |
6306 weekmask and holidays values. | |
6307 | |
6308 See Also | |
6309 -------- | |
6310 is_busday : Returns a boolean array indicating valid days. | |
6311 busday_offset : Applies an offset counted in valid days. | |
6312 busday_count : Counts how many valid days are in a half-open date range. | |
6313 | |
6314 Attributes | |
6315 ---------- | |
6316 Note: once a busdaycalendar object is created, you cannot modify the | |
6317 weekmask or holidays. The attributes return copies of internal data. | |
6318 weekmask : (copy) seven-element array of bool | |
6319 holidays : (copy) sorted array of datetime64[D] | |
6320 | |
6321 Examples | |
6322 -------- | |
6323 >>> # Some important days in July | |
6324 ... bdd = np.busdaycalendar( | |
6325 ... holidays=['2011-07-01', '2011-07-04', '2011-07-17']) | |
6326 >>> # Default is Monday to Friday weekdays | |
6327 ... bdd.weekmask | |
6328 array([ True, True, True, True, True, False, False], dtype='bool') | |
6329 >>> # Any holidays already on the weekend are removed | |
6330 ... bdd.holidays | |
6331 array(['2011-07-01', '2011-07-04'], dtype='datetime64[D]') | |
6332 """) | |
6333 | |
6334 add_newdoc('numpy.core.multiarray', 'busdaycalendar', ('weekmask', | |
6335 """A copy of the seven-element boolean mask indicating valid days.""")) | |
6336 | |
6337 add_newdoc('numpy.core.multiarray', 'busdaycalendar', ('holidays', | |
6338 """A copy of the holiday array indicating additional invalid days.""")) | |
6339 | |
6340 add_newdoc('numpy.core.multiarray', 'is_busday', | |
6341 """ | |
6342 is_busday(dates, weekmask='1111100', holidays=None, busdaycal=None, out=None) | |
6343 | |
6344 Calculates which of the given dates are valid days, and which are not. | |
6345 | |
6346 .. versionadded:: 1.7.0 | |
6347 | |
6348 Parameters | |
6349 ---------- | |
6350 dates : array_like of datetime64[D] | |
6351 The array of dates to process. | |
6352 weekmask : str or array_like of bool, optional | |
6353 A seven-element array indicating which of Monday through Sunday are | |
6354 valid days. May be specified as a length-seven list or array, like | |
6355 [1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string | |
6356 like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for | |
6357 weekdays, optionally separated by white space. Valid abbreviations | |
6358 are: Mon Tue Wed Thu Fri Sat Sun | |
6359 holidays : array_like of datetime64[D], optional | |
6360 An array of dates to consider as invalid dates. They may be | |
6361 specified in any order, and NaT (not-a-time) dates are ignored. | |
6362 This list is saved in a normalized form that is suited for | |
6363 fast calculations of valid days. | |
6364 busdaycal : busdaycalendar, optional | |
6365 A `busdaycalendar` object which specifies the valid days. If this | |
6366 parameter is provided, neither weekmask nor holidays may be | |
6367 provided. | |
6368 out : array of bool, optional | |
6369 If provided, this array is filled with the result. | |
6370 | |
6371 Returns | |
6372 ------- | |
6373 out : array of bool | |
6374 An array with the same shape as ``dates``, containing True for | |
6375 each valid day, and False for each invalid day. | |
6376 | |
6377 See Also | |
6378 -------- | |
6379 busdaycalendar: An object that specifies a custom set of valid days. | |
6380 busday_offset : Applies an offset counted in valid days. | |
6381 busday_count : Counts how many valid days are in a half-open date range. | |
6382 | |
6383 Examples | |
6384 -------- | |
6385 >>> # The weekdays are Friday, Saturday, and Monday | |
6386 ... np.is_busday(['2011-07-01', '2011-07-02', '2011-07-18'], | |
6387 ... holidays=['2011-07-01', '2011-07-04', '2011-07-17']) | |
6388 array([False, False, True], dtype='bool') | |
6389 """) | |
6390 | |
6391 add_newdoc('numpy.core.multiarray', 'busday_offset', | |
6392 """ | |
6393 busday_offset(dates, offsets, roll='raise', weekmask='1111100', holidays=None, busdaycal=None, out=None) | |
6394 | |
6395 First adjusts the date to fall on a valid day according to | |
6396 the ``roll`` rule, then applies offsets to the given dates | |
6397 counted in valid days. | |
6398 | |
6399 .. versionadded:: 1.7.0 | |
6400 | |
6401 Parameters | |
6402 ---------- | |
6403 dates : array_like of datetime64[D] | |
6404 The array of dates to process. | |
6405 offsets : array_like of int | |
6406 The array of offsets, which is broadcast with ``dates``. | |
6407 roll : {'raise', 'nat', 'forward', 'following', 'backward', 'preceding', 'modifiedfollowing', 'modifiedpreceding'}, optional | |
6408 How to treat dates that do not fall on a valid day. The default | |
6409 is 'raise'. | |
6410 | |
6411 * 'raise' means to raise an exception for an invalid day. | |
6412 * 'nat' means to return a NaT (not-a-time) for an invalid day. | |
6413 * 'forward' and 'following' mean to take the first valid day | |
6414 later in time. | |
6415 * 'backward' and 'preceding' mean to take the first valid day | |
6416 earlier in time. | |
6417 * 'modifiedfollowing' means to take the first valid day | |
6418 later in time unless it is across a Month boundary, in which | |
6419 case to take the first valid day earlier in time. | |
6420 * 'modifiedpreceding' means to take the first valid day | |
6421 earlier in time unless it is across a Month boundary, in which | |
6422 case to take the first valid day later in time. | |
6423 weekmask : str or array_like of bool, optional | |
6424 A seven-element array indicating which of Monday through Sunday are | |
6425 valid days. May be specified as a length-seven list or array, like | |
6426 [1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string | |
6427 like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for | |
6428 weekdays, optionally separated by white space. Valid abbreviations | |
6429 are: Mon Tue Wed Thu Fri Sat Sun | |
6430 holidays : array_like of datetime64[D], optional | |
6431 An array of dates to consider as invalid dates. They may be | |
6432 specified in any order, and NaT (not-a-time) dates are ignored. | |
6433 This list is saved in a normalized form that is suited for | |
6434 fast calculations of valid days. | |
6435 busdaycal : busdaycalendar, optional | |
6436 A `busdaycalendar` object which specifies the valid days. If this | |
6437 parameter is provided, neither weekmask nor holidays may be | |
6438 provided. | |
6439 out : array of datetime64[D], optional | |
6440 If provided, this array is filled with the result. | |
6441 | |
6442 Returns | |
6443 ------- | |
6444 out : array of datetime64[D] | |
6445 An array with a shape from broadcasting ``dates`` and ``offsets`` | |
6446 together, containing the dates with offsets applied. | |
6447 | |
6448 See Also | |
6449 -------- | |
6450 busdaycalendar: An object that specifies a custom set of valid days. | |
6451 is_busday : Returns a boolean array indicating valid days. | |
6452 busday_count : Counts how many valid days are in a half-open date range. | |
6453 | |
6454 Examples | |
6455 -------- | |
6456 >>> # First business day in October 2011 (not accounting for holidays) | |
6457 ... np.busday_offset('2011-10', 0, roll='forward') | |
6458 numpy.datetime64('2011-10-03','D') | |
6459 >>> # Last business day in February 2012 (not accounting for holidays) | |
6460 ... np.busday_offset('2012-03', -1, roll='forward') | |
6461 numpy.datetime64('2012-02-29','D') | |
6462 >>> # Third Wednesday in January 2011 | |
6463 ... np.busday_offset('2011-01', 2, roll='forward', weekmask='Wed') | |
6464 numpy.datetime64('2011-01-19','D') | |
6465 >>> # 2012 Mother's Day in Canada and the U.S. | |
6466 ... np.busday_offset('2012-05', 1, roll='forward', weekmask='Sun') | |
6467 numpy.datetime64('2012-05-13','D') | |
6468 | |
6469 >>> # First business day on or after a date | |
6470 ... np.busday_offset('2011-03-20', 0, roll='forward') | |
6471 numpy.datetime64('2011-03-21','D') | |
6472 >>> np.busday_offset('2011-03-22', 0, roll='forward') | |
6473 numpy.datetime64('2011-03-22','D') | |
6474 >>> # First business day after a date | |
6475 ... np.busday_offset('2011-03-20', 1, roll='backward') | |
6476 numpy.datetime64('2011-03-21','D') | |
6477 >>> np.busday_offset('2011-03-22', 1, roll='backward') | |
6478 numpy.datetime64('2011-03-23','D') | |
6479 """) | |
6480 | |
6481 add_newdoc('numpy.core.multiarray', 'busday_count', | |
6482 """ | |
6483 busday_count(begindates, enddates, weekmask='1111100', holidays=[], busdaycal=None, out=None) | |
6484 | |
6485 Counts the number of valid days between `begindates` and | |
6486 `enddates`, not including the day of `enddates`. | |
6487 | |
6488 If ``enddates`` specifies a date value that is earlier than the | |
6489 corresponding ``begindates`` date value, the count will be negative. | |
6490 | |
6491 .. versionadded:: 1.7.0 | |
6492 | |
6493 Parameters | |
6494 ---------- | |
6495 begindates : array_like of datetime64[D] | |
6496 The array of the first dates for counting. | |
6497 enddates : array_like of datetime64[D] | |
6498 The array of the end dates for counting, which are excluded | |
6499 from the count themselves. | |
6500 weekmask : str or array_like of bool, optional | |
6501 A seven-element array indicating which of Monday through Sunday are | |
6502 valid days. May be specified as a length-seven list or array, like | |
6503 [1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string | |
6504 like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for | |
6505 weekdays, optionally separated by white space. Valid abbreviations | |
6506 are: Mon Tue Wed Thu Fri Sat Sun | |
6507 holidays : array_like of datetime64[D], optional | |
6508 An array of dates to consider as invalid dates. They may be | |
6509 specified in any order, and NaT (not-a-time) dates are ignored. | |
6510 This list is saved in a normalized form that is suited for | |
6511 fast calculations of valid days. | |
6512 busdaycal : busdaycalendar, optional | |
6513 A `busdaycalendar` object which specifies the valid days. If this | |
6514 parameter is provided, neither weekmask nor holidays may be | |
6515 provided. | |
6516 out : array of int, optional | |
6517 If provided, this array is filled with the result. | |
6518 | |
6519 Returns | |
6520 ------- | |
6521 out : array of int | |
6522 An array with a shape from broadcasting ``begindates`` and ``enddates`` | |
6523 together, containing the number of valid days between | |
6524 the begin and end dates. | |
6525 | |
6526 See Also | |
6527 -------- | |
6528 busdaycalendar: An object that specifies a custom set of valid days. | |
6529 is_busday : Returns a boolean array indicating valid days. | |
6530 busday_offset : Applies an offset counted in valid days. | |
6531 | |
6532 Examples | |
6533 -------- | |
6534 >>> # Number of weekdays in January 2011 | |
6535 ... np.busday_count('2011-01', '2011-02') | |
6536 21 | |
6537 >>> # Number of weekdays in 2011 | |
6538 ... np.busday_count('2011', '2012') | |
6539 260 | |
6540 >>> # Number of Saturdays in 2011 | |
6541 ... np.busday_count('2011', '2012', weekmask='Sat') | |
6542 53 | |
6543 """) | |
6544 | |
6545 ############################################################################## | |
6546 # | |
6547 # nd_grid instances | |
6548 # | |
6549 ############################################################################## | |
6550 | |
6551 add_newdoc('numpy.lib.index_tricks', 'mgrid', | |
6552 """ | |
6553 `nd_grid` instance which returns a dense multi-dimensional "meshgrid". | |
6554 | |
6555 An instance of `numpy.lib.index_tricks.nd_grid` which returns an dense | |
6556 (or fleshed out) mesh-grid when indexed, so that each returned argument | |
6557 has the same shape. The dimensions and number of the output arrays are | |
6558 equal to the number of indexing dimensions. If the step length is not a | |
6559 complex number, then the stop is not inclusive. | |
6560 | |
6561 However, if the step length is a **complex number** (e.g. 5j), then | |
6562 the integer part of its magnitude is interpreted as specifying the | |
6563 number of points to create between the start and stop values, where | |
6564 the stop value **is inclusive**. | |
6565 | |
6566 Returns | |
6567 ---------- | |
6568 mesh-grid `ndarrays` all of the same dimensions | |
6569 | |
6570 See Also | |
6571 -------- | |
6572 numpy.lib.index_tricks.nd_grid : class of `ogrid` and `mgrid` objects | |
6573 ogrid : like mgrid but returns open (not fleshed out) mesh grids | |
6574 r_ : array concatenator | |
6575 | |
6576 Examples | |
6577 -------- | |
6578 >>> np.mgrid[0:5,0:5] | |
6579 array([[[0, 0, 0, 0, 0], | |
6580 [1, 1, 1, 1, 1], | |
6581 [2, 2, 2, 2, 2], | |
6582 [3, 3, 3, 3, 3], | |
6583 [4, 4, 4, 4, 4]], | |
6584 [[0, 1, 2, 3, 4], | |
6585 [0, 1, 2, 3, 4], | |
6586 [0, 1, 2, 3, 4], | |
6587 [0, 1, 2, 3, 4], | |
6588 [0, 1, 2, 3, 4]]]) | |
6589 >>> np.mgrid[-1:1:5j] | |
6590 array([-1. , -0.5, 0. , 0.5, 1. ]) | |
6591 | |
6592 """) | |
6593 | |
6594 add_newdoc('numpy.lib.index_tricks', 'ogrid', | |
6595 """ | |
6596 `nd_grid` instance which returns an open multi-dimensional "meshgrid". | |
6597 | |
6598 An instance of `numpy.lib.index_tricks.nd_grid` which returns an open | |
6599 (i.e. not fleshed out) mesh-grid when indexed, so that only one dimension | |
6600 of each returned array is greater than 1. The dimension and number of the | |
6601 output arrays are equal to the number of indexing dimensions. If the step | |
6602 length is not a complex number, then the stop is not inclusive. | |
6603 | |
6604 However, if the step length is a **complex number** (e.g. 5j), then | |
6605 the integer part of its magnitude is interpreted as specifying the | |
6606 number of points to create between the start and stop values, where | |
6607 the stop value **is inclusive**. | |
6608 | |
6609 Returns | |
6610 ---------- | |
6611 mesh-grid `ndarrays` with only one dimension :math:`\\neq 1` | |
6612 | |
6613 See Also | |
6614 -------- | |
6615 np.lib.index_tricks.nd_grid : class of `ogrid` and `mgrid` objects | |
6616 mgrid : like `ogrid` but returns dense (or fleshed out) mesh grids | |
6617 r_ : array concatenator | |
6618 | |
6619 Examples | |
6620 -------- | |
6621 >>> from numpy import ogrid | |
6622 >>> ogrid[-1:1:5j] | |
6623 array([-1. , -0.5, 0. , 0.5, 1. ]) | |
6624 >>> ogrid[0:5,0:5] | |
6625 [array([[0], | |
6626 [1], | |
6627 [2], | |
6628 [3], | |
6629 [4]]), array([[0, 1, 2, 3, 4]])] | |
6630 | |
6631 """) | |
6632 | |
6633 | |
6634 ############################################################################## | |
6635 # | |
6636 # Documentation for `generic` attributes and methods | |
6637 # | |
6638 ############################################################################## | |
6639 | |
6640 add_newdoc('numpy.core.numerictypes', 'generic', | |
6641 """ | |
6642 Base class for numpy scalar types. | |
6643 | |
6644 Class from which most (all?) numpy scalar types are derived. For | |
6645 consistency, exposes the same API as `ndarray`, despite many | |
6646 consequent attributes being either "get-only," or completely irrelevant. | |
6647 This is the class from which it is strongly suggested users should derive | |
6648 custom scalar types. | |
6649 | |
6650 """) | |
6651 | |
6652 # Attributes | |
6653 | |
6654 add_newdoc('numpy.core.numerictypes', 'generic', ('T', | |
6655 """ | |
6656 Not implemented (virtual attribute) | |
6657 | |
6658 Class generic exists solely to derive numpy scalars from, and possesses, | |
6659 albeit unimplemented, all the attributes of the ndarray class so as to | |
6660 provide a uniform API. | |
6661 | |
6662 See Also | |
6663 -------- | |
6664 The corresponding attribute of the derived class of interest. | |
6665 | |
6666 """)) | |
6667 | |
6668 add_newdoc('numpy.core.numerictypes', 'generic', ('base', | |
6669 """ | |
6670 Not implemented (virtual attribute) | |
6671 | |
6672 Class generic exists solely to derive numpy scalars from, and possesses, | |
6673 albeit unimplemented, all the attributes of the ndarray class so as to | |
6674 a uniform API. | |
6675 | |
6676 See Also | |
6677 -------- | |
6678 The corresponding attribute of the derived class of interest. | |
6679 | |
6680 """)) | |
6681 | |
6682 add_newdoc('numpy.core.numerictypes', 'generic', ('data', | |
6683 """Pointer to start of data.""")) | |
6684 | |
6685 add_newdoc('numpy.core.numerictypes', 'generic', ('dtype', | |
6686 """Get array data-descriptor.""")) | |
6687 | |
6688 add_newdoc('numpy.core.numerictypes', 'generic', ('flags', | |
6689 """The integer value of flags.""")) | |
6690 | |
6691 add_newdoc('numpy.core.numerictypes', 'generic', ('flat', | |
6692 """A 1-D view of the scalar.""")) | |
6693 | |
6694 add_newdoc('numpy.core.numerictypes', 'generic', ('imag', | |
6695 """The imaginary part of the scalar.""")) | |
6696 | |
6697 add_newdoc('numpy.core.numerictypes', 'generic', ('itemsize', | |
6698 """The length of one element in bytes.""")) | |
6699 | |
6700 add_newdoc('numpy.core.numerictypes', 'generic', ('nbytes', | |
6701 """The length of the scalar in bytes.""")) | |
6702 | |
6703 add_newdoc('numpy.core.numerictypes', 'generic', ('ndim', | |
6704 """The number of array dimensions.""")) | |
6705 | |
6706 add_newdoc('numpy.core.numerictypes', 'generic', ('real', | |
6707 """The real part of the scalar.""")) | |
6708 | |
6709 add_newdoc('numpy.core.numerictypes', 'generic', ('shape', | |
6710 """Tuple of array dimensions.""")) | |
6711 | |
6712 add_newdoc('numpy.core.numerictypes', 'generic', ('size', | |
6713 """The number of elements in the gentype.""")) | |
6714 | |
6715 add_newdoc('numpy.core.numerictypes', 'generic', ('strides', | |
6716 """Tuple of bytes steps in each dimension.""")) | |
6717 | |
6718 # Methods | |
6719 | |
6720 add_newdoc('numpy.core.numerictypes', 'generic', ('all', | |
6721 """ | |
6722 Not implemented (virtual attribute) | |
6723 | |
6724 Class generic exists solely to derive numpy scalars from, and possesses, | |
6725 albeit unimplemented, all the attributes of the ndarray class | |
6726 so as to provide a uniform API. | |
6727 | |
6728 See Also | |
6729 -------- | |
6730 The corresponding attribute of the derived class of interest. | |
6731 | |
6732 """)) | |
6733 | |
6734 add_newdoc('numpy.core.numerictypes', 'generic', ('any', | |
6735 """ | |
6736 Not implemented (virtual attribute) | |
6737 | |
6738 Class generic exists solely to derive numpy scalars from, and possesses, | |
6739 albeit unimplemented, all the attributes of the ndarray class | |
6740 so as to provide a uniform API. | |
6741 | |
6742 See Also | |
6743 -------- | |
6744 The corresponding attribute of the derived class of interest. | |
6745 | |
6746 """)) | |
6747 | |
6748 add_newdoc('numpy.core.numerictypes', 'generic', ('argmax', | |
6749 """ | |
6750 Not implemented (virtual attribute) | |
6751 | |
6752 Class generic exists solely to derive numpy scalars from, and possesses, | |
6753 albeit unimplemented, all the attributes of the ndarray class | |
6754 so as to provide a uniform API. | |
6755 | |
6756 See Also | |
6757 -------- | |
6758 The corresponding attribute of the derived class of interest. | |
6759 | |
6760 """)) | |
6761 | |
6762 add_newdoc('numpy.core.numerictypes', 'generic', ('argmin', | |
6763 """ | |
6764 Not implemented (virtual attribute) | |
6765 | |
6766 Class generic exists solely to derive numpy scalars from, and possesses, | |
6767 albeit unimplemented, all the attributes of the ndarray class | |
6768 so as to provide a uniform API. | |
6769 | |
6770 See Also | |
6771 -------- | |
6772 The corresponding attribute of the derived class of interest. | |
6773 | |
6774 """)) | |
6775 | |
6776 add_newdoc('numpy.core.numerictypes', 'generic', ('argsort', | |
6777 """ | |
6778 Not implemented (virtual attribute) | |
6779 | |
6780 Class generic exists solely to derive numpy scalars from, and possesses, | |
6781 albeit unimplemented, all the attributes of the ndarray class | |
6782 so as to provide a uniform API. | |
6783 | |
6784 See Also | |
6785 -------- | |
6786 The corresponding attribute of the derived class of interest. | |
6787 | |
6788 """)) | |
6789 | |
6790 add_newdoc('numpy.core.numerictypes', 'generic', ('astype', | |
6791 """ | |
6792 Not implemented (virtual attribute) | |
6793 | |
6794 Class generic exists solely to derive numpy scalars from, and possesses, | |
6795 albeit unimplemented, all the attributes of the ndarray class | |
6796 so as to provide a uniform API. | |
6797 | |
6798 See Also | |
6799 -------- | |
6800 The corresponding attribute of the derived class of interest. | |
6801 | |
6802 """)) | |
6803 | |
6804 add_newdoc('numpy.core.numerictypes', 'generic', ('byteswap', | |
6805 """ | |
6806 Not implemented (virtual attribute) | |
6807 | |
6808 Class generic exists solely to derive numpy scalars from, and possesses, | |
6809 albeit unimplemented, all the attributes of the ndarray class so as to | |
6810 provide a uniform API. | |
6811 | |
6812 See Also | |
6813 -------- | |
6814 The corresponding attribute of the derived class of interest. | |
6815 | |
6816 """)) | |
6817 | |
6818 add_newdoc('numpy.core.numerictypes', 'generic', ('choose', | |
6819 """ | |
6820 Not implemented (virtual attribute) | |
6821 | |
6822 Class generic exists solely to derive numpy scalars from, and possesses, | |
6823 albeit unimplemented, all the attributes of the ndarray class | |
6824 so as to provide a uniform API. | |
6825 | |
6826 See Also | |
6827 -------- | |
6828 The corresponding attribute of the derived class of interest. | |
6829 | |
6830 """)) | |
6831 | |
6832 add_newdoc('numpy.core.numerictypes', 'generic', ('clip', | |
6833 """ | |
6834 Not implemented (virtual attribute) | |
6835 | |
6836 Class generic exists solely to derive numpy scalars from, and possesses, | |
6837 albeit unimplemented, all the attributes of the ndarray class | |
6838 so as to provide a uniform API. | |
6839 | |
6840 See Also | |
6841 -------- | |
6842 The corresponding attribute of the derived class of interest. | |
6843 | |
6844 """)) | |
6845 | |
6846 add_newdoc('numpy.core.numerictypes', 'generic', ('compress', | |
6847 """ | |
6848 Not implemented (virtual attribute) | |
6849 | |
6850 Class generic exists solely to derive numpy scalars from, and possesses, | |
6851 albeit unimplemented, all the attributes of the ndarray class | |
6852 so as to provide a uniform API. | |
6853 | |
6854 See Also | |
6855 -------- | |
6856 The corresponding attribute of the derived class of interest. | |
6857 | |
6858 """)) | |
6859 | |
6860 add_newdoc('numpy.core.numerictypes', 'generic', ('conjugate', | |
6861 """ | |
6862 Not implemented (virtual attribute) | |
6863 | |
6864 Class generic exists solely to derive numpy scalars from, and possesses, | |
6865 albeit unimplemented, all the attributes of the ndarray class | |
6866 so as to provide a uniform API. | |
6867 | |
6868 See Also | |
6869 -------- | |
6870 The corresponding attribute of the derived class of interest. | |
6871 | |
6872 """)) | |
6873 | |
6874 add_newdoc('numpy.core.numerictypes', 'generic', ('copy', | |
6875 """ | |
6876 Not implemented (virtual attribute) | |
6877 | |
6878 Class generic exists solely to derive numpy scalars from, and possesses, | |
6879 albeit unimplemented, all the attributes of the ndarray class | |
6880 so as to provide a uniform API. | |
6881 | |
6882 See Also | |
6883 -------- | |
6884 The corresponding attribute of the derived class of interest. | |
6885 | |
6886 """)) | |
6887 | |
6888 add_newdoc('numpy.core.numerictypes', 'generic', ('cumprod', | |
6889 """ | |
6890 Not implemented (virtual attribute) | |
6891 | |
6892 Class generic exists solely to derive numpy scalars from, and possesses, | |
6893 albeit unimplemented, all the attributes of the ndarray class | |
6894 so as to provide a uniform API. | |
6895 | |
6896 See Also | |
6897 -------- | |
6898 The corresponding attribute of the derived class of interest. | |
6899 | |
6900 """)) | |
6901 | |
6902 add_newdoc('numpy.core.numerictypes', 'generic', ('cumsum', | |
6903 """ | |
6904 Not implemented (virtual attribute) | |
6905 | |
6906 Class generic exists solely to derive numpy scalars from, and possesses, | |
6907 albeit unimplemented, all the attributes of the ndarray class | |
6908 so as to provide a uniform API. | |
6909 | |
6910 See Also | |
6911 -------- | |
6912 The corresponding attribute of the derived class of interest. | |
6913 | |
6914 """)) | |
6915 | |
6916 add_newdoc('numpy.core.numerictypes', 'generic', ('diagonal', | |
6917 """ | |
6918 Not implemented (virtual attribute) | |
6919 | |
6920 Class generic exists solely to derive numpy scalars from, and possesses, | |
6921 albeit unimplemented, all the attributes of the ndarray class | |
6922 so as to provide a uniform API. | |
6923 | |
6924 See Also | |
6925 -------- | |
6926 The corresponding attribute of the derived class of interest. | |
6927 | |
6928 """)) | |
6929 | |
6930 add_newdoc('numpy.core.numerictypes', 'generic', ('dump', | |
6931 """ | |
6932 Not implemented (virtual attribute) | |
6933 | |
6934 Class generic exists solely to derive numpy scalars from, and possesses, | |
6935 albeit unimplemented, all the attributes of the ndarray class | |
6936 so as to provide a uniform API. | |
6937 | |
6938 See Also | |
6939 -------- | |
6940 The corresponding attribute of the derived class of interest. | |
6941 | |
6942 """)) | |
6943 | |
6944 add_newdoc('numpy.core.numerictypes', 'generic', ('dumps', | |
6945 """ | |
6946 Not implemented (virtual attribute) | |
6947 | |
6948 Class generic exists solely to derive numpy scalars from, and possesses, | |
6949 albeit unimplemented, all the attributes of the ndarray class | |
6950 so as to provide a uniform API. | |
6951 | |
6952 See Also | |
6953 -------- | |
6954 The corresponding attribute of the derived class of interest. | |
6955 | |
6956 """)) | |
6957 | |
6958 add_newdoc('numpy.core.numerictypes', 'generic', ('fill', | |
6959 """ | |
6960 Not implemented (virtual attribute) | |
6961 | |
6962 Class generic exists solely to derive numpy scalars from, and possesses, | |
6963 albeit unimplemented, all the attributes of the ndarray class | |
6964 so as to provide a uniform API. | |
6965 | |
6966 See Also | |
6967 -------- | |
6968 The corresponding attribute of the derived class of interest. | |
6969 | |
6970 """)) | |
6971 | |
6972 add_newdoc('numpy.core.numerictypes', 'generic', ('flatten', | |
6973 """ | |
6974 Not implemented (virtual attribute) | |
6975 | |
6976 Class generic exists solely to derive numpy scalars from, and possesses, | |
6977 albeit unimplemented, all the attributes of the ndarray class | |
6978 so as to provide a uniform API. | |
6979 | |
6980 See Also | |
6981 -------- | |
6982 The corresponding attribute of the derived class of interest. | |
6983 | |
6984 """)) | |
6985 | |
6986 add_newdoc('numpy.core.numerictypes', 'generic', ('getfield', | |
6987 """ | |
6988 Not implemented (virtual attribute) | |
6989 | |
6990 Class generic exists solely to derive numpy scalars from, and possesses, | |
6991 albeit unimplemented, all the attributes of the ndarray class | |
6992 so as to provide a uniform API. | |
6993 | |
6994 See Also | |
6995 -------- | |
6996 The corresponding attribute of the derived class of interest. | |
6997 | |
6998 """)) | |
6999 | |
7000 add_newdoc('numpy.core.numerictypes', 'generic', ('item', | |
7001 """ | |
7002 Not implemented (virtual attribute) | |
7003 | |
7004 Class generic exists solely to derive numpy scalars from, and possesses, | |
7005 albeit unimplemented, all the attributes of the ndarray class | |
7006 so as to provide a uniform API. | |
7007 | |
7008 See Also | |
7009 -------- | |
7010 The corresponding attribute of the derived class of interest. | |
7011 | |
7012 """)) | |
7013 | |
7014 add_newdoc('numpy.core.numerictypes', 'generic', ('itemset', | |
7015 """ | |
7016 Not implemented (virtual attribute) | |
7017 | |
7018 Class generic exists solely to derive numpy scalars from, and possesses, | |
7019 albeit unimplemented, all the attributes of the ndarray class | |
7020 so as to provide a uniform API. | |
7021 | |
7022 See Also | |
7023 -------- | |
7024 The corresponding attribute of the derived class of interest. | |
7025 | |
7026 """)) | |
7027 | |
7028 add_newdoc('numpy.core.numerictypes', 'generic', ('max', | |
7029 """ | |
7030 Not implemented (virtual attribute) | |
7031 | |
7032 Class generic exists solely to derive numpy scalars from, and possesses, | |
7033 albeit unimplemented, all the attributes of the ndarray class | |
7034 so as to provide a uniform API. | |
7035 | |
7036 See Also | |
7037 -------- | |
7038 The corresponding attribute of the derived class of interest. | |
7039 | |
7040 """)) | |
7041 | |
7042 add_newdoc('numpy.core.numerictypes', 'generic', ('mean', | |
7043 """ | |
7044 Not implemented (virtual attribute) | |
7045 | |
7046 Class generic exists solely to derive numpy scalars from, and possesses, | |
7047 albeit unimplemented, all the attributes of the ndarray class | |
7048 so as to provide a uniform API. | |
7049 | |
7050 See Also | |
7051 -------- | |
7052 The corresponding attribute of the derived class of interest. | |
7053 | |
7054 """)) | |
7055 | |
7056 add_newdoc('numpy.core.numerictypes', 'generic', ('min', | |
7057 """ | |
7058 Not implemented (virtual attribute) | |
7059 | |
7060 Class generic exists solely to derive numpy scalars from, and possesses, | |
7061 albeit unimplemented, all the attributes of the ndarray class | |
7062 so as to provide a uniform API. | |
7063 | |
7064 See Also | |
7065 -------- | |
7066 The corresponding attribute of the derived class of interest. | |
7067 | |
7068 """)) | |
7069 | |
7070 add_newdoc('numpy.core.numerictypes', 'generic', ('newbyteorder', | |
7071 """ | |
7072 newbyteorder(new_order='S') | |
7073 | |
7074 Return a new `dtype` with a different byte order. | |
7075 | |
7076 Changes are also made in all fields and sub-arrays of the data type. | |
7077 | |
7078 The `new_order` code can be any from the following: | |
7079 | |
7080 * {'<', 'L'} - little endian | |
7081 * {'>', 'B'} - big endian | |
7082 * {'=', 'N'} - native order | |
7083 * 'S' - swap dtype from current to opposite endian | |
7084 * {'|', 'I'} - ignore (no change to byte order) | |
7085 | |
7086 Parameters | |
7087 ---------- | |
7088 new_order : str, optional | |
7089 Byte order to force; a value from the byte order specifications | |
7090 above. The default value ('S') results in swapping the current | |
7091 byte order. The code does a case-insensitive check on the first | |
7092 letter of `new_order` for the alternatives above. For example, | |
7093 any of 'B' or 'b' or 'biggish' are valid to specify big-endian. | |
7094 | |
7095 | |
7096 Returns | |
7097 ------- | |
7098 new_dtype : dtype | |
7099 New `dtype` object with the given change to the byte order. | |
7100 | |
7101 """)) | |
7102 | |
7103 add_newdoc('numpy.core.numerictypes', 'generic', ('nonzero', | |
7104 """ | |
7105 Not implemented (virtual attribute) | |
7106 | |
7107 Class generic exists solely to derive numpy scalars from, and possesses, | |
7108 albeit unimplemented, all the attributes of the ndarray class | |
7109 so as to provide a uniform API. | |
7110 | |
7111 See Also | |
7112 -------- | |
7113 The corresponding attribute of the derived class of interest. | |
7114 | |
7115 """)) | |
7116 | |
7117 add_newdoc('numpy.core.numerictypes', 'generic', ('prod', | |
7118 """ | |
7119 Not implemented (virtual attribute) | |
7120 | |
7121 Class generic exists solely to derive numpy scalars from, and possesses, | |
7122 albeit unimplemented, all the attributes of the ndarray class | |
7123 so as to provide a uniform API. | |
7124 | |
7125 See Also | |
7126 -------- | |
7127 The corresponding attribute of the derived class of interest. | |
7128 | |
7129 """)) | |
7130 | |
7131 add_newdoc('numpy.core.numerictypes', 'generic', ('ptp', | |
7132 """ | |
7133 Not implemented (virtual attribute) | |
7134 | |
7135 Class generic exists solely to derive numpy scalars from, and possesses, | |
7136 albeit unimplemented, all the attributes of the ndarray class | |
7137 so as to provide a uniform API. | |
7138 | |
7139 See Also | |
7140 -------- | |
7141 The corresponding attribute of the derived class of interest. | |
7142 | |
7143 """)) | |
7144 | |
7145 add_newdoc('numpy.core.numerictypes', 'generic', ('put', | |
7146 """ | |
7147 Not implemented (virtual attribute) | |
7148 | |
7149 Class generic exists solely to derive numpy scalars from, and possesses, | |
7150 albeit unimplemented, all the attributes of the ndarray class | |
7151 so as to provide a uniform API. | |
7152 | |
7153 See Also | |
7154 -------- | |
7155 The corresponding attribute of the derived class of interest. | |
7156 | |
7157 """)) | |
7158 | |
7159 add_newdoc('numpy.core.numerictypes', 'generic', ('ravel', | |
7160 """ | |
7161 Not implemented (virtual attribute) | |
7162 | |
7163 Class generic exists solely to derive numpy scalars from, and possesses, | |
7164 albeit unimplemented, all the attributes of the ndarray class | |
7165 so as to provide a uniform API. | |
7166 | |
7167 See Also | |
7168 -------- | |
7169 The corresponding attribute of the derived class of interest. | |
7170 | |
7171 """)) | |
7172 | |
7173 add_newdoc('numpy.core.numerictypes', 'generic', ('repeat', | |
7174 """ | |
7175 Not implemented (virtual attribute) | |
7176 | |
7177 Class generic exists solely to derive numpy scalars from, and possesses, | |
7178 albeit unimplemented, all the attributes of the ndarray class | |
7179 so as to provide a uniform API. | |
7180 | |
7181 See Also | |
7182 -------- | |
7183 The corresponding attribute of the derived class of interest. | |
7184 | |
7185 """)) | |
7186 | |
7187 add_newdoc('numpy.core.numerictypes', 'generic', ('reshape', | |
7188 """ | |
7189 Not implemented (virtual attribute) | |
7190 | |
7191 Class generic exists solely to derive numpy scalars from, and possesses, | |
7192 albeit unimplemented, all the attributes of the ndarray class | |
7193 so as to provide a uniform API. | |
7194 | |
7195 See Also | |
7196 -------- | |
7197 The corresponding attribute of the derived class of interest. | |
7198 | |
7199 """)) | |
7200 | |
7201 add_newdoc('numpy.core.numerictypes', 'generic', ('resize', | |
7202 """ | |
7203 Not implemented (virtual attribute) | |
7204 | |
7205 Class generic exists solely to derive numpy scalars from, and possesses, | |
7206 albeit unimplemented, all the attributes of the ndarray class | |
7207 so as to provide a uniform API. | |
7208 | |
7209 See Also | |
7210 -------- | |
7211 The corresponding attribute of the derived class of interest. | |
7212 | |
7213 """)) | |
7214 | |
7215 add_newdoc('numpy.core.numerictypes', 'generic', ('round', | |
7216 """ | |
7217 Not implemented (virtual attribute) | |
7218 | |
7219 Class generic exists solely to derive numpy scalars from, and possesses, | |
7220 albeit unimplemented, all the attributes of the ndarray class | |
7221 so as to provide a uniform API. | |
7222 | |
7223 See Also | |
7224 -------- | |
7225 The corresponding attribute of the derived class of interest. | |
7226 | |
7227 """)) | |
7228 | |
7229 add_newdoc('numpy.core.numerictypes', 'generic', ('searchsorted', | |
7230 """ | |
7231 Not implemented (virtual attribute) | |
7232 | |
7233 Class generic exists solely to derive numpy scalars from, and possesses, | |
7234 albeit unimplemented, all the attributes of the ndarray class | |
7235 so as to provide a uniform API. | |
7236 | |
7237 See Also | |
7238 -------- | |
7239 The corresponding attribute of the derived class of interest. | |
7240 | |
7241 """)) | |
7242 | |
7243 add_newdoc('numpy.core.numerictypes', 'generic', ('setfield', | |
7244 """ | |
7245 Not implemented (virtual attribute) | |
7246 | |
7247 Class generic exists solely to derive numpy scalars from, and possesses, | |
7248 albeit unimplemented, all the attributes of the ndarray class | |
7249 so as to provide a uniform API. | |
7250 | |
7251 See Also | |
7252 -------- | |
7253 The corresponding attribute of the derived class of interest. | |
7254 | |
7255 """)) | |
7256 | |
7257 add_newdoc('numpy.core.numerictypes', 'generic', ('setflags', | |
7258 """ | |
7259 Not implemented (virtual attribute) | |
7260 | |
7261 Class generic exists solely to derive numpy scalars from, and possesses, | |
7262 albeit unimplemented, all the attributes of the ndarray class so as to | |
7263 provide a uniform API. | |
7264 | |
7265 See Also | |
7266 -------- | |
7267 The corresponding attribute of the derived class of interest. | |
7268 | |
7269 """)) | |
7270 | |
7271 add_newdoc('numpy.core.numerictypes', 'generic', ('sort', | |
7272 """ | |
7273 Not implemented (virtual attribute) | |
7274 | |
7275 Class generic exists solely to derive numpy scalars from, and possesses, | |
7276 albeit unimplemented, all the attributes of the ndarray class | |
7277 so as to provide a uniform API. | |
7278 | |
7279 See Also | |
7280 -------- | |
7281 The corresponding attribute of the derived class of interest. | |
7282 | |
7283 """)) | |
7284 | |
7285 add_newdoc('numpy.core.numerictypes', 'generic', ('squeeze', | |
7286 """ | |
7287 Not implemented (virtual attribute) | |
7288 | |
7289 Class generic exists solely to derive numpy scalars from, and possesses, | |
7290 albeit unimplemented, all the attributes of the ndarray class | |
7291 so as to provide a uniform API. | |
7292 | |
7293 See Also | |
7294 -------- | |
7295 The corresponding attribute of the derived class of interest. | |
7296 | |
7297 """)) | |
7298 | |
7299 add_newdoc('numpy.core.numerictypes', 'generic', ('std', | |
7300 """ | |
7301 Not implemented (virtual attribute) | |
7302 | |
7303 Class generic exists solely to derive numpy scalars from, and possesses, | |
7304 albeit unimplemented, all the attributes of the ndarray class | |
7305 so as to provide a uniform API. | |
7306 | |
7307 See Also | |
7308 -------- | |
7309 The corresponding attribute of the derived class of interest. | |
7310 | |
7311 """)) | |
7312 | |
7313 add_newdoc('numpy.core.numerictypes', 'generic', ('sum', | |
7314 """ | |
7315 Not implemented (virtual attribute) | |
7316 | |
7317 Class generic exists solely to derive numpy scalars from, and possesses, | |
7318 albeit unimplemented, all the attributes of the ndarray class | |
7319 so as to provide a uniform API. | |
7320 | |
7321 See Also | |
7322 -------- | |
7323 The corresponding attribute of the derived class of interest. | |
7324 | |
7325 """)) | |
7326 | |
7327 add_newdoc('numpy.core.numerictypes', 'generic', ('swapaxes', | |
7328 """ | |
7329 Not implemented (virtual attribute) | |
7330 | |
7331 Class generic exists solely to derive numpy scalars from, and possesses, | |
7332 albeit unimplemented, all the attributes of the ndarray class | |
7333 so as to provide a uniform API. | |
7334 | |
7335 See Also | |
7336 -------- | |
7337 The corresponding attribute of the derived class of interest. | |
7338 | |
7339 """)) | |
7340 | |
7341 add_newdoc('numpy.core.numerictypes', 'generic', ('take', | |
7342 """ | |
7343 Not implemented (virtual attribute) | |
7344 | |
7345 Class generic exists solely to derive numpy scalars from, and possesses, | |
7346 albeit unimplemented, all the attributes of the ndarray class | |
7347 so as to provide a uniform API. | |
7348 | |
7349 See Also | |
7350 -------- | |
7351 The corresponding attribute of the derived class of interest. | |
7352 | |
7353 """)) | |
7354 | |
7355 add_newdoc('numpy.core.numerictypes', 'generic', ('tofile', | |
7356 """ | |
7357 Not implemented (virtual attribute) | |
7358 | |
7359 Class generic exists solely to derive numpy scalars from, and possesses, | |
7360 albeit unimplemented, all the attributes of the ndarray class | |
7361 so as to provide a uniform API. | |
7362 | |
7363 See Also | |
7364 -------- | |
7365 The corresponding attribute of the derived class of interest. | |
7366 | |
7367 """)) | |
7368 | |
7369 add_newdoc('numpy.core.numerictypes', 'generic', ('tolist', | |
7370 """ | |
7371 Not implemented (virtual attribute) | |
7372 | |
7373 Class generic exists solely to derive numpy scalars from, and possesses, | |
7374 albeit unimplemented, all the attributes of the ndarray class | |
7375 so as to provide a uniform API. | |
7376 | |
7377 See Also | |
7378 -------- | |
7379 The corresponding attribute of the derived class of interest. | |
7380 | |
7381 """)) | |
7382 | |
7383 add_newdoc('numpy.core.numerictypes', 'generic', ('tostring', | |
7384 """ | |
7385 Not implemented (virtual attribute) | |
7386 | |
7387 Class generic exists solely to derive numpy scalars from, and possesses, | |
7388 albeit unimplemented, all the attributes of the ndarray class | |
7389 so as to provide a uniform API. | |
7390 | |
7391 See Also | |
7392 -------- | |
7393 The corresponding attribute of the derived class of interest. | |
7394 | |
7395 """)) | |
7396 | |
7397 add_newdoc('numpy.core.numerictypes', 'generic', ('trace', | |
7398 """ | |
7399 Not implemented (virtual attribute) | |
7400 | |
7401 Class generic exists solely to derive numpy scalars from, and possesses, | |
7402 albeit unimplemented, all the attributes of the ndarray class | |
7403 so as to provide a uniform API. | |
7404 | |
7405 See Also | |
7406 -------- | |
7407 The corresponding attribute of the derived class of interest. | |
7408 | |
7409 """)) | |
7410 | |
7411 add_newdoc('numpy.core.numerictypes', 'generic', ('transpose', | |
7412 """ | |
7413 Not implemented (virtual attribute) | |
7414 | |
7415 Class generic exists solely to derive numpy scalars from, and possesses, | |
7416 albeit unimplemented, all the attributes of the ndarray class | |
7417 so as to provide a uniform API. | |
7418 | |
7419 See Also | |
7420 -------- | |
7421 The corresponding attribute of the derived class of interest. | |
7422 | |
7423 """)) | |
7424 | |
7425 add_newdoc('numpy.core.numerictypes', 'generic', ('var', | |
7426 """ | |
7427 Not implemented (virtual attribute) | |
7428 | |
7429 Class generic exists solely to derive numpy scalars from, and possesses, | |
7430 albeit unimplemented, all the attributes of the ndarray class | |
7431 so as to provide a uniform API. | |
7432 | |
7433 See Also | |
7434 -------- | |
7435 The corresponding attribute of the derived class of interest. | |
7436 | |
7437 """)) | |
7438 | |
7439 add_newdoc('numpy.core.numerictypes', 'generic', ('view', | |
7440 """ | |
7441 Not implemented (virtual attribute) | |
7442 | |
7443 Class generic exists solely to derive numpy scalars from, and possesses, | |
7444 albeit unimplemented, all the attributes of the ndarray class | |
7445 so as to provide a uniform API. | |
7446 | |
7447 See Also | |
7448 -------- | |
7449 The corresponding attribute of the derived class of interest. | |
7450 | |
7451 """)) | |
7452 | |
7453 | |
7454 ############################################################################## | |
7455 # | |
7456 # Documentation for other scalar classes | |
7457 # | |
7458 ############################################################################## | |
7459 | |
7460 add_newdoc('numpy.core.numerictypes', 'bool_', | |
7461 """Numpy's Boolean type. Character code: ``?``. Alias: bool8""") | |
7462 | |
7463 add_newdoc('numpy.core.numerictypes', 'complex64', | |
7464 """ | |
7465 Complex number type composed of two 32 bit floats. Character code: 'F'. | |
7466 | |
7467 """) | |
7468 | |
7469 add_newdoc('numpy.core.numerictypes', 'complex128', | |
7470 """ | |
7471 Complex number type composed of two 64 bit floats. Character code: 'D'. | |
7472 Python complex compatible. | |
7473 | |
7474 """) | |
7475 | |
7476 add_newdoc('numpy.core.numerictypes', 'complex256', | |
7477 """ | |
7478 Complex number type composed of two 128-bit floats. Character code: 'G'. | |
7479 | |
7480 """) | |
7481 | |
7482 add_newdoc('numpy.core.numerictypes', 'float32', | |
7483 """ | |
7484 32-bit floating-point number. Character code 'f'. C float compatible. | |
7485 | |
7486 """) | |
7487 | |
7488 add_newdoc('numpy.core.numerictypes', 'float64', | |
7489 """ | |
7490 64-bit floating-point number. Character code 'd'. Python float compatible. | |
7491 | |
7492 """) | |
7493 | |
7494 add_newdoc('numpy.core.numerictypes', 'float96', | |
7495 """ | |
7496 """) | |
7497 | |
7498 add_newdoc('numpy.core.numerictypes', 'float128', | |
7499 """ | |
7500 128-bit floating-point number. Character code: 'g'. C long float | |
7501 compatible. | |
7502 | |
7503 """) | |
7504 | |
7505 add_newdoc('numpy.core.numerictypes', 'int8', | |
7506 """8-bit integer. Character code ``b``. C char compatible.""") | |
7507 | |
7508 add_newdoc('numpy.core.numerictypes', 'int16', | |
7509 """16-bit integer. Character code ``h``. C short compatible.""") | |
7510 | |
7511 add_newdoc('numpy.core.numerictypes', 'int32', | |
7512 """32-bit integer. Character code 'i'. C int compatible.""") | |
7513 | |
7514 add_newdoc('numpy.core.numerictypes', 'int64', | |
7515 """64-bit integer. Character code 'l'. Python int compatible.""") | |
7516 | |
7517 add_newdoc('numpy.core.numerictypes', 'object_', | |
7518 """Any Python object. Character code: 'O'.""") |