forked from SciSharp/Numpy.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumPy.indexing.gen.cs
More file actions
1466 lines (1430 loc) · 59.7 KB
/
NumPy.indexing.gen.cs
File metadata and controls
1466 lines (1430 loc) · 59.7 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
990
991
992
993
994
995
996
997
998
999
1000
// 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 Numpy.Models;
using Python.Included;
namespace Numpy
{
public partial class NumPy
{
/// <summary>
/// Translates slice objects to concatenation along the first axis.<br></br>
///
/// This is a simple way to build up arrays quickly.<br></br>
/// There are two use cases.<br></br>
///
/// If slice notation is used, the syntax start:stop:step is equivalent
/// to np.arange(start, stop, step) inside of the brackets.<br></br>
/// However, if
/// step is an imaginary number (i.e.<br></br>
/// 100j) then its integer portion is
/// interpreted as a number-of-points desired and the start and stop are
/// inclusive.<br></br>
/// In other words start:stop:stepj is interpreted as
/// np.linspace(start, stop, step, endpoint=1) inside of the brackets.<br></br>
///
/// After expansion of slice notation, all comma separated sequences are
/// concatenated together.<br></br>
///
/// Optional character strings placed as the first element of the index
/// expression can be used to change the output.<br></br>
/// The strings ‘r’ or ‘c’ result
/// in matrix output.<br></br>
/// If the result is 1-D and ‘r’ is specified a 1 x N (row)
/// matrix is produced.<br></br>
/// If the result is 1-D and ‘c’ is specified, then a N x 1
/// (column) matrix is produced.<br></br>
/// If the result is 2-D then both provide the
/// same matrix result.<br></br>
///
/// A string integer specifies which axis to stack multiple comma separated
/// arrays along.<br></br>
/// 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).<br></br>
///
/// 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.<br></br>
/// 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.<br></br>
/// By default, they are placed
/// in the front of the shape tuple.<br></br>
/// The third argument allows you to specify
/// where the start of the array should be instead.<br></br>
/// Thus, a third argument of
/// ‘0’ would place the 1’s at the end of the array shape.<br></br>
/// 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 void r_()
{
//auto-generated code, do not change
var __self__=self;
dynamic py = __self__.InvokeMethod("r_");
}
/// <summary>
/// A nicer way to build up index tuples for arrays.<br></br>
///
/// For any index combination, including slicing and axis insertion,
/// a[indices] is the same as a[np.index_exp[indices]] for any
/// array a.<br></br>
/// 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.<br></br>
///
/// 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 void s_(bool maketuple)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
maketuple,
});
var kwargs=new PyDict();
dynamic py = __self__.InvokeMethod("s_", pyargs, kwargs);
}
/// <summary>
/// Return the indices of the elements that are non-zero.<br></br>
///
/// Returns a tuple of arrays, one for each dimension of a,
/// containing the indices of the non-zero elements in that
/// dimension.<br></br>
/// The values in a are always tested and returned in
/// row-major, C-style order.<br></br>
/// 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 NDarray[] nonzero(NDarray a)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
a,
});
var kwargs=new PyDict();
dynamic py = __self__.InvokeMethod("nonzero", pyargs, kwargs);
return ToCsharp<NDarray[]>(py);
}
/// <summary>
/// Return elements chosen from x or y depending on condition.<br></br>
///
/// 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.<br></br>
/// x, y and condition need to be
/// broadcastable to some shape.
/// </param>
/// <param name="x">
/// Values from which to choose.<br></br>
/// 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 NDarray @where(NDarray condition, NDarray y, NDarray x)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
condition,
y,
x,
});
var kwargs=new PyDict();
dynamic py = __self__.InvokeMethod("where", pyargs, kwargs);
return ToCsharp<NDarray>(py);
}
/// <summary>
/// Return an array representing the indices of a grid.<br></br>
///
/// Compute an array where the subarrays contain index values 0,1,…
/// varying only along the corresponding axis.<br></br>
///
/// Notes
///
/// The output shape is obtained by prepending the number of dimensions
/// in front of the tuple of dimensions, i.e.<br></br>
/// if dimensions is a tuple
/// (r0, ..., rN-1) of length N, the output shape is
/// (N,r0,...,rN-1).<br></br>
///
/// The subarrays grid[k] contains the N-D array of indices along the
/// k-th axis.<br></br>
/// 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 NDarray indices(int[] dimensions, Dtype dtype = null)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
dimensions,
});
var kwargs=new PyDict();
if (dtype!=null) kwargs["dtype"]=ToPython(dtype);
dynamic py = __self__.InvokeMethod("indices", pyargs, kwargs);
return ToCsharp<NDarray>(py);
}
/// <summary>
/// Construct an open mesh from multiple sequences.<br></br>
///
/// 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.<br></br>
///
/// Using ix_ one can quickly construct index arrays that will index
/// the cross product.<br></br>
/// 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.<br></br>
///
/// 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.<br></br>
/// Together these arrays form an open mesh.
/// </returns>
public NDarray[] ix_(params NDarray[] args)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
args,
});
var kwargs=new PyDict();
dynamic py = __self__.InvokeMethod("ix_", pyargs, kwargs);
return ToCsharp<NDarray[]>(py);
}
/*
/// <summary>
/// Converts a tuple of index arrays into an array of flat
/// indices, applying boundary modes to the multi-index.<br></br>
///
/// 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.<br></br>
/// Can specify
/// either one mode or a tuple of modes, one mode per index.<br></br>
///
/// 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 NDarray ravel_multi_index(tuple of array_like multi_index, tuple of ints dims, string mode = "raise", string order = null)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
multi_index,
dims,
});
var kwargs=new PyDict();
if (mode!="raise") kwargs["mode"]=ToPython(mode);
if (order!=null) kwargs["order"]=ToPython(order);
dynamic py = __self__.InvokeMethod("ravel_multi_index", pyargs, kwargs);
return ToCsharp<NDarray>(py);
}
*/
/// <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.<br></br>
/// 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 NDarray[] unravel_index(NDarray indices, Shape shape, string order = null)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
indices,
shape,
});
var kwargs=new PyDict();
if (order!=null) kwargs["order"]=ToPython(order);
dynamic py = __self__.InvokeMethod("unravel_index", pyargs, kwargs);
return ToCsharp<NDarray[]>(py);
}
/// <summary>
/// Return the indices to access the main diagonal of an array.<br></br>
///
/// 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).<br></br>
/// 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].<br></br>
///
/// 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 void diag_indices(int n, int? ndim = 2)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
n,
});
var kwargs=new PyDict();
if (ndim!=2) kwargs["ndim"]=ToPython(ndim);
dynamic py = __self__.InvokeMethod("diag_indices", pyargs, kwargs);
}
/// <summary>
/// Return the indices to access the main diagonal of an n-dimensional array.<br></br>
///
/// See diag_indices for full details.<br></br>
///
/// Notes
/// </summary>
public void diag_indices_from(NDarray arr)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
arr,
});
var kwargs=new PyDict();
dynamic py = __self__.InvokeMethod("diag_indices_from", pyargs, kwargs);
}
/// <summary>
/// Return the indices to access (n, n) arrays, given a masking function.<br></br>
///
/// 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).<br></br>
/// Then this function
/// returns the indices where the non-zero values would be located.<br></br>
///
/// 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.<br></br>
///
/// That is, mask_func(x, k) returns a boolean array, shaped like x.<br></br>
///
/// k is an optional argument to the function.
/// </param>
/// <param name="k">
/// An optional argument which is passed through to mask_func.<br></br>
/// 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 NDarray[] mask_indices(int n, Delegate mask_func, int k = 0)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
n,
mask_func,
});
var kwargs=new PyDict();
if (k!=0) kwargs["k"]=ToPython(k);
dynamic py = __self__.InvokeMethod("mask_indices", pyargs, kwargs);
return ToCsharp<NDarray[]>(py);
}
/// <summary>
/// Return the indices for the lower-triangle of an (n, m) array.<br></br>
///
/// 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.<br></br>
///
/// By default m is taken equal to n.
/// </param>
/// <returns>
/// The indices for the triangle.<br></br>
/// The returned tuple contains two arrays,
/// each with the indices along one dimension of the array.
/// </returns>
public NDarray[] tril_indices(int n, int? k = 0, int? m = null)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
n,
});
var kwargs=new PyDict();
if (k!=0) kwargs["k"]=ToPython(k);
if (m!=null) kwargs["m"]=ToPython(m);
dynamic py = __self__.InvokeMethod("tril_indices", pyargs, kwargs);
return ToCsharp<NDarray[]>(py);
}
/// <summary>
/// Return the indices for the lower-triangle of arr.<br></br>
///
/// See tril_indices for full details.<br></br>
///
/// 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 void tril_indices_from(NDarray arr, int? k = 0)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
arr,
});
var kwargs=new PyDict();
if (k!=0) kwargs["k"]=ToPython(k);
dynamic py = __self__.InvokeMethod("tril_indices_from", pyargs, kwargs);
}
/// <summary>
/// Return the indices for the upper-triangle of an (n, m) array.<br></br>
///
/// 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.<br></br>
///
/// By default m is taken equal to n.
/// </param>
/// <returns>
/// The indices for the triangle.<br></br>
/// The returned tuple contains two arrays,
/// each with the indices along one dimension of the array.<br></br>
/// Can be used
/// to slice a ndarray of shape(n, n).
/// </returns>
public NDarray[] triu_indices(int n, int? k = 0, int? m = null)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
n,
});
var kwargs=new PyDict();
if (k!=0) kwargs["k"]=ToPython(k);
if (m!=null) kwargs["m"]=ToPython(m);
dynamic py = __self__.InvokeMethod("triu_indices", pyargs, kwargs);
return ToCsharp<NDarray[]>(py);
}
/// <summary>
/// Return the indices for the upper-triangle of arr.<br></br>
///
/// See triu_indices for full details.<br></br>
///
/// 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 NDarray[] triu_indices_from(NDarray arr, int? k = 0)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
arr,
});
var kwargs=new PyDict();
if (k!=0) kwargs["k"]=ToPython(k);
dynamic py = __self__.InvokeMethod("triu_indices_from", pyargs, kwargs);
return ToCsharp<NDarray[]>(py);
}
/// <summary>
/// Take elements from an array along an axis.<br></br>
///
/// 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.<br></br>
/// A call such as
/// np.take(arr, indices, axis=3) is equivalent to
/// arr[:,:,:,indices,...].<br></br>
///
/// 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.<br></br>
///
/// Also allow scalars for indices.
/// </param>
/// <param name="axis">
/// The axis over which to select values.<br></br>
/// By default, the flattened
/// input array is used.
/// </param>
/// <param name="out">
/// If provided, the result will be placed in this array.<br></br>
/// It should
/// be of the appropriate shape and dtype.
/// </param>
/// <param name="mode">
/// Specifies how out-of-bounds indices will behave.<br></br>
///
/// ‘clip’ mode means that all indices that are too large are replaced
/// by the index that addresses the last element along that axis.<br></br>
/// Note
/// that this disables indexing with negative numbers.
/// </param>
/// <returns>
/// The returned array has the same type as a.
/// </returns>
public NDarray take(NDarray[] a, NDarray[] indices, int? axis = null, NDarray @out = null, string mode = "raise")
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
a,
indices,
});
var kwargs=new PyDict();
if (axis!=null) kwargs["axis"]=ToPython(axis);
if (@out!=null) kwargs["out"]=ToPython(@out);
if (mode!="raise") kwargs["mode"]=ToPython(mode);
dynamic py = __self__.InvokeMethod("take", pyargs, kwargs);
return ToCsharp<NDarray>(py);
}
/// <summary>
/// Take values from the input array by matching 1d index and data slices.<br></br>
///
/// 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.<br></br>
/// These slices can be different lengths.<br></br>
///
/// Functions returning an index along an axis, like argsort and
/// argpartition, produce suitable indices for this function.<br></br>
///
/// 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.<br></br>
/// 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.<br></br>
/// 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 void take_along_axis(NDarray arr, NDarray indices, int axis)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
arr,
indices,
axis,
});
var kwargs=new PyDict();
dynamic py = __self__.InvokeMethod("take_along_axis", pyargs, kwargs);
}
/// <summary>
/// Construct an array from an index array and a set of arrays to choose from.<br></br>
///
/// 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)]).<br></br>
///
/// But this omits some subtleties.<br></br>
/// 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.<br></br>
/// 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.<br></br>
/// a and all of the choices must be broadcastable to the
/// same shape.<br></br>
/// 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.<br></br>
/// 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 NDarray choose(NDarray<int> a, NDarray[] choices, NDarray @out = null, string mode = "raise")
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
a,
choices,
});
var kwargs=new PyDict();
if (@out!=null) kwargs["out"]=ToPython(@out);
if (mode!="raise") kwargs["mode"]=ToPython(mode);
dynamic py = __self__.InvokeMethod("choose", pyargs, kwargs);
return ToCsharp<NDarray>(py);
}
/// <summary>
/// Return selected slices of an array along given axis.<br></br>
///
/// When working along a given axis, a slice along that axis is returned in
/// output for each index where condition evaluates to True.<br></br>
/// When
/// working on a 1-D array, compress is equivalent to extract.
/// </summary>
/// <param name="condition">
/// Array that selects which entries to return.<br></br>
/// 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.<br></br>
/// If None (default), work on the
/// flattened array.
/// </param>
/// <param name="out">
/// Output array.<br></br>
/// 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 NDarray compress(NDarray<bool> condition, NDarray a, int? axis = null, NDarray @out = null)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
condition,
a,
});
var kwargs=new PyDict();
if (axis!=null) kwargs["axis"]=ToPython(axis);
if (@out!=null) kwargs["out"]=ToPython(@out);
dynamic py = __self__.InvokeMethod("compress", pyargs, kwargs);
return ToCsharp<NDarray>(py);
}
/// <summary>
/// Return specified diagonals.<br></br>
///
/// 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].<br></br>
/// 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.<br></br>
/// 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.<br></br>
///
/// 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.<br></br>
///
/// In NumPy 1.7 and 1.8, it continues to return a copy of the diagonal,
/// but depending on this fact is deprecated.<br></br>
/// Writing to the resulting
/// array continues to work as it used to, but a FutureWarning is issued.<br></br>
///
/// Starting in NumPy 1.9 it returns a read-only view on the original array.<br></br>
///
/// Attempting to write to the resulting array will produce an error.<br></br>
///
/// In some future release, it will return a read/write view and writing to
/// the returned array will alter your original array.<br></br>
/// The returned array
/// will have the same type as the input array.<br></br>
///
/// If you don’t write to the array returned by this function, then you can
/// just ignore all of the above.<br></br>
///
/// 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).<br></br>
/// 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.<br></br>
/// Can be positive or
/// negative.<br></br>
/// 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.<br></br>
/// 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.<br></br>
/// 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.<br></br>
///
/// 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 NDarray diagonal(NDarray a, int? offset = 0, int? axis1 = 0, int? axis2 = 1)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
a,
});
var kwargs=new PyDict();
if (offset!=0) kwargs["offset"]=ToPython(offset);
if (axis1!=0) kwargs["axis1"]=ToPython(axis1);
if (axis2!=1) kwargs["axis2"]=ToPython(axis2);
dynamic py = __self__.InvokeMethod("diagonal", pyargs, kwargs);
return ToCsharp<NDarray>(py);
}
/// <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.<br></br>
/// 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.<br></br>
/// 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 NDarray @select(NDarray<bool>[] condlist, NDarray[] choicelist, object @default = null)
{
//auto-generated code, do not change
var __self__=self;
var pyargs=ToTuple(new object[]
{
condlist,
choicelist,
});
var kwargs=new PyDict();
if (@default!=null) kwargs["default"]=ToPython(@default);
dynamic py = __self__.InvokeMethod("select", pyargs, kwargs);
return ToCsharp<NDarray>(py);
}
/// <summary>
/// Create a view into the array with the given shape and strides.<br></br>
///
/// Notes
///
/// as_strided creates a view into the array given the exact strides
/// and shape.<br></br>
/// 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.<br></br>
///
/// It is advisable to always use the original x.strides when
/// calculating new strides to avoid reliance on a contiguous memory
/// layout.<br></br>
///
/// Furthermore, arrays created with this function often contain self
/// overlapping memory, so that two elements are identical.<br></br>
///
/// Vectorized write operations on such arrays will typically be
/// unpredictable.<br></br>
/// They may even give different results for small, large,
/// or transposed arrays.<br></br>
///
/// 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.<br></br>
///
/// 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.<br></br>
/// Defaults to x.shape.
/// </param>
/// <param name="strides">
/// The strides of the new array.<br></br>
/// 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.<br></br>
///
/// Otherwise it will be writable if the original array was.<br></br>
/// It
/// is advisable to set this to False if possible (see Notes).
/// </param>
public NDarray lib_stride_tricks_as_strided(NDarray x, Shape shape = null, int[] strides = null, bool? subok = false, bool? writeable = true)
{
//auto-generated code, do not change
var lib = self.GetAttr("lib");
var stride_tricks = lib.GetAttr("stride_tricks");
var __self__=stride_tricks;
var pyargs=ToTuple(new object[]
{
x,
});
var kwargs=new PyDict();
if (shape!=null) kwargs["shape"]=ToPython(shape);
if (strides!=null) kwargs["strides"]=ToPython(strides);
if (subok!=false) kwargs["subok"]=ToPython(subok);
if (writeable!=true) kwargs["writeable"]=ToPython(writeable);
dynamic py = __self__.InvokeMethod("as_strided", pyargs, kwargs);
return ToCsharp<NDarray>(py);