Repository navigation
Expand file tree
/
Copy pathnp.indexing.gen.cs
More file actions
989 lines (952 loc) · 45.8 KB
/
Copy pathnp.indexing.gen.cs
File metadata and controls
989 lines (952 loc) · 45.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
// Copyright (c) 2019 by the SciSharp Team
// Code generated by CodeMinion: https://github.com/SciSharp/CodeMinion
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Python.Runtime;
using Python.Included;
using Numpy.Models;
namespace Numpy
{
public static partial class np
{
/// <summary>
/// Translates slice objects to concatenation along the first axis.
///
/// This is a simple way to build up arrays quickly. There are two use cases.
///
/// If slice notation is used, the syntax start:stop:step is equivalent
/// to np.arange(start, stop, step) inside of the brackets. However, if
/// step is an imaginary number (i.e. 100j) then its integer portion is
/// interpreted as a number-of-points desired and the start and stop are
/// inclusive. In other words start:stop:stepj is interpreted as
/// np.linspace(start, stop, step, endpoint=1) inside of the brackets.
/// After expansion of slice notation, all comma separated sequences are
/// concatenated together.
///
/// Optional character strings placed as the first element of the index
/// expression can be used to change the output. The strings ‘r’ or ‘c’ result
/// in matrix output. If the result is 1-D and ‘r’ is specified a 1 x N (row)
/// matrix is produced. If the result is 1-D and ‘c’ is specified, then a N x 1
/// (column) matrix is produced. If the result is 2-D then both provide the
/// same matrix result.
///
/// A string integer specifies which axis to stack multiple comma separated
/// arrays along. A string of two comma-separated integers allows indication
/// of the minimum number of dimensions to force each entry into as the
/// second integer (the axis to concatenate along is still the first integer).
///
/// A string with three comma-separated integers allows specification of the
/// axis to concatenate along, the minimum number of dimensions to force the
/// entries to, and which axis should contain the start of the arrays which
/// are less than the specified number of dimensions. In other words the third
/// integer allows you to specify where the 1’s should be placed in the shape
/// of the arrays that have their shapes upgraded. By default, they are placed
/// in the front of the shape tuple. The third argument allows you to specify
/// where the start of the array should be instead. Thus, a third argument of
/// ‘0’ would place the 1’s at the end of the array shape. Negative integers
/// specify where in the new shape tuple the last dimension of upgraded arrays
/// should be placed, so the default is ‘-1’.
/// </summary>
public static void r_()
=> NumPy.Instance.r_();
/// <summary>
/// A nicer way to build up index tuples for arrays.
///
/// For any index combination, including slicing and axis insertion,
/// a[indices] is the same as a[np.index_exp[indices]] for any
/// array a. However, np.index_exp[indices] can be used anywhere
/// in Python code and returns a tuple of slice objects that can be
/// used in the construction of complex index expressions.
///
/// Notes
///
/// You can do all this with slice() plus a few special objects,
/// but there’s a lot to remember and this version is simpler because
/// it uses the standard array indexing syntax.
/// </summary>
/// <param name="maketuple">
/// If True, always returns a tuple.
/// </param>
public static void s_(bool maketuple)
=> NumPy.Instance.s_(maketuple);
/// <summary>
/// Return the indices of the elements that are non-zero.
///
/// Returns a tuple of arrays, one for each dimension of a,
/// containing the indices of the non-zero elements in that
/// dimension. The values in a are always tested and returned in
/// row-major, C-style order. The corresponding non-zero
/// values can be obtained with:
///
/// To group the indices by element, rather than dimension, use:
///
/// The result of this is always a 2-D array, with a row for
/// each non-zero element.
/// </summary>
/// <param name="a">
/// Input array.
/// </param>
/// <returns>
/// Indices of elements that are non-zero.
/// </returns>
public static NDarray[] nonzero(NDarray a)
=> NumPy.Instance.nonzero(a);
/// <summary>
/// Return elements chosen from x or y depending on condition.
///
/// Notes
///
/// If all the arrays are 1-D, where is equivalent to:
/// </summary>
/// <param name="condition">
/// Where True, yield x, otherwise yield y.
/// </param>
/// <param name="y">
/// Values from which to choose. x, y and condition need to be
/// broadcastable to some shape.
/// </param>
/// <param name="x">
/// Values from which to choose. x, y and condition need to be
/// broadcastable to some shape.
/// </param>
/// <returns>
/// An array with elements from x where condition is True, and elements
/// from y elsewhere.
/// </returns>
public static NDarray @where(NDarray condition, NDarray y, NDarray x)
=> NumPy.Instance.@where(condition, y, x);
/// <summary>
/// Return an array representing the indices of a grid.
///
/// Compute an array where the subarrays contain index values 0,1,…
/// varying only along the corresponding axis.
///
/// Notes
///
/// The output shape is obtained by prepending the number of dimensions
/// in front of the tuple of dimensions, i.e. if dimensions is a tuple
/// (r0, ..., rN-1) of length N, the output shape is
/// (N,r0,...,rN-1).
///
/// The subarrays grid[k] contains the N-D array of indices along the
/// k-th axis. Explicitly:
/// </summary>
/// <param name="dimensions">
/// The shape of the grid.
/// </param>
/// <param name="dtype">
/// Data type of the result.
/// </param>
/// <returns>
/// The array of grid indices,
/// grid.shape = (len(dimensions),) + tuple(dimensions).
/// </returns>
public static NDarray indices(int[] dimensions, Dtype dtype = null)
=> NumPy.Instance.indices(dimensions, dtype:dtype);
/// <summary>
/// Construct an open mesh from multiple sequences.
///
/// This function takes N 1-D sequences and returns N outputs with N
/// dimensions each, such that the shape is 1 in all but one dimension
/// and the dimension with the non-unit shape value cycles through all
/// N dimensions.
///
/// Using ix_ one can quickly construct index arrays that will index
/// the cross product. a[np.ix_([1,3],[2,5])] returns the array
/// [[a[1,2] a[1,5]], [a[3,2] a[3,5]]].
/// </summary>
/// <param name="args">
/// Each sequence should be of integer or boolean type.
/// Boolean sequences will be interpreted as boolean masks for the
/// corresponding dimension (equivalent to passing in
/// np.nonzero(boolean_sequence)).
/// </param>
/// <returns>
/// N arrays with N dimensions each, with N the number of input
/// sequences. Together these arrays form an open mesh.
/// </returns>
public static NDarray[] ix_(NDarray[] args)
=> NumPy.Instance.ix_(args);
/*
/// <summary>
/// Converts a tuple of index arrays into an array of flat
/// indices, applying boundary modes to the multi-index.
///
/// Notes
/// </summary>
/// <param name="multi_index">
/// A tuple of integer arrays, one array for each dimension.
/// </param>
/// <param name="dims">
/// The shape of array into which the indices from multi_index apply.
/// </param>
/// <param name="mode">
/// Specifies how out-of-bounds indices are handled. Can specify
/// either one mode or a tuple of modes, one mode per index.
///
/// In ‘clip’ mode, a negative index which would normally
/// wrap will clip to 0 instead.
/// </param>
/// <param name="order">
/// Determines whether the multi-index should be viewed as
/// indexing in row-major (C-style) or column-major
/// (Fortran-style) order.
/// </param>
/// <returns>
/// An array of indices into the flattened version of an array
/// of dimensions dims.
/// </returns>
public static NDarray ravel_multi_index(tuple of array_like multi_index, tuple of ints dims, string mode = "raise", string order = null)
=> NumPy.Instance.ravel_multi_index(multi_index, dims, mode:mode, order:order);
*/
/// <summary>
/// Converts a flat index or array of flat indices into a tuple
/// of coordinate arrays.
/// </summary>
/// <param name="indices">
/// An integer array whose elements are indices into the flattened
/// version of an array of dimensions shape. Before version 1.6.0,
/// this function accepted just one index value.
/// </param>
/// <param name="shape">
/// The shape of the array to use for unraveling indices.
/// </param>
/// <param name="order">
/// Determines whether the indices should be viewed as indexing in
/// row-major (C-style) or column-major (Fortran-style) order.
/// </param>
/// <returns>
/// Each array in the tuple has the same shape as the indices
/// array.
/// </returns>
public static NDarray[] unravel_index(NDarray indices, Shape shape, string order = null)
=> NumPy.Instance.unravel_index(indices, shape, order:order);
/// <summary>
/// Return the indices to access the main diagonal of an array.
///
/// This returns a tuple of indices that can be used to access the main
/// diagonal of an array a with a.ndim >= 2 dimensions and shape
/// (n, n, …, n). For a.ndim = 2 this is the usual diagonal, for
/// a.ndim > 2 this is the set of indices to access a[i, i, ..., i]
/// for i = [0..n-1].
///
/// Notes
/// </summary>
/// <param name="n">
/// The size, along each dimension, of the arrays for which the returned
/// indices can be used.
/// </param>
/// <param name="ndim">
/// The number of dimensions.
/// </param>
public static void diag_indices(int n, int? ndim = 2)
=> NumPy.Instance.diag_indices(n, ndim:ndim);
/// <summary>
/// Return the indices to access the main diagonal of an n-dimensional array.
///
/// See diag_indices for full details.
///
/// Notes
/// </summary>
public static void diag_indices_from(NDarray arr)
=> NumPy.Instance.diag_indices_from(arr);
/// <summary>
/// Return the indices to access (n, n) arrays, given a masking function.
///
/// Assume mask_func is a function that, for a square array a of size
/// (n, n) with a possible offset argument k, when called as
/// mask_func(a, k) returns a new array with zeros in certain locations
/// (functions like triu or tril do precisely this). Then this function
/// returns the indices where the non-zero values would be located.
///
/// Notes
/// </summary>
/// <param name="n">
/// The returned indices will be valid to access arrays of shape (n, n).
/// </param>
/// <param name="mask_func">
/// A function whose call signature is similar to that of triu, tril.
/// That is, mask_func(x, k) returns a boolean array, shaped like x.
/// k is an optional argument to the function.
/// </param>
/// <param name="k">
/// An optional argument which is passed through to mask_func. Functions
/// like triu, tril take a second argument that is interpreted as an
/// offset.
/// </param>
/// <returns>
/// The n arrays of indices corresponding to the locations where
/// mask_func(np.ones((n, n)), k) is True.
/// </returns>
public static NDarray[] mask_indices(int n, Delegate mask_func, int k = 0)
=> NumPy.Instance.mask_indices(n, mask_func, k);
/// <summary>
/// Return the indices for the lower-triangle of an (n, m) array.
///
/// Notes
/// </summary>
/// <param name="n">
/// The row dimension of the arrays for which the returned
/// indices will be valid.
/// </param>
/// <param name="k">
/// Diagonal offset (see tril for details).
/// </param>
/// <param name="m">
/// The column dimension of the arrays for which the returned
/// arrays will be valid.
/// By default m is taken equal to n.
/// </param>
/// <returns>
/// The indices for the triangle. The returned tuple contains two arrays,
/// each with the indices along one dimension of the array.
/// </returns>
public static NDarray[] tril_indices(int n, int? k = 0, int? m = null)
=> NumPy.Instance.tril_indices(n, k:k, m:m);
/// <summary>
/// Return the indices for the lower-triangle of arr.
///
/// See tril_indices for full details.
///
/// Notes
/// </summary>
/// <param name="arr">
/// The indices will be valid for square arrays whose dimensions are
/// the same as arr.
/// </param>
/// <param name="k">
/// Diagonal offset (see tril for details).
/// </param>
public static void tril_indices_from(NDarray arr, int? k = 0)
=> NumPy.Instance.tril_indices_from(arr, k:k);
/// <summary>
/// Return the indices for the upper-triangle of an (n, m) array.
///
/// Notes
/// </summary>
/// <param name="n">
/// The size of the arrays for which the returned indices will
/// be valid.
/// </param>
/// <param name="k">
/// Diagonal offset (see triu for details).
/// </param>
/// <param name="m">
/// The column dimension of the arrays for which the returned
/// arrays will be valid.
/// By default m is taken equal to n.
/// </param>
/// <returns>
/// The indices for the triangle. The returned tuple contains two arrays,
/// each with the indices along one dimension of the array. Can be used
/// to slice a ndarray of shape(n, n).
/// </returns>
public static NDarray[] triu_indices(int n, int? k = 0, int? m = null)
=> NumPy.Instance.triu_indices(n, k:k, m:m);
/// <summary>
/// Return the indices for the upper-triangle of arr.
///
/// See triu_indices for full details.
///
/// Notes
/// </summary>
/// <param name="arr">
/// The indices will be valid for square arrays.
/// </param>
/// <param name="k">
/// Diagonal offset (see triu for details).
/// </param>
/// <returns>
/// Indices for the upper-triangle of arr.
/// </returns>
public static NDarray[] triu_indices_from(NDarray arr, int? k = 0)
=> NumPy.Instance.triu_indices_from(arr, k:k);
/// <summary>
/// Take elements from an array along an axis.
///
/// When axis is not None, this function does the same thing as “fancy”
/// indexing (indexing arrays using arrays); however, it can be easier to use
/// if you need elements along a given axis. A call such as
/// np.take(arr, indices, axis=3) is equivalent to
/// arr[:,:,:,indices,...].
///
/// Explained without fancy indexing, this is equivalent to the following use
/// of ndindex, which sets each of ii, jj, and kk to a tuple of
/// indices:
///
/// Notes
///
/// By eliminating the inner loop in the description above, and using s_ to
/// build simple slice objects, take can be expressed in terms of applying
/// fancy indexing to each 1-d slice:
///
/// For this reason, it is equivalent to (but faster than) the following use
/// of apply_along_axis:
/// </summary>
/// <param name="a">
/// The source array.
/// </param>
/// <param name="indices">
/// The indices of the values to extract.
///
/// Also allow scalars for indices.
/// </param>
/// <param name="axis">
/// The axis over which to select values. By default, the flattened
/// input array is used.
/// </param>
/// <param name="@out">
/// If provided, the result will be placed in this array. It should
/// be of the appropriate shape and dtype.
/// </param>
/// <param name="mode">
/// Specifies how out-of-bounds indices will behave.
///
/// ‘clip’ mode means that all indices that are too large are replaced
/// by the index that addresses the last element along that axis. Note
/// that this disables indexing with negative numbers.
/// </param>
/// <returns>
/// The returned array has the same type as a.
/// </returns>
public static NDarray take(NDarray[] a, NDarray[] indices, int? axis = null, NDarray @out = null, string mode = "raise")
=> NumPy.Instance.take(a, indices, axis:axis, @out:@out, mode:mode);
/// <summary>
/// Take values from the input array by matching 1d index and data slices.
///
/// This iterates over matching 1d slices oriented along the specified axis in
/// the index and data arrays, and uses the former to look up values in the
/// latter. These slices can be different lengths.
///
/// Functions returning an index along an axis, like argsort and
/// argpartition, produce suitable indices for this function.
///
/// Notes
///
/// This is equivalent to (but faster than) the following use of ndindex and
/// s_, which sets each of ii and kk to a tuple of indices:
///
/// Equivalently, eliminating the inner loop, the last two lines would be:
/// </summary>
/// <param name="arr">
/// Source array
/// </param>
/// <param name="indices">
/// Indices to take along each 1d slice of arr. This must match the
/// dimension of arr, but dimensions Ni and Nj only need to broadcast
/// against arr.
/// </param>
/// <param name="axis">
/// The axis to take 1d slices along. If axis is None, the input array is
/// treated as if it had first been flattened to 1d, for consistency with
/// sort and argsort.
/// </param>
public static void take_along_axis(NDarray arr, NDarray indices, int axis)
=> NumPy.Instance.take_along_axis(arr, indices, axis);
/// <summary>
/// Construct an array from an index array and a set of arrays to choose from.
///
/// First of all, if confused or uncertain, definitely look at the Examples -
/// in its full generality, this function is less simple than it might
/// seem from the following code description (below ndi =
/// numpy.lib.index_tricks):
///
/// np.choose(a,c) == np.array([c[a[I]][I] for I in ndi.ndindex(a.shape)]).
///
/// But this omits some subtleties. Here is a fully general summary:
///
/// Given an “index” array (a) of integers and a sequence of n arrays
/// (choices), a and each choice array are first broadcast, as necessary,
/// to arrays of a common shape; calling these Ba and Bchoices[i], i =
/// 0,…,n-1 we have that, necessarily, Ba.shape == Bchoices[i].shape
/// for each i. Then, a new array with shape Ba.shape is created as
/// follows:
///
/// Notes
///
/// To reduce the chance of misinterpretation, even though the following
/// “abuse” is nominally supported, choices should neither be, nor be
/// thought of as, a single array, i.e., the outermost sequence-like container
/// should be either a list or a tuple.
/// </summary>
/// <param name="a">
/// This array must contain integers in [0, n-1], where n is the number
/// of choices, unless mode=wrap or mode=clip, in which cases any
/// integers are permissible.
/// </param>
/// <param name="choices">
/// Choice arrays. a and all of the choices must be broadcastable to the
/// same shape. If choices is itself an array (not recommended), then
/// its outermost dimension (i.e., the one corresponding to
/// choices.shape[0]) is taken as defining the “sequence”.
/// </param>
/// <param name="@out">
/// If provided, the result will be inserted into this array. It should
/// be of the appropriate shape and dtype.
/// </param>
/// <param name="mode">
/// Specifies how indices outside [0, n-1] will be treated:
/// </param>
/// <returns>
/// The merged result.
/// </returns>
public static NDarray choose(NDarray<int> a, NDarray[] choices, NDarray @out = null, string mode = "raise")
=> NumPy.Instance.choose(a, choices, @out:@out, mode:mode);
/// <summary>
/// Return selected slices of an array along given axis.
///
/// When working along a given axis, a slice along that axis is returned in
/// output for each index where condition evaluates to True. When
/// working on a 1-D array, compress is equivalent to extract.
/// </summary>
/// <param name="condition">
/// Array that selects which entries to return. If len(condition)
/// is less than the size of a along the given axis, then output is
/// truncated to the length of the condition array.
/// </param>
/// <param name="a">
/// Array from which to extract a part.
/// </param>
/// <param name="axis">
/// Axis along which to take slices. If None (default), work on the
/// flattened array.
/// </param>
/// <param name="@out">
/// Output array. Its type is preserved and it must be of the right
/// shape to hold the output.
/// </param>
/// <returns>
/// A copy of a without the slices along axis for which condition
/// is false.
/// </returns>
public static NDarray compress(NDarray<bool> condition, NDarray a, int? axis = null, NDarray @out = null)
=> NumPy.Instance.compress(condition, a, axis:axis, @out:@out);
/// <summary>
/// Return specified diagonals.
///
/// If a is 2-D, returns the diagonal of a with the given offset,
/// i.e., the collection of elements of the form a[i, i+offset]. If
/// a has more than two dimensions, then the axes specified by axis1
/// and axis2 are used to determine the 2-D sub-array whose diagonal is
/// returned. The shape of the resulting array can be determined by
/// removing axis1 and axis2 and appending an index to the right equal
/// to the size of the resulting diagonals.
///
/// In versions of NumPy prior to 1.7, this function always returned a new,
/// independent array containing a copy of the values in the diagonal.
///
/// In NumPy 1.7 and 1.8, it continues to return a copy of the diagonal,
/// but depending on this fact is deprecated. Writing to the resulting
/// array continues to work as it used to, but a FutureWarning is issued.
///
/// Starting in NumPy 1.9 it returns a read-only view on the original array.
/// Attempting to write to the resulting array will produce an error.
///
/// In some future release, it will return a read/write view and writing to
/// the returned array will alter your original array. The returned array
/// will have the same type as the input array.
///
/// If you don’t write to the array returned by this function, then you can
/// just ignore all of the above.
///
/// If you depend on the current behavior, then we suggest copying the
/// returned array explicitly, i.e., use np.diagonal(a).copy() instead
/// of just np.diagonal(a). This will work with both past and future
/// versions of NumPy.
/// </summary>
/// <param name="a">
/// Array from which the diagonals are taken.
/// </param>
/// <param name="offset">
/// Offset of the diagonal from the main diagonal. Can be positive or
/// negative. Defaults to main diagonal (0).
/// </param>
/// <param name="axis1">
/// Axis to be used as the first axis of the 2-D sub-arrays from which
/// the diagonals should be taken. Defaults to first axis (0).
/// </param>
/// <param name="axis2">
/// Axis to be used as the second axis of the 2-D sub-arrays from
/// which the diagonals should be taken. Defaults to second axis (1).
/// </param>
/// <returns>
/// If a is 2-D, then a 1-D array containing the diagonal and of the
/// same type as a is returned unless a is a matrix, in which case
/// a 1-D array rather than a (2-D) matrix is returned in order to
/// maintain backward compatibility.
///
/// If a.ndim > 2, then the dimensions specified by axis1 and axis2
/// are removed, and a new axis inserted at the end corresponding to the
/// diagonal.
/// </returns>
public static NDarray diagonal(NDarray a, int? offset = 0, int? axis1 = 0, int? axis2 = 1)
=> NumPy.Instance.diagonal(a, offset:offset, axis1:axis1, axis2:axis2);
/// <summary>
/// Return an array drawn from elements in choicelist, depending on conditions.
/// </summary>
/// <param name="condlist">
/// The list of conditions which determine from which array in choicelist
/// the output elements are taken. When multiple conditions are satisfied,
/// the first one encountered in condlist is used.
/// </param>
/// <param name="choicelist">
/// The list of arrays from which the output elements are taken. It has
/// to be of the same length as condlist.
/// </param>
/// <param name="@default">
/// The element inserted in output when all conditions evaluate to False.
/// </param>
/// <returns>
/// The output at position m is the m-th element of the array in
/// choicelist where the m-th element of the corresponding array in
/// condlist is True.
/// </returns>
public static NDarray @select(NDarray<bool>[] condlist, NDarray[] choicelist, object @default = null)
=> NumPy.Instance.@select(condlist, choicelist, @default:@default);
public static partial class lib {
public static partial class stride_tricks {
/// <summary>
/// Create a view into the array with the given shape and strides.
///
/// Notes
///
/// as_strided creates a view into the array given the exact strides
/// and shape. This means it manipulates the internal data structure of
/// ndarray and, if done incorrectly, the array elements can point to
/// invalid memory and can corrupt results or crash your program.
/// It is advisable to always use the original x.strides when
/// calculating new strides to avoid reliance on a contiguous memory
/// layout.
///
/// Furthermore, arrays created with this function often contain self
/// overlapping memory, so that two elements are identical.
/// Vectorized write operations on such arrays will typically be
/// unpredictable. They may even give different results for small, large,
/// or transposed arrays.
/// Since writing to these arrays has to be tested and done with great
/// care, you may want to use writeable=False to avoid accidental write
/// operations.
///
/// For these reasons it is advisable to avoid as_strided when
/// possible.
/// </summary>
/// <param name="x">
/// Array to create a new.
/// </param>
/// <param name="shape">
/// The shape of the new array. Defaults to x.shape.
/// </param>
/// <param name="strides">
/// The strides of the new array. Defaults to x.strides.
/// </param>
/// <param name="subok">
/// If True, subclasses are preserved.
/// </param>
/// <param name="writeable">
/// If set to False, the returned array will always be readonly.
/// Otherwise it will be writable if the original array was. It
/// is advisable to set this to False if possible (see Notes).
/// </param>
public static NDarray as_strided(NDarray x, Shape shape = null, int[] strides = null, bool? subok = false, bool? writeable = true)
=> NumPy.Instance.lib_stride_tricks_as_strided(x, shape:shape, strides:strides, subok:subok, writeable:writeable);
}
}
/// <summary>
/// Change elements of an array based on conditional and input values.
///
/// Similar to np.copyto(arr, vals, where=mask), the difference is that
/// place uses the first N elements of vals, where N is the number of
/// True values in mask, while copyto uses the elements where mask
/// is True.
///
/// Note that extract does the exact opposite of place.
/// </summary>
/// <param name="arr">
/// Array to put data into.
/// </param>
/// <param name="mask">
/// Boolean mask array. Must have the same size as a.
/// </param>
/// <param name="vals">
/// Values to put into a. Only the first N elements are used, where
/// N is the number of True values in mask. If vals is smaller
/// than N, it will be repeated, and if elements of a are to be masked,
/// this sequence must be non-empty.
/// </param>
public static void place(NDarray arr, NDarray mask, NDarray vals)
=> NumPy.Instance.place(arr, mask, vals);
/// <summary>
/// Replaces specified elements of an array with given values.
///
/// The indexing works on the flattened target array. put is roughly
/// equivalent to:
/// </summary>
/// <param name="a">
/// Target array.
/// </param>
/// <param name="ind">
/// Target indices, interpreted as integers.
/// </param>
/// <param name="v">
/// Values to place in a at target indices. If v is shorter than
/// ind it will be repeated as necessary.
/// </param>
/// <param name="mode">
/// Specifies how out-of-bounds indices will behave.
///
/// ‘clip’ mode means that all indices that are too large are replaced
/// by the index that addresses the last element along that axis. Note
/// that this disables indexing with negative numbers.
/// </param>
public static void put(NDarray a, NDarray ind, NDarray v, string mode = "raise")
=> NumPy.Instance.put(a, ind, v, mode:mode);
/// <summary>
/// Put values into the destination array by matching 1d index and data slices.
///
/// This iterates over matching 1d slices oriented along the specified axis in
/// the index and data arrays, and uses the former to place values into the
/// latter. These slices can be different lengths.
///
/// Functions returning an index along an axis, like argsort and
/// argpartition, produce suitable indices for this function.
///
/// Notes
///
/// This is equivalent to (but faster than) the following use of ndindex and
/// s_, which sets each of ii and kk to a tuple of indices:
///
/// Equivalently, eliminating the inner loop, the last two lines would be:
/// </summary>
/// <param name="arr">
/// Destination array.
/// </param>
/// <param name="indices">
/// Indices to change along each 1d slice of arr. This must match the
/// dimension of arr, but dimensions in Ni and Nj may be 1 to broadcast
/// against arr.
/// </param>
/// <param name="values">
/// values to insert at those indices. Its shape and dimension are
/// broadcast to match that of indices.
/// </param>
/// <param name="axis">
/// The axis to take 1d slices along. If axis is None, the destination
/// array is treated as if a flattened 1d view had been created of it.
/// </param>
public static void put_along_axis(NDarray arr, NDarray indices, NDarray[] values, int axis)
=> NumPy.Instance.put_along_axis(arr, indices, values, axis);
/// <summary>
/// Changes elements of an array based on conditional and input values.
///
/// Sets a.flat[n] = values[n] for each n where mask.flat[n]==True.
///
/// If values is not the same size as a and mask then it will repeat.
/// This gives behavior different from a[mask] = values.
/// </summary>
/// <param name="a">
/// Target array.
/// </param>
/// <param name="mask">
/// Boolean mask array. It has to be the same shape as a.
/// </param>
/// <param name="values">
/// Values to put into a where mask is True. If values is smaller
/// than a it will be repeated.
/// </param>
public static void putmask(NDarray a, NDarray mask, NDarray values)
=> NumPy.Instance.putmask(a, mask, values);
/// <summary>
/// Fill the main diagonal of the given array of any dimensionality.
///
/// For an array a with a.ndim >= 2, the diagonal is the list of
/// locations with indices a[i, ..., i] all identical. This function
/// modifies the input array in-place, it does not return a value.
///
/// Notes
///
/// This functionality can be obtained via diag_indices, but internally
/// this version uses a much faster implementation that never constructs the
/// indices and uses simple slicing.
/// </summary>
/// <param name="a">
/// Array whose diagonal is to be filled, it gets modified in-place.
/// </param>
/// <param name="val">
/// Value to be written on the diagonal, its type must be compatible with
/// that of the array a.
/// </param>
/// <param name="wrap">
/// For tall matrices in NumPy version up to 1.6.2, the
/// diagonal “wrapped” after N columns. You can have this behavior
/// with this option. This affects only tall matrices.
/// </param>
public static void fill_diagonal(NDarray a, ValueType val, bool wrap = false)
=> NumPy.Instance.fill_diagonal(a, val, wrap);
/*
/// <summary>
/// Efficient multi-dimensional iterator object to iterate over arrays.
/// To get started using this object, see the
/// introductory guide to array iteration.
///
/// Notes
///
/// nditer supersedes flatiter. The iterator implementation behind
/// nditer is also exposed by the NumPy C API.
///
/// The Python exposure supplies two iteration interfaces, one which follows
/// the Python iterator protocol, and another which mirrors the C-style
/// do-while pattern. The native Python approach is better in most cases, but
/// if you need the iterator’s coordinates or index, use the C-style pattern.
/// </summary>
/// <param name="op">
/// The array(s) to iterate over.
/// </param>
/// <param name="flags">
/// Flags to control the behavior of the iterator.
/// </param>
/// <param name="op_flags">
/// This is a list of flags for each operand. At minimum, one of
/// “readonly”, “readwrite”, or “writeonly” must be specified.
/// </param>
/// <param name="op_dtypes">
/// The required data type(s) of the operands. If copying or buffering
/// is enabled, the data will be converted to/from their original types.
/// </param>
/// <param name="order">
/// Controls the iteration order. ‘C’ means C order, ‘F’ means
/// Fortran order, ‘A’ means ‘F’ order if all the arrays are Fortran
/// contiguous, ‘C’ order otherwise, and ‘K’ means as close to the
/// order the array elements appear in memory as possible. This also
/// affects the element memory order of “allocate” operands, as they
/// are allocated to be compatible with iteration order.
/// Default is ‘K’.
/// </param>
/// <param name="casting">
/// Controls what kind of data casting may occur when making a copy
/// or buffering. Setting this to ‘unsafe’ is not recommended,
/// as it can adversely affect accumulations.
/// </param>
/// <param name="op_axes">
/// If provided, is a list of ints or None for each operands.
/// The list of axes for an operand is a mapping from the dimensions
/// of the iterator to the dimensions of the operand. A value of
/// -1 can be placed for entries, causing that dimension to be
/// treated as “newaxis”.
/// </param>
/// <param name="itershape">
/// The desired shape of the iterator. This allows “allocate” operands
/// with a dimension mapped by op_axes not corresponding to a dimension
/// of a different operand to get a value not equal to 1 for that
/// dimension.
/// </param>
/// <param name="buffersize">
/// When buffering is enabled, controls the size of the temporary
/// buffers. Set to 0 for the default value.
/// </param>
public static void nditer(NDarray op, string[] flags = null, list of list of str op_flags = null, dtype or tuple of dtype(s) op_dtypes = null, string order = null, string casting = null, list of list of ints op_axes = null, tuple of ints itershape = null, int? buffersize = null)
=> NumPy.Instance.nditer(op, flags:flags, op_flags:op_flags, op_dtypes:op_dtypes, order:order, casting:casting, op_axes:op_axes, itershape:itershape, buffersize:buffersize);
*/
/// <summary>
/// Multidimensional index iterator.
///
/// Return an iterator yielding pairs of array coordinates and values.
/// </summary>
/// <param name="arr">
/// Input array.
/// </param>
public static void ndenumerate(NDarray arr)
=> NumPy.Instance.ndenumerate(arr);
/// <summary>
/// An N-dimensional iterator object to index arrays.
///
/// Given the shape of an array, an ndindex instance iterates over
/// the N-dimensional index of the array. At each iteration a tuple
/// of indices is returned, the last dimension is iterated over first.
/// </summary>
/// <param name="args">
/// The size of each dimension of the array.
/// </param>
public static void ndindex(int[] args)
=> NumPy.Instance.ndindex(args);
/*
/// <summary>
/// Create nditers for use in nested loops
///
/// Create a tuple of nditer objects which iterate in nested loops over
/// different axes of the op argument. The first iterator is used in the
/// outermost loop, the last in the innermost loop. Advancing one will change
/// the subsequent iterators to point at its new element.
/// </summary>
/// <param name="op">
/// The array(s) to iterate over.
/// </param>
/// <param name="axes">
/// Each item is used as an “op_axes” argument to an nditer
/// </param>
/// <returns>
/// An nditer for each item in axes, outermost first
/// </returns>
public static tuple of nditer nested_iters(NDarray op, int[] axes = null)
=> NumPy.Instance.nested_iters(op, axes);
*/
/// <summary>
/// Flat iterator object to iterate over arrays.
///
/// A flatiter iterator is returned by x.flat for any array x.
/// It allows iterating over the array as if it were a 1-D array,
/// either in a for-loop or by calling its next method.
///
/// Iteration is done in row-major, C-style order (the last
/// index varying the fastest). The iterator can also be indexed using
/// basic slicing or advanced indexing.
///
/// Notes
///
/// A flatiter iterator can not be constructed directly from Python code
/// by calling the flatiter constructor.
/// </summary>
public static void flatiter()
=> NumPy.Instance.flatiter();
public static partial class lib {
/// <summary>
/// Buffered iterator for big arrays.
///
/// Arrayterator creates a buffered iterator for reading big arrays in small
/// contiguous blocks. The class is useful for objects stored in the
/// file system. It allows iteration over the object without reading
/// everything in memory; instead, small blocks are read and iterated over.
///
/// Arrayterator can be used with any object that supports multidimensional
/// slices. This includes NumPy arrays, but also variables from
/// Scientific.IO.NetCDF or pynetcdf for example.
///
/// Notes
///
/// The algorithm works by first finding a “running dimension”, along which
/// the blocks will be extracted. Given an array of dimensions
/// (d1, d2, ..., dn), e.g. if buf_size is smaller than d1, the
/// first dimension will be used. If, on the other hand,
/// d1 < buf_size < d1*d2 the second dimension will be used, and so on.
/// Blocks are extracted along this dimension, and when the last block is
/// returned the process continues from the next dimension, until all
/// elements have been read.
/// </summary>
/// <param name="@var">
/// The object to iterate over.
/// </param>
/// <param name="buf_size">
/// The buffer size. If buf_size is supplied, the maximum amount of
/// data that will be read into memory is buf_size elements.
/// Default is None, which will read as many element as possible
/// into memory.
/// </param>
public static void Arrayterator(NDarray @var, int? buf_size = null)
=> NumPy.Instance.lib_Arrayterator(@var, buf_size:buf_size);
}
}
}