This repository has been archived by the owner on May 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
c-api.array.html
2103 lines (2090 loc) · 367 KB
/
c-api.array.html
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
<h1><span class="yiyi-st" id="yiyi-59">Array API</span></h1>
<blockquote>
<p>原文:<a href="https://docs.scipy.org/doc/numpy/reference/c-api.array.html">https://docs.scipy.org/doc/numpy/reference/c-api.array.html</a></p>
<p>译者:<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
<p>校对:(虚位以待)</p>
</blockquote>
<div class="line-block">
<div class="line"><span class="yiyi-st" id="yiyi-60">一级智力的测试是持有两个能力的能力</span></div>
<div class="line"><span class="yiyi-st" id="yiyi-61">反对思想在同一时间,仍然保留</span></div>
<div class="line"><span class="yiyi-st" id="yiyi-62">功能的能力。</span></div>
<div class="line"><span class="yiyi-st" id="yiyi-63">— <em>F. Scott Fitzgerald</em></span></div>
</div>
<div class="line-block">
<div class="line"><span class="yiyi-st" id="yiyi-64">对于成功的技术,现实必须优先于公众</span></div>
<div class="line"><span class="yiyi-st" id="yiyi-65">关系,对于自然不能被愚弄。</span></div>
<div class="line"><span class="yiyi-st" id="yiyi-66"> - <em>Richard P. Feynman</em></span></div>
</div>
<div class="section" id="array-structure-and-data-access">
<span id="index-0"></span><h2><span class="yiyi-st" id="yiyi-67">Array structure and data access</span></h2>
<p><span class="yiyi-st" id="yiyi-68">这些宏都可以访问<a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><code class="xref c c-type docutils literal"><span class="pre">PyArrayObject</span></code></a>结构成员。</span><span class="yiyi-st" id="yiyi-69">The input argument, arr, can be any <code class="xref c c-type docutils literal"><span class="pre">PyObject</span> <span class="pre">*</span></code> that is directly interpretable as a <a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><code class="xref c c-type docutils literal"><span class="pre">PyArrayObject</span> <span class="pre">*</span></code></a> (any instance of the <code class="xref c c-data docutils literal"><span class="pre">PyArray_Type</span></code> and its sub-types).</span></p>
<dl class="function">
<dt id="c.PyArray_NDIM"><span class="yiyi-st" id="yiyi-70"> int <code class="descname">PyArray_NDIM</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-71">数组中的维数。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_DIMS"><span class="yiyi-st" id="yiyi-72"> npy_intp *<code class="descname">PyArray_DIMS</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-73">返回指向数组的尺寸/形状的指针。</span><span class="yiyi-st" id="yiyi-74">元素的数量与数组的维数相匹配。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_SHAPE"><span class="yiyi-st" id="yiyi-75"> npy_intp *<code class="descname">PyArray_SHAPE</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *arr</em><span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-76"><span class="versionmodified">版本1.7中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-77">PyArray_DIMS的同义词,命名为与Python中的'shape'用法一致。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_DATA"><span class="yiyi-st" id="yiyi-78"> void *<code class="descname">PyArray_DATA</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *arr</em><span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_BYTES"><span class="yiyi-st" id="yiyi-79"> char *<code class="descname">PyArray_BYTES</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-80">这两个宏是相似的,并获得指向数组的数据缓冲区的指针。</span><span class="yiyi-st" id="yiyi-81">第一个宏可以(并且应该)被分配给特定指针,其中第二个宏用于通用处理。</span><span class="yiyi-st" id="yiyi-82">如果你不能保证一个连续和/或对齐的数组,那么请确保你理解如何访问数组中的数据,以避免内存和/或对齐问题。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_STRIDES"><span class="yiyi-st" id="yiyi-83"> npy_intp *<code class="descname">PyArray_STRIDES</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-84">返回指向数组的步长的指针。</span><span class="yiyi-st" id="yiyi-85">元素的数量与数组的维数相匹配。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_DIM"><span class="yiyi-st" id="yiyi-86"> npy_intp <code class="descname">PyArray_DIM</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> n</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-87">返回<em>n</em> <img alt="^{\textrm{th}}" class="math" src="../_images/math/c7201dfb8acbb9adb5fc06d19acb1604d16472f5.png" style="vertical-align: 6px">维中的形状。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_STRIDE"><span class="yiyi-st" id="yiyi-88"> npy_intp <code class="descname">PyArray_STRIDE</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> n</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-89">返回<em>n</em> <img alt="^{\textrm{th}}" class="math" src="../_images/math/c7201dfb8acbb9adb5fc06d19acb1604d16472f5.png" style="vertical-align: 6px">维度中的步幅。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_BASE"><span class="yiyi-st" id="yiyi-90"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a> *<code class="descname">PyArray_BASE</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-91">这将返回数组的基础对象。</span><span class="yiyi-st" id="yiyi-92">在大多数情况下,这意味着拥有数组正在指向的内存的对象。</span></p>
<p><span class="yiyi-st" id="yiyi-93">如果你正在使用C API构造一个数组,并指定你自己的内存,你应该使用函数<a class="reference internal" href="#c.PyArray_SetBaseObject" title="PyArray_SetBaseObject"><code class="xref c c-func docutils literal"><span class="pre">PyArray_SetBaseObject</span></code></a>将基址设置为拥有内存的对象。</span></p>
<p><span class="yiyi-st" id="yiyi-94">如果设置了<a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a>标志,则它具有不同的含义,即base是在销毁时将当前数组复制到其中的数组。</span><span class="yiyi-st" id="yiyi-95">这两个函数的基本属性的重载可能在未来版本的NumPy中改变。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_DESCR"><span class="yiyi-st" id="yiyi-96"> <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a> *<code class="descname">PyArray_DESCR</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-97">返回对数组的dtype属性的借用引用。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_DTYPE"><span class="yiyi-st" id="yiyi-98"> <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a> *<code class="descname">PyArray_DTYPE</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-99"><span class="versionmodified">版本1.7中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-100">PyArray_DESCR的同义词,命名为与Python中的'dtype'用法一致。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ENABLEFLAGS"><span class="yiyi-st" id="yiyi-101"> void <code class="descname">PyArray_ENABLEFLAGS</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> flags</em><span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-102"><span class="versionmodified">版本1.7中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-103">启用指定的数组标志。</span><span class="yiyi-st" id="yiyi-104">这个函数没有验证,并假设你知道你在做什么。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CLEARFLAGS"><span class="yiyi-st" id="yiyi-105"> void <code class="descname">PyArray_CLEARFLAGS</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> flags</em><span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-106"><span class="versionmodified">版本1.7中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-107">清除指定的数组标志。</span><span class="yiyi-st" id="yiyi-108">这个函数没有验证,并假设你知道你在做什么。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FLAGS"><span class="yiyi-st" id="yiyi-109"> int <code class="descname">PyArray_FLAGS</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ITEMSIZE"><span class="yiyi-st" id="yiyi-110"> npy_intp <code class="descname">PyArray_ITEMSIZE</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-111">返回此数组元素的itemsize。</span></p>
<p><span class="yiyi-st" id="yiyi-112">请注意,在旧版本1.7中已弃用的API中,此函数的返回类型为<code class="docutils literal"><span class="pre">int</span></code>。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_TYPE"><span class="yiyi-st" id="yiyi-113"> int <code class="descname">PyArray_TYPE</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-114">返回此数组元素的(builtin)类型号。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_GETITEM"><span class="yiyi-st" id="yiyi-115"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a> *<code class="descname">PyArray_GETITEM</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, void*<em> itemptr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-116">从ndarray中获取一个Python对象,<em>arr</em>,在itemptr指向的位置。</span><span class="yiyi-st" id="yiyi-117">失败时返回<code class="docutils literal"><span class="pre">NULL</span></code>。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_SETITEM"><span class="yiyi-st" id="yiyi-118"> int <code class="descname">PyArray_SETITEM</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, void*<em> itemptr</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-119">转换obj并将其放在ndarray中,<em>arr</em>,在itemptr指向的地方。</span><span class="yiyi-st" id="yiyi-120">如果发生错误,返回-1,否则返回0。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_SIZE"><span class="yiyi-st" id="yiyi-121"> npy_intp <code class="descname">PyArray_SIZE</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-122">返回数组的总大小(以元素数表示)。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_Size"><span class="yiyi-st" id="yiyi-123"> npy_intp <code class="descname">PyArray_Size</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> obj</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-124">如果<em>obj</em>不是bigndarray的子类,则返回0。</span><span class="yiyi-st" id="yiyi-125">否则,返回数组中元素的总数。</span><span class="yiyi-st" id="yiyi-126"><a class="reference internal" href="#c.PyArray_SIZE" title="PyArray_SIZE"><code class="xref c c-func docutils literal"><span class="pre">PyArray_SIZE</span></code></a>(<em>obj</em>)的安全版本。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_NBYTES"><span class="yiyi-st" id="yiyi-127"> npy_intp <code class="descname">PyArray_NBYTES</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-128">返回数组使用的总字节数。</span></p>
</dd></dl>
<div class="section" id="data-access">
<h3><span class="yiyi-st" id="yiyi-129">Data access</span></h3>
<p><span class="yiyi-st" id="yiyi-130">这些函数和宏提供容易访问ndarray的元素从C。这些工作对所有数组。</span><span class="yiyi-st" id="yiyi-131">你可能需要在访问数组中的数据时注意,但是,如果它不是机器字节顺序,未对齐或不可写。</span><span class="yiyi-st" id="yiyi-132">换句话说,一定要尊重标志的状态,除非你知道你在做什么,或者以前保证一个数组是可写,对齐的,并且使用<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a>以机器字节顺序。</span><span class="yiyi-st" id="yiyi-133">如果你希望处理所有类型的数组,每种类型的copyswap函数对于处理不当数组是有用的。</span><span class="yiyi-st" id="yiyi-134">一些平台(例如Solaris)不喜欢错位的数据,如果你解引用一个未对齐的指针,会崩溃。</span><span class="yiyi-st" id="yiyi-135">其他平台(例如x86 Linux)只会在未对齐数据时工作速度较慢。</span></p>
<dl class="function">
<dt id="c.PyArray_GetPtr"><span class="yiyi-st" id="yiyi-136"> void* <code class="descname">PyArray_GetPtr</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> aobj</em>, npy_intp*<em> ind</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-137">在由c阵列<em>ind</em>给出的N维索引处返回指向ndarray的数据的指针<em>aobj</em>(其必须至少<em>aobj-nd大小)。</em></span><span class="yiyi-st" id="yiyi-138">你可能希望将返回的指针类型转换为ndarray的数据类型。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_GETPTR1"><span class="yiyi-st" id="yiyi-139"> void* <code class="descname">PyArray_GETPTR1</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> obj</em>, npy_intp<em> i</em><span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_GETPTR2"><span class="yiyi-st" id="yiyi-140"> void* <code class="descname">PyArray_GETPTR2</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> obj</em>, npy_intp<em> i</em>, npy_intp<em> j</em><span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_GETPTR3"><span class="yiyi-st" id="yiyi-141"> void* <code class="descname">PyArray_GETPTR3</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> obj</em>, npy_intp<em> i</em>, npy_intp<em> j</em>, npy_intp<em> k</em><span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_GETPTR4"><span class="yiyi-st" id="yiyi-142"> void* <code class="descname">PyArray_GETPTR4</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> obj</em>, npy_intp<em> i</em>, npy_intp<em> j</em>, npy_intp<em> k</em>, npy_intp<em> l</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-143">快速,内联访问在ndarray中给定坐标(<em>obj</em>)的元素,它必须分别具有1,2,3或4维(这不被选中)。</span><span class="yiyi-st" id="yiyi-144">对应的<em>i</em>,<em>j</em>,<em>k</em>和<em>l</em>可以是任何整数,但将被解释为<code class="docutils literal"><span class="pre">npy_intp</span></code>。</span><span class="yiyi-st" id="yiyi-145">你可能希望将返回的指针类型转换为ndarray的数据类型。</span></p>
</dd></dl>
</div>
</div>
<div class="section" id="creating-arrays">
<h2><span class="yiyi-st" id="yiyi-146">Creating arrays</span></h2>
<div class="section" id="from-scratch">
<h3><span class="yiyi-st" id="yiyi-147">From scratch</span></h3>
<dl class="function">
<dt id="c.PyArray_NewFromDescr"><span class="yiyi-st" id="yiyi-148"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_NewFromDescr</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/type.html#c.PyTypeObject" title="(in Python v3.7)">PyTypeObject</a>*<em> subtype</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em>, int<em> nd</em>, npy_intp*<em> dims</em>, npy_intp*<em> strides</em>, void*<em> data</em>, int<em> flags</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-149">此函数窃取对<em>descr</em>的引用。</span></p>
<p><span class="yiyi-st" id="yiyi-150">这是主要的数组创建功能。</span><span class="yiyi-st" id="yiyi-151">最新的数组是用这个灵活的函数创建的。</span></p>
<p><span class="yiyi-st" id="yiyi-152">返回的对象是Python类型<em>子类型</em>的对象,它必须是<code class="xref c c-data docutils literal"><span class="pre">PyArray_Type</span></code>的子类型。</span><span class="yiyi-st" id="yiyi-153">数组具有<em>nd</em>维度,由<em>dims</em>描述。</span><span class="yiyi-st" id="yiyi-154">新数组的数据类型描述符为<em>descr</em>。</span></p>
<p><span class="yiyi-st" id="yiyi-155">如果<em>子类型</em>是数组子类而不是基本<code class="xref c c-data docutils literal"><span class="pre">&PyArray_Type</span></code>,则<em>obj</em>是要传递到<code class="xref py py-obj docutils literal"><span class="pre">__array_finalize__</span></code></span></p>
<p><span class="yiyi-st" id="yiyi-156">如果<em>data</em>为<code class="docutils literal"><span class="pre">NULL</span></code>,则将分配新的内存,并且<em>标志</em>可以为非零,以指示Fortran风格的连续数组。</span><span class="yiyi-st" id="yiyi-157">如果<em>数据</em>不是<code class="docutils literal"><span class="pre">NULL</span></code>,则假定指向要用于数组的存储器,并且使用<em>标志</em>参数作为数组的新标志(除了新数组的<code class="xref c c-data docutils literal"><span class="pre">NPY_OWNDATA</span></code>和<a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a>标志的状态将被复位)。</span></p>
<p><span class="yiyi-st" id="yiyi-158">另外,如果<em>数据</em>是非NULL,则也可以提供<em>步幅</em>。</span><span class="yiyi-st" id="yiyi-159">If <em>strides</em> is <code class="docutils literal"><span class="pre">NULL</span></code>, then the array strides are computed as C-style contiguous (default) or Fortran-style contiguous (<em>flags</em> is nonzero for <em>data</em> = <code class="docutils literal"><span class="pre">NULL</span></code> or <em>flags</em> & <a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> is nonzero non-NULL <em>data</em>). </span><span class="yiyi-st" id="yiyi-160">任何提供的<em>dims</em>和<em>strides</em>都会复制到新分配的维度中,并且新建数组的数组。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_NewLikeArray"><span class="yiyi-st" id="yiyi-161"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_NewLikeArray</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> prototype</em>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER">NPY_ORDER</a><em> order</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em>, int<em> subok</em><span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-162"><span class="versionmodified">版本1.6中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-163">如果它不为NULL,此函数将窃取对<em>descr</em>的引用。</span></p>
<p><span class="yiyi-st" id="yiyi-164">此数组创建例程允许方便地创建与现有数组的形状和存储器布局匹配的新数组,可能改变布局和/或数据类型。</span></p>
<p><span class="yiyi-st" id="yiyi-165">当<em>订单</em>是<a class="reference internal" href="#c.NPY_ANYORDER" title="NPY_ANYORDER"><code class="xref c c-data docutils literal"><span class="pre">NPY_ANYORDER</span></code></a>时,结果顺序为<a class="reference internal" href="#c.NPY_FORTRANORDER" title="NPY_FORTRANORDER"><code class="xref c c-data docutils literal"><span class="pre">NPY_FORTRANORDER</span></code></a> if if <em>prototype</em> is fortran数组,<a class="reference internal" href="#c.NPY_CORDER" title="NPY_CORDER"><code class="xref c c-data docutils literal"><span class="pre">NPY_CORDER</span></code></a></span><span class="yiyi-st" id="yiyi-166">当<em>命令</em>为<a class="reference internal" href="#c.NPY_KEEPORDER" title="NPY_KEEPORDER"><code class="xref c c-data docutils literal"><span class="pre">NPY_KEEPORDER</span></code></a>时,结果顺序与<em>原型</em>匹配,即使<em>原型</em>在C或Fortran顺序。</span></p>
<p><span class="yiyi-st" id="yiyi-167">如果<em>descr</em>为NULL,则使用<em>原型</em>的数据类型。</span></p>
<p><span class="yiyi-st" id="yiyi-168">如果<em>subok</em>为1,则新创建的数组将使用<em>原型</em>的子类型创建新数组,否则将创建基类数组。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_New"><span class="yiyi-st" id="yiyi-169"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_New</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/type.html#c.PyTypeObject" title="(in Python v3.7)">PyTypeObject</a>*<em> subtype</em>, int<em> nd</em>, npy_intp*<em> dims</em>, int<em> type_num</em>, npy_intp*<em> strides</em>, void*<em> data</em>, int<em> itemsize</em>, int<em> flags</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-170">这类似于<a class="reference internal" href="#c.PyArray_DescrNew" title="PyArray_DescrNew"><code class="xref c c-func docutils literal"><span class="pre">PyArray_DescrNew</span></code></a>(...),除非你用<em>type_num</em>和<em>itemsize</em>指定数据类型描述符,其中<em>type_num 对应于内置(或用户定义)类型。</em></span><span class="yiyi-st" id="yiyi-171">如果类型总是具有相同的字节数,则忽略itemsize。</span><span class="yiyi-st" id="yiyi-172">否则,itemsize指定此数组的特定大小。</span></p>
</dd></dl>
<div class="admonition warning">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-173">警告</span></p>
<p class="last"><span class="yiyi-st" id="yiyi-174">如果数据传递到<a class="reference internal" href="#c.PyArray_NewFromDescr" title="PyArray_NewFromDescr"><code class="xref c c-func docutils literal"><span class="pre">PyArray_NewFromDescr</span></code></a>或<a class="reference internal" href="#c.PyArray_New" title="PyArray_New"><code class="xref c c-func docutils literal"><span class="pre">PyArray_New</span></code></a>,则在删除新数组之前,不得重新分配此内存。</span><span class="yiyi-st" id="yiyi-175">如果此数据来自另一个Python对象,则可以使用该对象上的<a class="reference external" href="https://docs.python.org/dev/c-api/refcounting.html#c.Py_INCREF" title="(in Python v3.7)"><code class="xref c c-func docutils literal"><span class="pre">Py_INCREF</span></code></a>来完成此操作,并将新数组的基本成员设置为指向该对象。</span><span class="yiyi-st" id="yiyi-176">如果传递步幅,它们必须与尺寸,项目大小和数组的数据一致。</span></p>
</div>
<dl class="function">
<dt id="c.PyArray_SimpleNew"><span class="yiyi-st" id="yiyi-177"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_SimpleNew</code><span class="sig-paren">(</span>int<em> nd</em>, npy_intp*<em> dims</em>, int<em> typenum</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-178">创建类型为<em>typenum</em>的新未初始化数组,其每个<em>和</em>维中的大小由整数数组<em>dims</em>给出。</span><span class="yiyi-st" id="yiyi-179">此函数不能用于创建一个灵活类型的数组(没有给定itemize)。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_SimpleNewFromData"><span class="yiyi-st" id="yiyi-180"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_SimpleNewFromData</code><span class="sig-paren">(</span>int<em> nd</em>, npy_intp*<em> dims</em>, int<em> typenum</em>, void*<em> data</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-181">在给定指针指向的<em>数据</em>周围创建一个数组包装。</span><span class="yiyi-st" id="yiyi-182">数组标志将具有默认值,即数据区域运行良好并且C型连续。</span><span class="yiyi-st" id="yiyi-183">数组的形状由长度<em>nd</em>的<em>dims</em> c-数组给出。</span><span class="yiyi-st" id="yiyi-184">数组的数据类型由<em>typenum</em>指示。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_SimpleNewFromDescr"><span class="yiyi-st" id="yiyi-185"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_SimpleNewFromDescr</code><span class="sig-paren">(</span>int<em> nd</em>, npy_intp*<em> dims</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-186">如果它不为NULL,此函数将窃取对<em>descr</em>的引用。</span></p>
<p><span class="yiyi-st" id="yiyi-187">使用提供的数据类型描述符<em>descr</em>创建由<em>nd</em>和<em>dims</em>确定的形状的新数组。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FILLWBYTE"><span class="yiyi-st" id="yiyi-188"> <code class="descname">PyArray_FILLWBYTE</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em>, int<em> val</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-189">填充由<em>obj</em>指向的数组 - 它必须是bigndarray的子类,其中<em>val</em>(作为字节计算)。</span><span class="yiyi-st" id="yiyi-190">这个宏调用memset,所以obj必须是连续的。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_Zeros"><span class="yiyi-st" id="yiyi-191"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_Zeros</code><span class="sig-paren">(</span>int<em> nd</em>, npy_intp*<em> dims</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> fortran</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-192">使用由<em>dims</em>给出的形状和由<em>dtype</em>给出的数据类型构造新的<em>nd</em> -dimensional数组。</span><span class="yiyi-st" id="yiyi-193">如果<em>fortran</em>不为零,则创建Fortran顺序数组,否则创建C顺序数组。</span><span class="yiyi-st" id="yiyi-194">用零填充存储器(如果<em>dtype</em>对应于<a class="reference internal" href="c-api.dtype.html#c.NPY_OBJECT" title="NPY_OBJECT"><code class="xref c c-type docutils literal"><span class="pre">NPY_OBJECT</span></code></a>,则为0对象)。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ZEROS"><span class="yiyi-st" id="yiyi-195"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_ZEROS</code><span class="sig-paren">(</span>int<em> nd</em>, npy_intp*<em> dims</em>, int<em> type_num</em>, int<em> fortran</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-196"><a class="reference internal" href="#c.PyArray_Zeros" title="PyArray_Zeros"><code class="xref c c-func docutils literal"><span class="pre">PyArray_Zeros</span></code></a>的宏形式,它采用类型号而不是数据类型对象。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_Empty"><span class="yiyi-st" id="yiyi-197"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_Empty</code><span class="sig-paren">(</span>int<em> nd</em>, npy_intp*<em> dims</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> fortran</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-198">使用由<em>dims</em>给出的形状和由<em>dtype</em>给出的数据类型构造新的<em>nd</em> -dimensional数组。</span><span class="yiyi-st" id="yiyi-199">如果<em>fortran</em>不为零,则创建Fortran顺序数组,否则创建C顺序数组。</span><span class="yiyi-st" id="yiyi-200">数组未初始化,除非数据类型对应于<a class="reference internal" href="c-api.dtype.html#c.NPY_OBJECT" title="NPY_OBJECT"><code class="xref c c-type docutils literal"><span class="pre">NPY_OBJECT</span></code></a>,在这种情况下数组用<a class="reference external" href="https://docs.python.org/dev/c-api/none.html#c.Py_None" title="(in Python v3.7)"><code class="xref c c-data docutils literal"><span class="pre">Py_None</span></code></a>填充。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_EMPTY"><span class="yiyi-st" id="yiyi-201"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_EMPTY</code><span class="sig-paren">(</span>int<em> nd</em>, npy_intp*<em> dims</em>, int<em> typenum</em>, int<em> fortran</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-202"><a class="reference internal" href="#c.PyArray_Empty" title="PyArray_Empty"><code class="xref c c-func docutils literal"><span class="pre">PyArray_Empty</span></code></a>的宏形式,它采用类型号,<em>typenum</em>而不是数据类型对象。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_Arange"><span class="yiyi-st" id="yiyi-203"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_Arange</code><span class="sig-paren">(</span>double<em> start</em>, double<em> stop</em>, double<em> step</em>, int<em> typenum</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-204">Construct a new 1-dimensional array of data-type, <em>typenum</em>, that ranges from <em>start</em> to <em>stop</em> (exclusive) in increments of <em>step</em> . </span><span class="yiyi-st" id="yiyi-205">等同于<strong>arange</strong>(<em>开始</em>,<em>停止</em>,<em>步骤</em>,dtype)。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ArangeObj"><span class="yiyi-st" id="yiyi-206"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_ArangeObj</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> start</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> stop</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> step</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-207">构建由<code class="docutils literal"><span class="pre">descr</span></code>确定的数据类型的新的1维数组,范围从<code class="docutils literal"><span class="pre">start</span></code>到<code class="docutils literal"><span class="pre">stop</span></code>(排除),增量为<code class="docutils literal"><span class="pre">step</span></code>。</span><span class="yiyi-st" id="yiyi-208">等于arange(<code class="docutils literal"><span class="pre">start</span></code>,<code class="docutils literal"><span class="pre">stop</span></code>,<code class="docutils literal"><span class="pre">step</span></code>,<code class="docutils literal"><span class="pre">typenum</span></code>)。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_SetBaseObject"><span class="yiyi-st" id="yiyi-209"> int <code class="descname">PyArray_SetBaseObject</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-210"><span class="versionmodified">版本1.7中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-211">此函数<strong>将引用</strong>挪到<code class="docutils literal"><span class="pre">obj</span></code>,并将其设置为<code class="docutils literal"><span class="pre">arr</span></code>的基本属性。</span></p>
<p><span class="yiyi-st" id="yiyi-212">如果你通过传入你自己的内存缓冲区作为参数来构造一个数组,你需要设置数组的<em class="xref py py-obj">base</em>属性,以确保内存缓冲区的生命周期是合适的。</span></p>
<p><span class="yiyi-st" id="yiyi-213">成功返回值为0,失败时返回-1。</span></p>
<p><span class="yiyi-st" id="yiyi-214">如果提供的对象是数组,则此函数遍历<em class="xref py py-obj">base</em>指针链,以使每个数组直接指向内存所有者。</span><span class="yiyi-st" id="yiyi-215">一旦基本设置,它可能不会更改为另一个值。</span></p>
</dd></dl>
</div>
<div class="section" id="from-other-objects">
<h3><span class="yiyi-st" id="yiyi-216">From other objects</span></h3>
<dl class="function">
<dt id="c.PyArray_FromAny"><span class="yiyi-st" id="yiyi-217"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FromAny</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> min_depth</em>, int<em> max_depth</em>, int<em> requirements</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> context</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-218">这是用于从任何嵌套序列或暴露数组接口<em>op</em>的对象获取数组的主函数。</span><span class="yiyi-st" id="yiyi-219">The parameters allow specification of the required <em>dtype</em>, the minimum (<em>min_depth</em>) and maximum (<em>max_depth</em>) number of dimensions acceptable, and other <em>requirements</em> for the array. </span><span class="yiyi-st" id="yiyi-220"><em>dtype</em>参数需要是指示所需数据类型(包括所需的字节序)的<a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><code class="xref c c-type docutils literal"><span class="pre">PyArray_Descr</span></code></a>结构。</span><span class="yiyi-st" id="yiyi-221"><em>dtype</em>参数可以为NULL,表示任何数据类型(和字节序)都是可以接受的。</span><span class="yiyi-st" id="yiyi-222">除非<code class="docutils literal"><span class="pre">flags</span></code>中存在<code class="docutils literal"><span class="pre">FORCECAST</span></code>,如果无法从对象安全获取数据类型,则此调用将生成错误。</span><span class="yiyi-st" id="yiyi-223">如果你想对<em>dtype</em>使用<code class="docutils literal"><span class="pre">NULL</span></code>,并确保数组没有被切换,请使用<a class="reference internal" href="#c.PyArray_CheckFromAny" title="PyArray_CheckFromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_CheckFromAny</span></code></a>。</span><span class="yiyi-st" id="yiyi-224">任何深度参数的值为0将导致该参数被忽略。</span><span class="yiyi-st" id="yiyi-225">可以添加以下任何数组标志(<em>例如</em>使用|)以获取<em>需求</em>参数。</span><span class="yiyi-st" id="yiyi-226">如果您的代码可以处理一般(<em>例如</em> stride,字节交换或未对齐的数组),则<em>要求</em>可能为0。</span><span class="yiyi-st" id="yiyi-227">此外,如果<em>op</em>不是数组(或不公开数组接口),则将创建一个新数组(并使用序列协议从<em>op</em>填充) 。</span><span class="yiyi-st" id="yiyi-228">新数组将具有<code class="xref c c-data docutils literal"><span class="pre">NPY_DEFAULT</span></code>作为其标志成员。</span><span class="yiyi-st" id="yiyi-229"><em>上下文</em>参数被传递给<em>op</em>的<code class="xref py py-obj docutils literal"><span class="pre">__array__</span></code>方法,并且仅当数组以这种方式构造时才使用。</span><span class="yiyi-st" id="yiyi-230">几乎总是此参数为<code class="docutils literal"><span class="pre">NULL</span></code>。</span></p>
<p><span class="yiyi-st" id="yiyi-231">在NumPy的1.6版本和更早版本中,以下标志中没有_ARRAY_宏命名空间。</span><span class="yiyi-st" id="yiyi-232">这种形式的常量名在1.7中已被弃用。</span></p>
<dl class="var">
<dt id="c.NPY_ARRAY_C_CONTIGUOUS"><span class="yiyi-st" id="yiyi-233"> <code class="descname">NPY_ARRAY_C_CONTIGUOUS</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-234">确保返回的数组是C样式连续的</span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_F_CONTIGUOUS"><span class="yiyi-st" id="yiyi-235"> <code class="descname">NPY_ARRAY_F_CONTIGUOUS</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-236"></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_ALIGNED"><span class="yiyi-st" id="yiyi-237"> <code class="descname">NPY_ARRAY_ALIGNED</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-238">确保返回的数组在其数据类型的正确边界上对齐。</span><span class="yiyi-st" id="yiyi-239">对齐数组具有数据指针和每个步幅因子作为数据类型描述符的对准因子的倍数。</span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_WRITEABLE"><span class="yiyi-st" id="yiyi-240"> <code class="descname">NPY_ARRAY_WRITEABLE</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-241">确保返回的数组可以写入。</span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_ENSURECOPY"><span class="yiyi-st" id="yiyi-242"> <code class="descname">NPY_ARRAY_ENSURECOPY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-243">确保副本由<em>op</em>组成。</span><span class="yiyi-st" id="yiyi-244">如果此标志不存在,则如果可以避免,则不复制数据。</span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_ENSUREARRAY"><span class="yiyi-st" id="yiyi-245"> <code class="descname">NPY_ARRAY_ENSUREARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-246">确保结果是基类ndarray或bigndarray。</span><span class="yiyi-st" id="yiyi-247">默认情况下,如果<em>op</em>是bigndarray的子类的实例,则返回相同子类的实例。</span><span class="yiyi-st" id="yiyi-248">如果设置了此标志,将返回一个ndarray对象。</span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_FORCECAST"><span class="yiyi-st" id="yiyi-249"> <code class="descname">NPY_ARRAY_FORCECAST</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-250">强制转换为输出类型,即使它不能安全地完成。</span><span class="yiyi-st" id="yiyi-251">没有这个标志,只有当它可以安全地进行时,才会发生数据转换,否则会引发错误。</span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_UPDATEIFCOPY"><span class="yiyi-st" id="yiyi-252"> <code class="descname">NPY_ARRAY_UPDATEIFCOPY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-253">如果<em>op</em>已经是一个数组,但不满足要求,那么将进行一个副本(这将满足要求)。</span><span class="yiyi-st" id="yiyi-254">如果此标志存在并且必须创建一个(已经是数组的对象的)副本,则在返回的副本中设置相应的<a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a>标志,并且<em>op</em>为设为只读。</span><span class="yiyi-st" id="yiyi-255">当返回的副本被删除时(可能是在计算完成后),其内容将被复制回<em>op</em>,并且<em>op</em>数组将再次可写。</span><span class="yiyi-st" id="yiyi-256">如果<em>op</em>无法写入,则会引发错误。</span><span class="yiyi-st" id="yiyi-257">如果<em>op</em>不是数组,则此标志无效。</span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_BEHAVED"><span class="yiyi-st" id="yiyi-258"> <code class="descname">NPY_ARRAY_BEHAVED</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-259"><a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_CARRAY"><span class="yiyi-st" id="yiyi-260"> <code class="descname">NPY_ARRAY_CARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-261"><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_BEHAVED" title="NPY_ARRAY_BEHAVED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_BEHAVED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_CARRAY_RO"><span class="yiyi-st" id="yiyi-262"> <code class="descname">NPY_ARRAY_CARRAY_RO</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-263"><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_FARRAY"><span class="yiyi-st" id="yiyi-264"> <code class="descname">NPY_ARRAY_FARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-265"><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_BEHAVED" title="NPY_ARRAY_BEHAVED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_BEHAVED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_FARRAY_RO"><span class="yiyi-st" id="yiyi-266"> <code class="descname">NPY_ARRAY_FARRAY_RO</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-267"><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_DEFAULT"><span class="yiyi-st" id="yiyi-268"> <code class="descname">NPY_ARRAY_DEFAULT</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-269"><a class="reference internal" href="#c.NPY_ARRAY_CARRAY" title="NPY_ARRAY_CARRAY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_CARRAY</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_IN_ARRAY"><span class="yiyi-st" id="yiyi-270"> <code class="descname">NPY_ARRAY_IN_ARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-271"><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_IN_FARRAY"><span class="yiyi-st" id="yiyi-272"> <code class="descname">NPY_ARRAY_IN_FARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-273"><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_OUT_ARRAY"><span class="yiyi-st" id="yiyi-274"> <code class="descname">NPY_OUT_ARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-275"><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_OUT_FARRAY"><span class="yiyi-st" id="yiyi-276"> <code class="descname">NPY_ARRAY_OUT_FARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-277"><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_INOUT_ARRAY"><span class="yiyi-st" id="yiyi-278"> <code class="descname">NPY_ARRAY_INOUT_ARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-279"><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_INOUT_FARRAY"><span class="yiyi-st" id="yiyi-280"> <code class="descname">NPY_ARRAY_INOUT_FARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-281"><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a></span></p>
</dd></dl>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_GetArrayParamsFromObject"><span class="yiyi-st" id="yiyi-282"> int <code class="descname">PyArray_GetArrayParamsFromObject</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> requested_dtype</em>, <a class="reference internal" href="c-api.dtype.html#c.npy_bool" title="npy_bool">npy_bool</a><em> writeable</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>**<em> out_dtype</em>, int*<em> out_ndim</em>, npy_intp*<em> out_dims</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>**<em> out_arr</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> context</em><span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-283"><span class="versionmodified">版本1.6中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-284">检索用于查看/将任意PyObject *转换为NumPy数组的数组参数。</span><span class="yiyi-st" id="yiyi-285">这允许发现Python列表列表的“先天类型和形状”,而无需实际转换为数组。</span><span class="yiyi-st" id="yiyi-286">PyArray_FromAny调用此函数来分析其输入。</span></p>
<p><span class="yiyi-st" id="yiyi-287">在某些情况下,例如结构化数组和__array__接口,需要使用数据类型来理解对象。</span><span class="yiyi-st" id="yiyi-288">当需要时,为'requested_dtype'提供一个Descr,否则提供NULL。</span><span class="yiyi-st" id="yiyi-289">此引用不会被窃取。</span><span class="yiyi-st" id="yiyi-290">此外,如果请求的dtype不修改输入的解释,out_dtype仍将获得对象的“先天”dtype,而不是在'requested_dtype'中传递的dtype。</span></p>
<p><span class="yiyi-st" id="yiyi-291">如果需要写入“op”中的值,请将布尔值“writeable”设置为1。</span><span class="yiyi-st" id="yiyi-292">当'op'是标量,列表列表或其他不可写入的'op'时,会出现错误。</span><span class="yiyi-st" id="yiyi-293">这不同于将NPY_ARRAY_WRITEABLE传递到PyArray_FromAny,其中可写数组可以是输入的副本。</span></p>
<p><span class="yiyi-st" id="yiyi-294">当返回成功(返回值为0)时,out_arr将填充一个非空的PyArrayObject,其余的参数保持不变,或out_arr填充为NULL,其余的参数将被填充。</span></p>
<p><span class="yiyi-st" id="yiyi-295">典型用途:</span></p>
<div class="highlight-c"><div class="highlight"><pre><span></span>PyArrayObject *arr = NULL;
PyArray_Descr *dtype = NULL;
int ndim = 0;
npy_intp dims[NPY_MAXDIMS];
if (PyArray_GetArrayParamsFromObject(op, NULL, 1, &dtype,
&ndim, &dims, &arr, NULL) < 0) {
return NULL;
}
if (arr == NULL) {
... validate/change dtype, validate flags, ndim, etc ...
// Could make custom strides here too
arr = PyArray_NewFromDescr(&PyArray_Type, dtype, ndim,
dims, NULL,
fortran ? NPY_ARRAY_F_CONTIGUOUS : 0,
NULL);
if (arr == NULL) {
return NULL;
}
if (PyArray_CopyObject(arr, op) < 0) {
Py_DECREF(arr);
return NULL;
}
}
else {
... in this case the other parameters weren't filled, just
validate and possibly copy arr itself ...
}
... use arr ...
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CheckFromAny"><span class="yiyi-st" id="yiyi-296"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_CheckFromAny</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> min_depth</em>, int<em> max_depth</em>, int<em> requirements</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> context</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-297">几乎与<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a>(...)除了<em>要求</em>可以包含<a class="reference internal" href="#c.NPY_ARRAY_NOTSWAPPED" title="NPY_ARRAY_NOTSWAPPED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_NOTSWAPPED</span></code></a>(覆盖<em>dtype</em> )和<a class="reference internal" href="#c.NPY_ARRAY_ELEMENTSTRIDES" title="NPY_ARRAY_ELEMENTSTRIDES"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ELEMENTSTRIDES</span></code></a>,表示数组应该对齐,因为步长是元素大小的倍数。</span></p>
<p><span class="yiyi-st" id="yiyi-298">在NumPy的1.6版本和更早版本中,以下标志中没有_ARRAY_宏命名空间。</span><span class="yiyi-st" id="yiyi-299">这种形式的常量名在1.7中已被弃用。</span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_NOTSWAPPED"><span class="yiyi-st" id="yiyi-300"> <code class="descname">NPY_ARRAY_NOTSWAPPED</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-301">确保返回的数组具有按机器字节顺序的数据类型描述符,超越了<em>dtype</em>参数中的任何规范。</span><span class="yiyi-st" id="yiyi-302">通常,字节顺序要求由<em>dtype</em>参数决定。</span><span class="yiyi-st" id="yiyi-303">如果这个标志被设置,并且dtype参数不指示机器字节顺序描述符(或者是NULL,并且该对象已经是具有不是机器字节顺序的数据类型描述符的数组),则新的数据 - 类型描述符被创建并使用,其字节顺序字段设置为native。</span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_BEHAVED_NS"><span class="yiyi-st" id="yiyi-304"> <code class="descname">NPY_ARRAY_BEHAVED_NS</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-305"><a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_NOTSWAPPED" title="NPY_ARRAY_NOTSWAPPED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_NOTSWAPPED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_ELEMENTSTRIDES"><span class="yiyi-st" id="yiyi-306"> <code class="descname">NPY_ARRAY_ELEMENTSTRIDES</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-307">确保返回的数组具有元素大小的倍数的步长。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FromArray"><span class="yiyi-st" id="yiyi-308"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FromArray</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> op</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> newtype</em>, int<em> requirements</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-309">Special case of <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a> for when <em>op</em> is already an array but it needs to be of a specific <em>newtype</em> (including byte-order) or has certain <em>requirements</em>.</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FromStructInterface"><span class="yiyi-st" id="yiyi-310"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FromStructInterface</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-311">从公开了<code class="xref py py-obj docutils literal"><span class="pre">__array_struct__</span></code>属性并遵循数组接口协议的Python对象返回一个ndarray对象。</span><span class="yiyi-st" id="yiyi-312">如果对象不包含此属性,则返回对<a class="reference external" href="https://docs.python.org/dev/c-api/object.html#c.Py_NotImplemented" title="(in Python v3.7)"><code class="xref c c-data docutils literal"><span class="pre">Py_NotImplemented</span></code></a>的借用引用。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FromInterface"><span class="yiyi-st" id="yiyi-313"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FromInterface</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-314">从暴露数组接口协议后的<a class="reference internal" href="arrays.interface.html#__array_interface__" title="__array_interface__"><code class="xref py py-obj docutils literal"><span class="pre">__array_interface__</span></code></a>属性的Python对象返回一个ndarray对象。</span><span class="yiyi-st" id="yiyi-315">如果对象不包含此属性,则返回对<a class="reference external" href="https://docs.python.org/dev/c-api/object.html#c.Py_NotImplemented" title="(in Python v3.7)"><code class="xref c c-data docutils literal"><span class="pre">Py_NotImplemented</span></code></a>的借用引用。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FromArrayAttr"><span class="yiyi-st" id="yiyi-316"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FromArrayAttr</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> context</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-317">从暴露了<code class="xref py py-obj docutils literal"><span class="pre">__array__</span></code>方法的Python对象返回一个ndarray对象。</span><span class="yiyi-st" id="yiyi-318"><code class="xref py py-obj docutils literal"><span class="pre">__array__</span></code>方法可以取0,1或2个参数([dtype,context]),其中<em>上下文</em>用于传递有关<code class="xref py py-obj docutils literal"><span class="pre">__array__</span></code></span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ContiguousFromAny"><span class="yiyi-st" id="yiyi-319"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_ContiguousFromAny</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em>, int<em> typenum</em>, int<em> min_depth</em>, int<em> max_depth</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-320">此函数从枚举的<em>typenum指定的(非灵活)类型的任何嵌套序列或数组接口导出对象<em>op</em>返回(C样式) t1>,最小深度<em>min_depth</em>和最大深度<em>max_depth</em>。</em></span><span class="yiyi-st" id="yiyi-321">等效于对<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a>的调用,其要求设置为<code class="xref c c-data docutils literal"><span class="pre">NPY_DEFAULT</span></code>,类型参数的type_num成员设置为<em>typenum</em>。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FromObject"><span class="yiyi-st" id="yiyi-322"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a> *<code class="descname">PyArray_FromObject</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a><em> *op</em>, int<em> typenum</em>, int<em> min_depth</em>, int<em> max_depth</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-323">从枚举类型给定的类型的任何嵌套序列或数组接口导出对象op返回对齐的和本地字节序数组。</span><span class="yiyi-st" id="yiyi-324">数组可以具有的最小维数由min_depth给出,而最大值为max_depth。</span><span class="yiyi-st" id="yiyi-325">这等同于对需求设置为BEHAVED的<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a>的调用。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_EnsureArray"><span class="yiyi-st" id="yiyi-326"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_EnsureArray</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-327">此函数<strong>将引用</strong>挪到<code class="docutils literal"><span class="pre">op</span></code>,并确保<code class="docutils literal"><span class="pre">op</span></code>是基类的ndarray。</span><span class="yiyi-st" id="yiyi-328">它是特殊情况的数组标量,但是否则调用<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a>(<code class="docutils literal"><span class="pre">op</span></code>,NULL,0,0,<a class="reference internal" href="../user/c-info.how-to-extend.html#c.NPY_ARRAY_ENSUREARRAY" title="NPY_ARRAY_ENSUREARRAY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ENSUREARRAY</span></code></a>)。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FromString"><span class="yiyi-st" id="yiyi-329"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FromString</code><span class="sig-paren">(</span>char*<em> string</em>, npy_intp<em> slen</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, npy_intp<em> num</em>, char*<em> sep</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-330">从长度为<code class="docutils literal"><span class="pre">slen</span></code>的二进制或(ASCII)文本<code class="docutils literal"><span class="pre">string</span></code>构造单一类型的一维数组。</span><span class="yiyi-st" id="yiyi-331">要创建的数组的数据类型由<code class="docutils literal"><span class="pre">dtype</span></code>给出。</span><span class="yiyi-st" id="yiyi-332">如果num是-1,则<strong>复制</strong>整个字符串并返回一个适当大小的数组,否则<code class="docutils literal"><span class="pre">num</span></code>是要<strong>复制</strong>字符串。</span><span class="yiyi-st" id="yiyi-333">If <code class="docutils literal"><span class="pre">sep</span></code> is NULL (or “”), then interpret the string as bytes of binary data, otherwise convert the sub-strings separated by <code class="docutils literal"><span class="pre">sep</span></code> to items of data-type <code class="docutils literal"><span class="pre">dtype</span></code>. </span><span class="yiyi-st" id="yiyi-334">某些数据类型在文本模式下可能无法读取,如果发生错误,则会出现错误。</span><span class="yiyi-st" id="yiyi-335">所有错误返回NULL。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FromFile"><span class="yiyi-st" id="yiyi-336"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FromFile</code><span class="sig-paren">(</span>FILE*<em> fp</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, npy_intp<em> num</em>, char*<em> sep</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-337">从二进制或文本文件构造单个类型的一维数组。</span><span class="yiyi-st" id="yiyi-338">打开的文件指针为<code class="docutils literal"><span class="pre">fp</span></code>,要创建的数组的数据类型由<code class="docutils literal"><span class="pre">dtype</span></code>给出。</span><span class="yiyi-st" id="yiyi-339">这必须与文件中的数据匹配。</span><span class="yiyi-st" id="yiyi-340">如果<code class="docutils literal"><span class="pre">num</span></code>为-1,则读取直到文件结束并返回适当大小的数组,否则<code class="docutils literal"><span class="pre">num</span></code>是要读取的项目数。</span><span class="yiyi-st" id="yiyi-341">如果<code class="docutils literal"><span class="pre">sep</span></code>为NULL(或“”),则以二进制模式从文件读取,否则从文本模式中使用<code class="docutils literal"><span class="pre">sep</span></code>提供项目分隔符。</span><span class="yiyi-st" id="yiyi-342">某些数组类型无法在文本模式下读取,在这种情况下会出现错误。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FromBuffer"><span class="yiyi-st" id="yiyi-343"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FromBuffer</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> buf</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, npy_intp<em> count</em>, npy_intp<em> offset</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-344">从导出(单段)缓冲区协议(或具有返回导出缓冲区协议的对象的__buffer__属性)的对象<code class="docutils literal"><span class="pre">buf</span></code>构造单个类型的一维数组。</span><span class="yiyi-st" id="yiyi-345">首先尝试可写缓冲区,然后尝试只读缓冲区。</span><span class="yiyi-st" id="yiyi-346">返回的数组的<a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a>标志将反映哪个成功。</span><span class="yiyi-st" id="yiyi-347">The data is assumed to start at <code class="docutils literal"><span class="pre">offset</span></code> bytes from the start of the memory location for the object. </span><span class="yiyi-st" id="yiyi-348">缓冲区中的数据类型将根据数据类型描述符<code class="docutils literal"><span class="pre">dtype.</span></code></span><span class="yiyi-st" id="yiyi-349">如果<code class="docutils literal"><span class="pre">count</span></code>为负,那么将根据缓冲区的大小和所请求的itemsize来确定,否则<code class="docutils literal"><span class="pre">count</span></code>表示应该从缓冲区转换多少个元素。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CopyInto"><span class="yiyi-st" id="yiyi-350"> int <code class="descname">PyArray_CopyInto</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> dest</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> src</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-351">从源数组<code class="docutils literal"><span class="pre">src</span></code>复制到目标数组<code class="docutils literal"><span class="pre">dest</span></code>,如有必要,执行数据类型转换。</span><span class="yiyi-st" id="yiyi-352">如果发生错误返回-1(否则为0)。</span><span class="yiyi-st" id="yiyi-353"><code class="docutils literal"><span class="pre">src</span></code>的形状必须可以广播到<code class="docutils literal"><span class="pre">dest</span></code>的形状。</span><span class="yiyi-st" id="yiyi-354">dest和src的数据区不能重叠。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_MoveInto"><span class="yiyi-st" id="yiyi-355"> int <code class="descname">PyArray_MoveInto</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> dest</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> src</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-356">将数据从源数组<code class="docutils literal"><span class="pre">src</span></code>移入目标数组<code class="docutils literal"><span class="pre">dest</span></code>,如有必要,执行数据类型转换。</span><span class="yiyi-st" id="yiyi-357">如果发生错误返回-1(否则为0)。</span><span class="yiyi-st" id="yiyi-358"><code class="docutils literal"><span class="pre">src</span></code>的形状必须可以广播到<code class="docutils literal"><span class="pre">dest</span></code>的形状。</span><span class="yiyi-st" id="yiyi-359">dest和src的数据区可能重叠。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_GETCONTIGUOUS"><span class="yiyi-st" id="yiyi-360"> <a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>* <code class="descname">PyArray_GETCONTIGUOUS</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-361">如果<code class="docutils literal"><span class="pre">op</span></code>已经是(C风格)连续和良好行为,那么只是返回一个引用,否则返回一个(连续和良好行为)的数组副本。</span><span class="yiyi-st" id="yiyi-362">参数op必须是(ndarray的子类),并且不进行检查。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FROM_O"><span class="yiyi-st" id="yiyi-363"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FROM_O</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-364">将<code class="docutils literal"><span class="pre">obj</span></code>转换为ndarray。</span><span class="yiyi-st" id="yiyi-365">参数可以是导出数组接口的任何嵌套序列或对象。</span><span class="yiyi-st" id="yiyi-366">这是<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a>的宏形式,使用<code class="docutils literal"><span class="pre">NULL</span></code>,0,0,0作为其他参数。</span><span class="yiyi-st" id="yiyi-367">您的代码必须能够处理任何数据类型描述符和任何data-flags的组合,以使用此宏。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FROM_OF"><span class="yiyi-st" id="yiyi-368"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FROM_OF</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em>, int<em> requirements</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-369">类似于<a class="reference internal" href="#c.PyArray_FROM_O" title="PyArray_FROM_O"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FROM_O</span></code></a>,但它可以接受<em>要求</em>的参数,指示生成的数组必须具有的属性。</span><span class="yiyi-st" id="yiyi-370">Available requirements that can be enforced are <a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_NOTSWAPPED" title="NPY_ARRAY_NOTSWAPPED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_NOTSWAPPED</span></code></a>, <a class="reference internal" href="../user/c-info.how-to-extend.html#c.NPY_ARRAY_ENSURECOPY" title="NPY_ARRAY_ENSURECOPY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ENSURECOPY</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a>, <a class="reference internal" href="../user/c-info.how-to-extend.html#c.NPY_ARRAY_FORCECAST" title="NPY_ARRAY_FORCECAST"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_FORCECAST</span></code></a>, and <a class="reference internal" href="../user/c-info.how-to-extend.html#c.NPY_ARRAY_ENSUREARRAY" title="NPY_ARRAY_ENSUREARRAY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ENSUREARRAY</span></code></a>. </span><span class="yiyi-st" id="yiyi-371">还可以使用标志的标准组合:</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FROM_OT"><span class="yiyi-st" id="yiyi-372"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FROM_OT</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em>, int<em> typenum</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-373">类似于<a class="reference internal" href="#c.PyArray_FROM_O" title="PyArray_FROM_O"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FROM_O</span></code></a>,除了它可以接受<em>typenum</em>的参数,指定返回的数组的类型号。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FROM_OTF"><span class="yiyi-st" id="yiyi-374"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FROM_OTF</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em>, int<em> typenum</em>, int<em> requirements</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-375">组合<a class="reference internal" href="#c.PyArray_FROM_OF" title="PyArray_FROM_OF"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FROM_OF</span></code></a>和<a class="reference internal" href="#c.PyArray_FROM_OT" title="PyArray_FROM_OT"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FROM_OT</span></code></a>,允许提供<em>typenum</em>和<em>标志</em>参数。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FROMANY"><span class="yiyi-st" id="yiyi-376"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_FROMANY</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em>, int<em> typenum</em>, int<em> min</em>, int<em> max</em>, int<em> requirements</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-377">类似于<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a>,除了使用类型号指定数据类型。</span><span class="yiyi-st" id="yiyi-378"><a class="reference internal" href="#c.PyArray_DescrFromType" title="PyArray_DescrFromType"><code class="xref c c-func docutils literal"><span class="pre">PyArray_DescrFromType</span></code></a>(<em>typenum</em>)直接传递到<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a>。</span><span class="yiyi-st" id="yiyi-379">如果<a class="reference internal" href="../user/c-info.how-to-extend.html#c.NPY_ARRAY_ENSURECOPY" title="NPY_ARRAY_ENSURECOPY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ENSURECOPY</span></code></a>作为需求传递,此宏还将<code class="xref c c-data docutils literal"><span class="pre">NPY_DEFAULT</span></code>添加到要求中。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CheckAxis"><span class="yiyi-st" id="yiyi-380"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a> *<code class="descname">PyArray_CheckAxis</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em>, int*<em> axis</em>, int<em> requirements</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-381">封装具有axis =关键字的函数和方法的功能,并且以None作为轴参数正常工作。</span><span class="yiyi-st" id="yiyi-382">输入数组是<code class="docutils literal"><span class="pre">obj</span></code>,而<code class="docutils literal"><span class="pre">*axis</span></code>是一个转换的整数(因此> = MAXDIMS是None值),<code class="docutils literal"><span class="pre">requirements</span></code>需要的属性<code class="docutils literal"><span class="pre">obj</span></code>。</span><span class="yiyi-st" id="yiyi-383">输出是输入的转换版本,以满足要求,并且如果需要,发生平坦化。</span><span class="yiyi-st" id="yiyi-384">对<code class="docutils literal"><span class="pre">*axis</span></code>的输出负值进行转换,并检查新值以确保与<code class="docutils literal"><span class="pre">obj</span></code>的形状一致。</span></p>
</dd></dl>
</div>
</div>
<div class="section" id="dealing-with-types">
<h2><span class="yiyi-st" id="yiyi-385">Dealing with types</span></h2>
<div class="section" id="general-check-of-python-type">
<h3><span class="yiyi-st" id="yiyi-386">General check of Python Type</span></h3>
<dl class="function">
<dt id="c.PyArray_Check"><span class="yiyi-st" id="yiyi-387"> <code class="descname">PyArray_Check</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-388">如果<em>op</em>是类型为<code class="xref c c-data docutils literal"><span class="pre">PyArray_Type</span></code>的子类型的Python对象,则计算true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CheckExact"><span class="yiyi-st" id="yiyi-389"> <code class="descname">PyArray_CheckExact</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-390">如果<em>op</em>是类型为<code class="xref c c-data docutils literal"><span class="pre">PyArray_Type</span></code>的Python对象,则计算true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_HasArrayInterface"><span class="yiyi-st" id="yiyi-391"> <code class="descname">PyArray_HasArrayInterface</code><span class="sig-paren">(</span>op, out<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-392">如果<code class="docutils literal"><span class="pre">op</span></code>实现数组接口的任何部分,则<code class="docutils literal"><span class="pre">out</span></code>将包含对使用接口或<code class="docutils literal"><span class="pre">out</span></code> <code class="docutils literal"><span class="pre">NULL</span></code>如果在转换期间发生错误。</span><span class="yiyi-st" id="yiyi-393">否则,out将包含对<a class="reference external" href="https://docs.python.org/dev/c-api/object.html#c.Py_NotImplemented" title="(in Python v3.7)"><code class="xref c c-data docutils literal"><span class="pre">Py_NotImplemented</span></code></a>的借用引用,并且未设置错误条件。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_HasArrayInterfaceType"><span class="yiyi-st" id="yiyi-394"> <code class="descname">PyArray_HasArrayInterfaceType</code><span class="sig-paren">(</span>op, type, context, out<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-395">如果<code class="docutils literal"><span class="pre">op</span></code>实现数组接口的任何部分,则<code class="docutils literal"><span class="pre">out</span></code>将包含对使用接口或<code class="docutils literal"><span class="pre">out</span></code> <code class="docutils literal"><span class="pre">NULL</span></code>如果在转换期间发生错误。</span><span class="yiyi-st" id="yiyi-396">否则,out将包含对Py_NotImplemented的借用引用,并且不设置错误条件。</span><span class="yiyi-st" id="yiyi-397">此版本允许在查找<code class="xref py py-obj docutils literal"><span class="pre">__array__</span></code>属性的数组接口部分中设置类型和上下文。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_IsZeroDim"><span class="yiyi-st" id="yiyi-398"> <code class="descname">PyArray_IsZeroDim</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-399">如果<em>op</em>是<code class="xref c c-data docutils literal"><span class="pre">PyArray_Type</span></code>(的子类)的实例并且具有0个维度,则计算true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_IsScalar"><span class="yiyi-st" id="yiyi-400"> <code class="descname">PyArray_IsScalar</code><span class="sig-paren">(</span>op, cls<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-401">如果<em>op</em>是<code class="xref c c-data docutils literal"><span class="pre">Py{cls}ArrType_Type</span></code>的实例,则计算true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CheckScalar"><span class="yiyi-st" id="yiyi-402"> <code class="descname">PyArray_CheckScalar</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-403">如果<em>op</em>是数组标量(<code class="xref c c-data docutils literal"><span class="pre">PyGenericArr_Type</span></code>的子类型的实例)或<code class="xref c c-data docutils literal"><span class="pre">PyArray_Type</span></code></span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_IsPythonNumber"><span class="yiyi-st" id="yiyi-404"> <code class="descname">PyArray_IsPythonNumber</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-405">如果<em>op</em>是内置数值类型的实例(int,float,complex,long,bool)</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_IsPythonScalar"><span class="yiyi-st" id="yiyi-406"> <code class="descname">PyArray_IsPythonScalar</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-407">如果<em>op</em>是内置的Python标量对象(int,float,complex,str,unicode,long,bool),则计算true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_IsAnyScalar"><span class="yiyi-st" id="yiyi-408"> <code class="descname">PyArray_IsAnyScalar</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-409">如果<em>op</em>是Python标量对象(请参阅<a class="reference internal" href="#c.PyArray_IsPythonScalar" title="PyArray_IsPythonScalar"><code class="xref c c-func docutils literal"><span class="pre">PyArray_IsPythonScalar</span></code></a>)或数组标量(<code class="xref c c-data docutils literal"><span class="pre">PyGenericArr_Type</span></code>的子类型的实例) 。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CheckAnyScalar"><span class="yiyi-st" id="yiyi-410"> <code class="descname">PyArray_CheckAnyScalar</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-411">如果<em>op</em>是Python标量对象(参见<a class="reference internal" href="#c.PyArray_IsPythonScalar" title="PyArray_IsPythonScalar"><code class="xref c c-func docutils literal"><span class="pre">PyArray_IsPythonScalar</span></code></a>),即数组标量(<code class="xref c c-data docutils literal"><span class="pre">PyGenericArr_Type</span></code>的子类型的实例),其维度为0的<code class="xref c c-data docutils literal"><span class="pre">PyArray_Type</span></code>的子类型的实例。</span></p>
</dd></dl>
</div>
<div class="section" id="data-type-checking">
<h3><span class="yiyi-st" id="yiyi-412">Data-type checking</span></h3>
<p><span class="yiyi-st" id="yiyi-413">对于typenum宏,参数是表示枚举的数组数据类型的整数。</span><span class="yiyi-st" id="yiyi-414">对于数组类型检查宏,参数必须是<code class="xref c c-type docutils literal"><span class="pre">PyObject</span> <span class="pre">*</span></code>,可以直接解释为<a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><code class="xref c c-type docutils literal"><span class="pre">PyArrayObject</span> <span class="pre">*</span></code></a>。</span></p>
<dl class="function">
<dt id="c.PyTypeNum_ISUNSIGNED"><span class="yiyi-st" id="yiyi-415"> <code class="descname">PyTypeNum_ISUNSIGNED</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISUNSIGNED"><span class="yiyi-st" id="yiyi-416"> <code class="descname">PyDataType_ISUNSIGNED</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISUNSIGNED"><span class="yiyi-st" id="yiyi-417"> <code class="descname">PyArray_ISUNSIGNED</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-418">类型表示无符号整数。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISSIGNED"><span class="yiyi-st" id="yiyi-419"> <code class="descname">PyTypeNum_ISSIGNED</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISSIGNED"><span class="yiyi-st" id="yiyi-420"> <code class="descname">PyDataType_ISSIGNED</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISSIGNED"><span class="yiyi-st" id="yiyi-421"> <code class="descname">PyArray_ISSIGNED</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-422">类型表示有符号整数。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISINTEGER"><span class="yiyi-st" id="yiyi-423"> <code class="descname">PyTypeNum_ISINTEGER</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISINTEGER"><span class="yiyi-st" id="yiyi-424"> <code class="descname">PyDataType_ISINTEGER</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISINTEGER"><span class="yiyi-st" id="yiyi-425"> <code class="descname">PyArray_ISINTEGER</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-426">类型表示任何整数。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISFLOAT"><span class="yiyi-st" id="yiyi-427"> <code class="descname">PyTypeNum_ISFLOAT</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISFLOAT"><span class="yiyi-st" id="yiyi-428"> <code class="descname">PyDataType_ISFLOAT</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISFLOAT"><span class="yiyi-st" id="yiyi-429"> <code class="descname">PyArray_ISFLOAT</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-430">类型表示任何浮点数。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISCOMPLEX"><span class="yiyi-st" id="yiyi-431"> <code class="descname">PyTypeNum_ISCOMPLEX</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISCOMPLEX"><span class="yiyi-st" id="yiyi-432"> <code class="descname">PyDataType_ISCOMPLEX</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISCOMPLEX"><span class="yiyi-st" id="yiyi-433"> <code class="descname">PyArray_ISCOMPLEX</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-434">类型表示任何复杂浮点数。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISNUMBER"><span class="yiyi-st" id="yiyi-435"> <code class="descname">PyTypeNum_ISNUMBER</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISNUMBER"><span class="yiyi-st" id="yiyi-436"> <code class="descname">PyDataType_ISNUMBER</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISNUMBER"><span class="yiyi-st" id="yiyi-437"> <code class="descname">PyArray_ISNUMBER</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-438">类型表示任何整数,浮点数或复数浮点数。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISSTRING"><span class="yiyi-st" id="yiyi-439"> <code class="descname">PyTypeNum_ISSTRING</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISSTRING"><span class="yiyi-st" id="yiyi-440"> <code class="descname">PyDataType_ISSTRING</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISSTRING"><span class="yiyi-st" id="yiyi-441"> <code class="descname">PyArray_ISSTRING</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-442">Type表示字符串数据类型。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISPYTHON"><span class="yiyi-st" id="yiyi-443"> <code class="descname">PyTypeNum_ISPYTHON</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISPYTHON"><span class="yiyi-st" id="yiyi-444"> <code class="descname">PyDataType_ISPYTHON</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISPYTHON"><span class="yiyi-st" id="yiyi-445"> <code class="descname">PyArray_ISPYTHON</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-446">类型表示对应于标准Python标量(bool,int,float或complex)之一的枚举类型。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISFLEXIBLE"><span class="yiyi-st" id="yiyi-447"> <code class="descname">PyTypeNum_ISFLEXIBLE</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISFLEXIBLE"><span class="yiyi-st" id="yiyi-448"> <code class="descname">PyDataType_ISFLEXIBLE</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISFLEXIBLE"><span class="yiyi-st" id="yiyi-449"> <code class="descname">PyArray_ISFLEXIBLE</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-450">类型表示灵活数组类型之一(<a class="reference internal" href="c-api.dtype.html#c.NPY_STRING" title="NPY_STRING"><code class="xref c c-data docutils literal"><span class="pre">NPY_STRING</span></code></a>,<a class="reference internal" href="c-api.dtype.html#c.NPY_UNICODE" title="NPY_UNICODE"><code class="xref c c-data docutils literal"><span class="pre">NPY_UNICODE</span></code></a>或<a class="reference internal" href="c-api.dtype.html#c.NPY_VOID" title="NPY_VOID"><code class="xref c c-data docutils literal"><span class="pre">NPY_VOID</span></code></a>)。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISUSERDEF"><span class="yiyi-st" id="yiyi-451"> <code class="descname">PyTypeNum_ISUSERDEF</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISUSERDEF"><span class="yiyi-st" id="yiyi-452"> <code class="descname">PyDataType_ISUSERDEF</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISUSERDEF"><span class="yiyi-st" id="yiyi-453"> <code class="descname">PyArray_ISUSERDEF</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-454">类型表示用户定义的类型。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISEXTENDED"><span class="yiyi-st" id="yiyi-455"> <code class="descname">PyTypeNum_ISEXTENDED</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISEXTENDED"><span class="yiyi-st" id="yiyi-456"> <code class="descname">PyDataType_ISEXTENDED</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISEXTENDED"><span class="yiyi-st" id="yiyi-457"> <code class="descname">PyArray_ISEXTENDED</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-458">类型是灵活的或用户定义的。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISOBJECT"><span class="yiyi-st" id="yiyi-459"> <code class="descname">PyTypeNum_ISOBJECT</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISOBJECT"><span class="yiyi-st" id="yiyi-460"> <code class="descname">PyDataType_ISOBJECT</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISOBJECT"><span class="yiyi-st" id="yiyi-461"> <code class="descname">PyArray_ISOBJECT</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-462">类型表示对象数据类型。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTypeNum_ISBOOL"><span class="yiyi-st" id="yiyi-463"> <code class="descname">PyTypeNum_ISBOOL</code><span class="sig-paren">(</span>num<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyDataType_ISBOOL"><span class="yiyi-st" id="yiyi-464"> <code class="descname">PyDataType_ISBOOL</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_ISBOOL"><span class="yiyi-st" id="yiyi-465"> <code class="descname">PyArray_ISBOOL</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-466">类型表示布尔数据类型。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyDataType_HASFIELDS"><span class="yiyi-st" id="yiyi-467"> <code class="descname">PyDataType_HASFIELDS</code><span class="sig-paren">(</span>descr<span class="sig-paren">)</span></span></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.PyArray_HASFIELDS"><span class="yiyi-st" id="yiyi-468"> <code class="descname">PyArray_HASFIELDS</code><span class="sig-paren">(</span>obj<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-469">类型具有与其相关联的字段。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISNOTSWAPPED"><span class="yiyi-st" id="yiyi-470"> <code class="descname">PyArray_ISNOTSWAPPED</code><span class="sig-paren">(</span>m<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-471">根据数组的数据类型描述符,如果ndarray <em>m</em>的数据区域是机器字节顺序,则评估为真。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISBYTESWAPPED"><span class="yiyi-st" id="yiyi-472"> <code class="descname">PyArray_ISBYTESWAPPED</code><span class="sig-paren">(</span>m<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-473">根据数组的数据类型描述符,如果机器字节顺序中ndarray <em>m</em>的数据区不是<strong></strong>,则判断为真。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_EquivTypes"><span class="yiyi-st" id="yiyi-474"> Bool <code class="descname">PyArray_EquivTypes</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> type1</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> type2</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-475">返回<a class="reference internal" href="#c.NPY_TRUE" title="NPY_TRUE"><code class="xref c c-data docutils literal"><span class="pre">NPY_TRUE</span></code></a>如果<em>type1</em>和<em>type2</em>实际上代表此平台的等效类型(每个类型的fortran成员被忽略)。</span><span class="yiyi-st" id="yiyi-476">例如,在32位平台上,<a class="reference internal" href="c-api.dtype.html#c.NPY_LONG" title="NPY_LONG"><code class="xref c c-data docutils literal"><span class="pre">NPY_LONG</span></code></a>和<a class="reference internal" href="c-api.dtype.html#c.NPY_INT" title="NPY_INT"><code class="xref c c-data docutils literal"><span class="pre">NPY_INT</span></code></a>是等效的。</span><span class="yiyi-st" id="yiyi-477">否则返回<a class="reference internal" href="#c.NPY_FALSE" title="NPY_FALSE"><code class="xref c c-data docutils literal"><span class="pre">NPY_FALSE</span></code></a>。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_EquivArrTypes"><span class="yiyi-st" id="yiyi-478"> Bool <code class="descname">PyArray_EquivArrTypes</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> a1</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a> *<em> a2</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-479">如果<em>a1</em>和<em>a2</em>是具有此平台的等效类型的数组,则返回<a class="reference internal" href="#c.NPY_TRUE" title="NPY_TRUE"><code class="xref c c-data docutils literal"><span class="pre">NPY_TRUE</span></code></a>。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_EquivTypenums"><span class="yiyi-st" id="yiyi-480"> Bool <code class="descname">PyArray_EquivTypenums</code><span class="sig-paren">(</span>int<em> typenum1</em>, int<em> typenum2</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-481"><a class="reference internal" href="#c.PyArray_EquivTypes" title="PyArray_EquivTypes"><code class="xref c c-func docutils literal"><span class="pre">PyArray_EquivTypes</span></code></a>(...)的特殊情况,它不接受灵活的数据类型,但可能更容易调用。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_EquivByteorders"><span class="yiyi-st" id="yiyi-482"> int <code class="descname">PyArray_EquivByteorders</code><span class="sig-paren">(</span>{byteorder}<em> b1</em>, {byteorder}<em> b2</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-483">如果字节顺序字符(<code class="xref c c-data docutils literal"><span class="pre">NPY_LITTLE</span></code>,<code class="xref c c-data docutils literal"><span class="pre">NPY_BIG</span></code>,<code class="xref c c-data docutils literal"><span class="pre">NPY_NATIVE</span></code>,<code class="xref c c-data docutils literal"><span class="pre">NPY_IGNORE</span></code>)等于或等于其规格的本地字节顺序。</span><span class="yiyi-st" id="yiyi-484">因此,对于小端机器,<code class="xref c c-data docutils literal"><span class="pre">NPY_LITTLE</span></code>和<code class="xref c c-data docutils literal"><span class="pre">NPY_NATIVE</span></code>是等效的,它们在大端机器上不等效。</span></p>
</dd></dl>
</div>
<div class="section" id="converting-data-types">
<h3><span class="yiyi-st" id="yiyi-485">Converting data types</span></h3>
<dl class="function">
<dt id="c.PyArray_Cast"><span class="yiyi-st" id="yiyi-486"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_Cast</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> typenum</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-487">主要用于向后兼容数字C-API,以及用于简单转换为非灵活类型。</span><span class="yiyi-st" id="yiyi-488">返回一个具有<em>arr</em>元素的新数组对象转换为数据类型<em>typenum</em>,它必须是枚举类型之一,而不是灵活类型。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CastToType"><span class="yiyi-st" id="yiyi-489"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_CastToType</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> type</em>, int<em> fortran</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-490">返回指定的<em>类型</em>的新数组,适当地投射<em>arr</em>的元素。</span><span class="yiyi-st" id="yiyi-491">fortran参数指定输出数组的顺序。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CastTo"><span class="yiyi-st" id="yiyi-492"> int <code class="descname">PyArray_CastTo</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> in</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-493">从1.6开始,该函数只调用<a class="reference internal" href="#c.PyArray_CopyInto" title="PyArray_CopyInto"><code class="xref c c-func docutils literal"><span class="pre">PyArray_CopyInto</span></code></a>,它处理转换。</span></p>
<p><span class="yiyi-st" id="yiyi-494">将中数组<em>的元素转换为数组<em>out</em>。</em></span><span class="yiyi-st" id="yiyi-495">输出数组应该是可写的,具有输入数组中的元素数目的整数倍(多个副本可以放入输出),并且具有作为内置类型之一的数据类型。</span><span class="yiyi-st" id="yiyi-496">成功返回0,如果发生错误则返回-1。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_GetCastFunc"><span class="yiyi-st" id="yiyi-497"> PyArray_VectorUnaryFunc* <code class="descname">PyArray_GetCastFunc</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> from</em>, int<em> totype</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-498">返回低级别转换函数,从给定描述符转换为内置类型数。</span><span class="yiyi-st" id="yiyi-499">如果没有转换函数存在,返回<code class="docutils literal"><span class="pre">NULL</span></code>并设置错误。</span><span class="yiyi-st" id="yiyi-500">使用此函数而不是直接访问<em>从</em> - > f-> cast将允许支持添加到描述符转换字典中的任何用户定义的浇筑函数。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CanCastSafely"><span class="yiyi-st" id="yiyi-501"> int <code class="descname">PyArray_CanCastSafely</code><span class="sig-paren">(</span>int<em> fromtype</em>, int<em> totype</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-502">如果数据类型<em>fromtype</em>的数组可以转换为数据类型<em>totype</em>的数组,而不会丢失信息,则返回非零。</span><span class="yiyi-st" id="yiyi-503">一个例外是64位整数允许转换为64位浮点值,即使这样可能会丢失大整数的精度,以便在没有展开请求的情况下不增加使用长双精度。</span><span class="yiyi-st" id="yiyi-504">使用此功能,不会根据其长度检查灵活的数组类型。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CanCastTo"><span class="yiyi-st" id="yiyi-505"> int <code class="descname">PyArray_CanCastTo</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> fromtype</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> totype</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-506"><a class="reference internal" href="#c.PyArray_CanCastTypeTo" title="PyArray_CanCastTypeTo"><code class="xref c c-func docutils literal"><span class="pre">PyArray_CanCastTypeTo</span></code></a>在NumPy 1.6及更高版本中取代此函数。</span></p>
<p><span class="yiyi-st" id="yiyi-507">相当于PyArray_CanCastTypeTo(fromtype,totype,NPY_SAFE_CASTING)。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CanCastTypeTo"><span class="yiyi-st" id="yiyi-508"> int <code class="descname">PyArray_CanCastTypeTo</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> fromtype</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> totype</em>, <a class="reference internal" href="#c.NPY_CASTING" title="NPY_CASTING">NPY_CASTING</a><em> casting</em><span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-509"><span class="versionmodified">版本1.6中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-510">如果数据类型<em>fromtype</em>(可以包括灵活类型)的数组可以安全地转换到数据类型<em>totype</em>(可以包括灵活类型)的数组,则返回非零,根据铸造规则<em>铸造</em>。</span><span class="yiyi-st" id="yiyi-511">对于<a class="reference internal" href="#c.NPY_SAFE_CASTING" title="NPY_SAFE_CASTING"><code class="xref c c-data docutils literal"><span class="pre">NPY_SAFE_CASTING</span></code></a>的简单类型,这基本上是<a class="reference internal" href="#c.PyArray_CanCastSafely" title="PyArray_CanCastSafely"><code class="xref c c-func docutils literal"><span class="pre">PyArray_CanCastSafely</span></code></a>的包装,但对于诸如字符串或unicode的灵活类型,它会根据其大小生成结果。</span><span class="yiyi-st" id="yiyi-512">如果字符串或unicode类型大到足以容纳从中转换的整数/浮点类型的最大值,那么整数和浮点类型只能使用<a class="reference internal" href="#c.NPY_SAFE_CASTING" title="NPY_SAFE_CASTING"><code class="xref c c-data docutils literal"><span class="pre">NPY_SAFE_CASTING</span></code></a>转换为字符串或unicode类型。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_CanCastArrayTo"><span class="yiyi-st" id="yiyi-513"> int <code class="descname">PyArray_CanCastArrayTo</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> totype</em>, <a class="reference internal" href="#c.NPY_CASTING" title="NPY_CASTING">NPY_CASTING</a><em> casting</em><span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-514"><span class="versionmodified">版本1.6中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-515">如果<em>arr</em>可以根据<em>投射</em>中给出的投射规则投射到<em>totype</em>,则返回非零值。</span><span class="yiyi-st" id="yiyi-516">如果<em>arr</em>是数组标量,则会考虑其值,并且当值不会溢出或在转换为较小类型时被截断为整数时,也会返回非零。</span></p>
<p><span class="yiyi-st" id="yiyi-517">这几乎与PyArray_CanCastTypeTo(PyArray_MinScalarType(arr),totype,casting)的结果相同,但它也处理一个特殊情况,因为对于具有相同数量的类型,uint值的集合不是int值的子集位。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_MinScalarType"><span class="yiyi-st" id="yiyi-518"> <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="descname">PyArray_MinScalarType</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-519"><span class="versionmodified">版本1.6中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-520">如果<em>arr</em>是数组,则返回其数据类型描述符,但如果<em>arr</em>是数组标量(具有0个维度),则它会找到最小大小的数据类型值可以转换为不溢出或截断为整数。</span></p>
<p><span class="yiyi-st" id="yiyi-521">此函数不会将复数浮点型或任何布尔型降级为布尔型,但当标量值为正时将将有符号整数降级为无符号整数。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_PromoteTypes"><span class="yiyi-st" id="yiyi-522"> <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="descname">PyArray_PromoteTypes</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> type1</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> type2</em><span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-523"><span class="versionmodified">版本1.6中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-524">查找<em>type1</em>和<em>type2</em>可以安全转换的最小尺寸和种类的数据类型。</span><span class="yiyi-st" id="yiyi-525">此函数是对称和关联的。</span><span class="yiyi-st" id="yiyi-526">字符串或unicode结果将是存储转换为字符串或unicode的输入类型的最大值的正确大小。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ResultType"><span class="yiyi-st" id="yiyi-527"> <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="descname">PyArray_ResultType</code><span class="sig-paren">(</span>npy_intp<em> narrs</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>**arrs, npy_intp<em> ndtypes</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>**dtypes<span class="sig-paren">)</span></span></dt>
<dd><div class="versionadded">
<p><span class="yiyi-st" id="yiyi-528"><span class="versionmodified">版本1.6中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-529">这将类型提升应用于所有输入,使用用于组合标量和数组的NumPy规则来确定一组操作数的输出类型。</span><span class="yiyi-st" id="yiyi-530">这与ufuncs产生的结果类型相同。</span><span class="yiyi-st" id="yiyi-531">使用的具体算法如下。</span></p>
<p><span class="yiyi-st" id="yiyi-532">通过首先检查布尔值,整数(int / uint)或浮点(float / complex)中所有数组和标量的最大种类来确定类别。</span></p>
<p><span class="yiyi-st" id="yiyi-533">如果只有标量或标量的最大类别高于数组的最大类别,则数据类型与<a class="reference internal" href="#c.PyArray_PromoteTypes" title="PyArray_PromoteTypes"><code class="xref c c-func docutils literal"><span class="pre">PyArray_PromoteTypes</span></code></a>组合以生成返回值。</span></p>
<p><span class="yiyi-st" id="yiyi-534">否则,对每个数组调用PyArray_MinScalarType,并将生成的数据类型与<a class="reference internal" href="#c.PyArray_PromoteTypes" title="PyArray_PromoteTypes"><code class="xref c c-func docutils literal"><span class="pre">PyArray_PromoteTypes</span></code></a>组合以生成返回值。</span></p>
<p><span class="yiyi-st" id="yiyi-535">对于具有相同位数的类型,int值集合不是uint值的子集,而是在<a class="reference internal" href="#c.PyArray_MinScalarType" title="PyArray_MinScalarType"><code class="xref c c-func docutils literal"><span class="pre">PyArray_MinScalarType</span></code></a>中没有反映出来,但在PyArray_ResultType中作为特殊情况处理。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ObjectType"><span class="yiyi-st" id="yiyi-536"> int <code class="descname">PyArray_ObjectType</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em>, int<em> mintype</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-537">此函数由<a class="reference internal" href="#c.PyArray_MinScalarType" title="PyArray_MinScalarType"><code class="xref c c-func docutils literal"><span class="pre">PyArray_MinScalarType</span></code></a>和/或<a class="reference internal" href="#c.PyArray_ResultType" title="PyArray_ResultType"><code class="xref c c-func docutils literal"><span class="pre">PyArray_ResultType</span></code></a>替代。</span></p>
<p><span class="yiyi-st" id="yiyi-538">此函数用于确定两个或多个数组可以转换为的公共类型。</span><span class="yiyi-st" id="yiyi-539">它只适用于非灵活数组类型,因为没有传递项目信息。</span><span class="yiyi-st" id="yiyi-540"><em>mintype</em>参数表示可接受的最小类型,<em>op</em>表示将转换为数组的对象。</span><span class="yiyi-st" id="yiyi-541">返回值是表示<em>op</em>应该具有的数据类型的枚举类型号。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ArrayType"><span class="yiyi-st" id="yiyi-542"> void <code class="descname">PyArray_ArrayType</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> mintype</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> outtype</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-543">此函数由<a class="reference internal" href="#c.PyArray_ResultType" title="PyArray_ResultType"><code class="xref c c-func docutils literal"><span class="pre">PyArray_ResultType</span></code></a>替代。</span></p>
<p><span class="yiyi-st" id="yiyi-544">此函数与<a class="reference internal" href="#c.PyArray_ObjectType" title="PyArray_ObjectType"><code class="xref c c-func docutils literal"><span class="pre">PyArray_ObjectType</span></code></a>(...)类似,除了它处理灵活数组。</span><span class="yiyi-st" id="yiyi-545"><em>mintype</em>参数可以有一个itemize成员,并且<em>outtype</em>参数将有一个itemsize成员至少与对象<em>op</em> 。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ConvertToCommonType"><span class="yiyi-st" id="yiyi-546"> <a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>** <code class="descname">PyArray_ConvertToCommonType</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> op</em>, int*<em> n</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-547">它提供的功能在很大程度上被1.6中引入的迭代器<a class="reference internal" href="c-api.iterator.html#c.NpyIter" title="NpyIter"><code class="xref c c-type docutils literal"><span class="pre">NpyIter</span></code></a>所替代,标记为<a class="reference internal" href="c-api.iterator.html#c.NPY_ITER_COMMON_DTYPE" title="NPY_ITER_COMMON_DTYPE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ITER_COMMON_DTYPE</span></code></a>,或者对所有操作数使用相同的dtype参数。</span></p>
<p><span class="yiyi-st" id="yiyi-548">将<em>op</em>中包含的Python对象序列转换为每个都具有相同数据类型的ndarrays的数组。</span><span class="yiyi-st" id="yiyi-549">基于类型号(在较小的类型号上选择较大的类型号)选择类型,忽略只是标量的对象。</span><span class="yiyi-st" id="yiyi-550">序列的长度在<em>n</em>中返回,<a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><code class="xref c c-type docutils literal"><span class="pre">PyArrayObject</span></code></a>指针的<em>n</em>长度数组是返回值(或<code class="docutils literal"><span class="pre">NULL</span></code>如果发生错误)。</span><span class="yiyi-st" id="yiyi-551">返回的数组必须由此例程的调用者(使用<a class="reference internal" href="#c.PyDataMem_FREE" title="PyDataMem_FREE"><code class="xref c c-func docutils literal"><span class="pre">PyDataMem_FREE</span></code></a>)和其中的所有数组对象(<code class="docutils literal"><span class="pre">DECREF</span></code>'d)释放,否则将发生内存泄漏。</span><span class="yiyi-st" id="yiyi-552">下面的示例模板代码显示了一个典型的用法:</span></p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="n">mps</span> <span class="o">=</span> <span class="n">PyArray_ConvertToCommonType</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">mps</span><span class="o">==</span><span class="nb">NULL</span><span class="p">)</span> <span class="k">return</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="p">{</span><span class="n">code</span><span class="p">}</span>
<span class="o"><</span><span class="n">before</span> <span class="k">return</span><span class="o">></span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">Py_DECREF</span><span class="p">(</span><span class="n">mps</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">PyDataMem_FREE</span><span class="p">(</span><span class="n">mps</span><span class="p">);</span>
<span class="p">{</span><span class="k">return</span><span class="p">}</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_Zero"><span class="yiyi-st" id="yiyi-553"> char* <code class="descname">PyArray_Zero</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-554">指向大小为<em>arr</em> - > itemsize的新创建的内存的指针,它保存该类型的表示形式。</span><span class="yiyi-st" id="yiyi-555">当不再需要时,使用<a class="reference internal" href="#c.PyDataMem_FREE" title="PyDataMem_FREE"><code class="xref c c-func docutils literal"><span class="pre">PyDataMem_FREE</span></code></a>(ret)必须释放返回的指针<em>ret</em>,<strong></strong></span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_One"><span class="yiyi-st" id="yiyi-556"> char* <code class="descname">PyArray_One</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-557">指向大小为<em>arr</em> - > itemsize的新创建的内存的指针,它保存该类型的表示形式。</span><span class="yiyi-st" id="yiyi-558">当不再需要时,使用<a class="reference internal" href="#c.PyDataMem_FREE" title="PyDataMem_FREE"><code class="xref c c-func docutils literal"><span class="pre">PyDataMem_FREE</span></code></a>(ret)必须释放返回的指针<em>ret</em>,<strong></strong></span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ValidType"><span class="yiyi-st" id="yiyi-559"> int <code class="descname">PyArray_ValidType</code><span class="sig-paren">(</span>int<em> typenum</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-560">如果<em>typenum</em>表示有效的类型号(内置或用户定义或字符代码),则返回<a class="reference internal" href="#c.NPY_TRUE" title="NPY_TRUE"><code class="xref c c-data docutils literal"><span class="pre">NPY_TRUE</span></code></a>。</span><span class="yiyi-st" id="yiyi-561">否则,此函数返回<a class="reference internal" href="#c.NPY_FALSE" title="NPY_FALSE"><code class="xref c c-data docutils literal"><span class="pre">NPY_FALSE</span></code></a>。</span></p>
</dd></dl>
</div>
<div class="section" id="new-data-types">
<h3><span class="yiyi-st" id="yiyi-562">New data types</span></h3>
<dl class="function">
<dt id="c.PyArray_InitArrFuncs"><span class="yiyi-st" id="yiyi-563"> void <code class="descname">PyArray_InitArrFuncs</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_ArrFuncs" title="PyArray_ArrFuncs">PyArray_ArrFuncs</a>*<em> f</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-564">将所有函数指针和成员初始化为<code class="docutils literal"><span class="pre">NULL</span></code>。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_RegisterDataType"><span class="yiyi-st" id="yiyi-565"> int <code class="descname">PyArray_RegisterDataType</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-566">将数据类型注册为数组的新用户定义数据类型。</span><span class="yiyi-st" id="yiyi-567">类型必须填充大多数条目。</span><span class="yiyi-st" id="yiyi-568">这不总是被检查,错误可以产生segfaults。</span><span class="yiyi-st" id="yiyi-569">特别地,<code class="docutils literal"><span class="pre">dtype</span></code>结构的typeobj成员必须用具有对应于<em>dtype</em>的elsize成员的固定大小的元素大小的Python类型填充。</span><span class="yiyi-st" id="yiyi-570">此外,<code class="docutils literal"><span class="pre">f</span></code>成员必须具有必需的函数:非零,copyswap,copyswapn,getitem,setitem和cast(如果不需要支持,某些转换函数可以是<code class="docutils literal"><span class="pre">NULL</span></code> )。</span><span class="yiyi-st" id="yiyi-571">为了避免混淆,你应该选择一个唯一的字符类型,但这不是强制的,不是内部依赖。</span></p>
<p><span class="yiyi-st" id="yiyi-572">返回唯一标识类型的用户定义类型编号。</span><span class="yiyi-st" id="yiyi-573">然后可以使用返回的类型号从<a class="reference internal" href="#c.PyArray_DescrFromType" title="PyArray_DescrFromType"><code class="xref c c-func docutils literal"><span class="pre">PyArray_DescrFromType</span></code></a>获取指向新结构的指针。</span><span class="yiyi-st" id="yiyi-574">如果发生错误,则返回-1。</span><span class="yiyi-st" id="yiyi-575">如果此<em>dtype</em>已经注册(仅由指针的地址检查),则返回先前分配的类型号。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_RegisterCastFunc"><span class="yiyi-st" id="yiyi-576"> int <code class="descname">PyArray_RegisterCastFunc</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em>, int<em> totype</em>, PyArray_VectorUnaryFunc*<em> castfunc</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-577">注册低级别转换函数<em>castfunc</em>,将数据类型<em>descr</em>转换为给定的数据类型编号<em>totype</em> 。</span><span class="yiyi-st" id="yiyi-578">任何旧的铸造功能都被覆盖。</span><span class="yiyi-st" id="yiyi-579">成功时返回<code class="docutils literal"><span class="pre">0</span></code>或失败时返回<code class="docutils literal"><span class="pre">-1</span></code>。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_RegisterCanCast"><span class="yiyi-st" id="yiyi-580"> int <code class="descname">PyArray_RegisterCanCast</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em>, int<em> totype</em>, <a class="reference internal" href="#c.NPY_SCALARKIND" title="NPY_SCALARKIND">NPY_SCALARKIND</a><em> scalar</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-581">从给定的<em>标量</em>类型的数据类型对象<em>descr</em>注册数据类型号<em>totype</em></span><span class="yiyi-st" id="yiyi-582">使用<em>标量</em> = <code class="xref c c-data docutils literal"><span class="pre">NPY_NOSCALAR</span></code>注册数据类型<em>descr</em>的数组可以安全地转换为type_number为<em>totype</em>。</span></p>
</dd></dl>
</div>
<div class="section" id="special-functions-for-npy-object">
<h3><span class="yiyi-st" id="yiyi-583">Special functions for NPY_OBJECT</span></h3>
<dl class="function">
<dt id="c.PyArray_INCREF"><span class="yiyi-st" id="yiyi-584"> int <code class="descname">PyArray_INCREF</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> op</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-585">用于包含任何Python对象的数组<em>op</em>。</span><span class="yiyi-st" id="yiyi-586">它根据<em>op</em>的数据类型增加数组中每个对象的引用计数。</span><span class="yiyi-st" id="yiyi-587">如果发生错误,则返回-1,否则返回0。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_Item_INCREF"><span class="yiyi-st" id="yiyi-588"> void <code class="descname">PyArray_Item_INCREF</code><span class="sig-paren">(</span>char*<em> ptr</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-589">根据数据类型<em>dtype</em>,在位置<em>ptr</em>处对所有对象进行INCREF的函数。</span><span class="yiyi-st" id="yiyi-590">如果<em>ptr</em>是具有任何偏移量的对象的结构化类型的开始,则这将(递归地)增加结构化类型中所有类似对象的项的引用计数。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_XDECREF"><span class="yiyi-st" id="yiyi-591"> int <code class="descname">PyArray_XDECREF</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> op</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-592">用于包含任何Python对象的数组<em>op</em>。</span><span class="yiyi-st" id="yiyi-593">它根据<em>op</em>的数据类型减少数组中每个对象的引用计数。</span><span class="yiyi-st" id="yiyi-594">正常返回值为0。</span><span class="yiyi-st" id="yiyi-595">如果发生错误,则返回-1。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_Item_XDECREF"><span class="yiyi-st" id="yiyi-596"> void <code class="descname">PyArray_Item_XDECREF</code><span class="sig-paren">(</span>char*<em> ptr</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-597">XDECREF函数用于记录数据类型<em>dtype</em>中位置<em>ptr</em>的所有类似对象的项目。</span><span class="yiyi-st" id="yiyi-598">这样递归地工作,以便如果<code class="docutils literal"><span class="pre">dtype</span></code>本身具有包含类似对象的项的数据类型的字段,则所有类似于对象的字段将是XDECREF <code class="docutils literal"><span class="pre">'d</span></code>。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_FillObjectArray"><span class="yiyi-st" id="yiyi-599"> void <code class="descname">PyArray_FillObjectArray</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-600">使用对象数据类型在结构中的所有位置使用单个值obj填充新创建的数组。</span><span class="yiyi-st" id="yiyi-601">不执行检查,但<em>arr</em>必须是数据类型<a class="reference internal" href="c-api.dtype.html#c.NPY_OBJECT" title="NPY_OBJECT"><code class="xref c c-type docutils literal"><span class="pre">NPY_OBJECT</span></code></a>,并且是单段和未初始化的(位置中没有上一个对象)。</span><span class="yiyi-st" id="yiyi-602">如果您需要在调用此函数之前减少对象数组中的所有项目,请使用<code class="xref c c-func docutils literal"><span class="pre">PyArray_DECREF</span></code>(<em>arr</em>)。</span></p>
</dd></dl>
</div>
</div>
<div class="section" id="array-flags">
<h2><span class="yiyi-st" id="yiyi-603">Array flags</span></h2>
<p><span class="yiyi-st" id="yiyi-604"><code class="docutils literal"><span class="pre">PyArrayObject</span></code>结构的<code class="docutils literal"><span class="pre">flags</span></code>属性包含数组(由数据成员指向)使用的内存的重要信息。此标志信息必须保持准确或奇怪的结果,甚至可能导致硒缺陷。</span></p>
<p><span class="yiyi-st" id="yiyi-605">有6个(二进制)标志,描述数据缓冲区使用的存储区。</span><span class="yiyi-st" id="yiyi-606">这些常数在<code class="docutils literal"><span class="pre">arrayobject.h</span></code>中定义,并确定标志的位位置。</span><span class="yiyi-st" id="yiyi-607">Python公开了一个很好的基于属性的接口以及一个类似字典的接口,用于获取(和,如果适当的话)这些标志。</span></p>
<p><span class="yiyi-st" id="yiyi-608">所有种类的存储器区域可以由ndarray指向,需要这些标志。</span><span class="yiyi-st" id="yiyi-609">如果你在C代码中得到一个任意的<code class="docutils literal"><span class="pre">PyArrayObject</span></code>,你需要知道设置的标志。</span><span class="yiyi-st" id="yiyi-610">如果你需要保证某种数组(如<a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a>和<a class="reference internal" href="#c.NPY_ARRAY_BEHAVED" title="NPY_ARRAY_BEHAVED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_BEHAVED</span></code></a>),那么将这些需求传递到PyArray_FromAny函数中。</span></p>
<div class="section" id="basic-array-flags">
<h3><span class="yiyi-st" id="yiyi-611">Basic Array Flags</span></h3>
<p><span class="yiyi-st" id="yiyi-612">一个ndarray可以有一个数据段,不是一个简单的连续块的良好的记忆你可以操纵。</span><span class="yiyi-st" id="yiyi-613">它可能不与字边界对齐(在某些平台上非常重要)。</span><span class="yiyi-st" id="yiyi-614">它可能具有不同于机器识别的字节顺序的数据。</span><span class="yiyi-st" id="yiyi-615">它可能不可写。</span><span class="yiyi-st" id="yiyi-616">它可能是Fortan连续的顺序。</span><span class="yiyi-st" id="yiyi-617">数组标志用于指示关于与数组相关联的数据的内容。</span></p>
<p><span class="yiyi-st" id="yiyi-618">在NumPy的1.6版本和更早版本中,以下标志中没有_ARRAY_宏命名空间。</span><span class="yiyi-st" id="yiyi-619">这种形式的常量名在1.7中已被弃用。</span></p>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-620"><code class="descname">NPY_ARRAY_C_CONTIGUOUS</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-621">数据区以C样式连续顺序(最后索引变化最快)。</span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-622"><code class="descname">NPY_ARRAY_F_CONTIGUOUS</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-623">数据区域是Fortran风格的连续顺序(第一个索引变化最快)。</span></p>
</dd></dl>
<div class="admonition note">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-624">注意</span></p>
<p><span class="yiyi-st" id="yiyi-625">数组可以同时是C风格和Fortran风格的。</span><span class="yiyi-st" id="yiyi-626">这对于1维数组是清楚的,但对于更高维数组也是如此。</span></p>
<p><span class="yiyi-st" id="yiyi-627">Even for contiguous arrays a stride for a given dimension <code class="docutils literal"><span class="pre">arr.strides[dim]</span></code> may be <em>arbitrary</em> if <code class="docutils literal"><span class="pre">arr.shape[dim]</span> <span class="pre">==</span> <span class="pre">1</span></code> or the array has no elements. </span><span class="yiyi-st" id="yiyi-628"><em>不</em>一般认为<code class="docutils literal"><span class="pre">self.strides [-1]</span> <span class="pre">==</span> <span class="pre">self.itemsize</span> / t1>用于C型连续数组或<code class="docutils literal"><span class="pre">self.strides [0]</span> <span class="pre">==</span> <span class="pre">self.itemsize</span> Fortran风格的连续数组是真的。</code></code></span><span class="yiyi-st" id="yiyi-629">从C API访问数组的<code class="docutils literal"><span class="pre">itemsize</span></code>的正确方法是<code class="docutils literal"><span class="pre">PyArray_ITEMSIZE(arr)</span></code>。</span></p>
<div class="last admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-630">也可以看看</span></p>
<p class="last"><span class="yiyi-st" id="yiyi-631"><a class="reference internal" href="arrays.ndarray.html#arrays-ndarray"><span class="std std-ref">Internal memory layout of an ndarray</span></a></span></p>
</div>
</div>
<dl class="var">
<dt id="c.NPY_ARRAY_OWNDATA"><span class="yiyi-st" id="yiyi-632"> <code class="descname">NPY_ARRAY_OWNDATA</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-633">数据区由此数组所有。</span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-634"><code class="descname">NPY_ARRAY_ALIGNED</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-635">数据区和所有数组元素都对齐。</span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-636"><code class="descname">NPY_ARRAY_WRITEABLE</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-637">数据区可以写入。</span></p>
<p><span class="yiyi-st" id="yiyi-638">注意,上面的3个标志是定义的,所以一个新的,行为良好的数组有这些标志被定义为真。</span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-639"><code class="descname">NPY_ARRAY_UPDATEIFCOPY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-640">数据区表示一个(行为良好的)副本,当删除此数组时,该副本的信息应该被传回原始。</span></p>
<p><span class="yiyi-st" id="yiyi-641">这是一个特殊的标志,如果这个数组代表一个拷贝,因为用户需要在<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a>中的某些标志,并且一个副本必须由其他数组组成(并且用户要求这个标志在这种情况下设置)。</span><span class="yiyi-st" id="yiyi-642">base属性然后指向“misbehaved”数组(设置为read_only)。</span><span class="yiyi-st" id="yiyi-643">当具有此标志集的数组被解除分配时,它将其内容复制回“错误的”数组(如果必要的话),并将“错误的”数组重置为<a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a>。</span><span class="yiyi-st" id="yiyi-644">如果“misbehaved”数组不是<a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a>开始,则<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a>将返回错误,因为不能使用<a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a>。</span></p>
</dd></dl>
<p><span class="yiyi-st" id="yiyi-645"><a class="reference internal" href="#c.PyArray_UpdateFlags" title="PyArray_UpdateFlags"><code class="xref c c-func docutils literal"><span class="pre">PyArray_UpdateFlags</span></code></a> (obj, flags) will update the <code class="docutils literal"><span class="pre">obj->flags</span></code> for <code class="docutils literal"><span class="pre">flags</span></code> which can be any of <a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a>, or <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a>.</span></p>
</div>
<div class="section" id="combinations-of-array-flags">
<h3><span class="yiyi-st" id="yiyi-646">Combinations of array flags</span></h3>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-647"><code class="descname">NPY_ARRAY_BEHAVED</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-648"><a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-649"><code class="descname">NPY_ARRAY_CARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-650"><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_BEHAVED" title="NPY_ARRAY_BEHAVED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_BEHAVED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-651"><code class="descname">NPY_ARRAY_CARRAY_RO</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-652"><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-653"><code class="descname">NPY_ARRAY_FARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-654"><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_BEHAVED" title="NPY_ARRAY_BEHAVED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_BEHAVED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-655"><code class="descname">NPY_ARRAY_FARRAY_RO</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-656"><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-657"><code class="descname">NPY_ARRAY_DEFAULT</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-658"><a class="reference internal" href="#c.NPY_ARRAY_CARRAY" title="NPY_ARRAY_CARRAY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_CARRAY</span></code></a></span></p>
</dd></dl>
<dl class="var">
<dt id="c.NPY_ARRAY_UPDATE_ALL"><span class="yiyi-st" id="yiyi-659"> <code class="descname">NPY_ARRAY_UPDATE_ALL</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-660"><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></span></p>
</dd></dl>
</div>
<div class="section" id="flag-like-constants">
<h3><span class="yiyi-st" id="yiyi-661">Flag-like constants</span></h3>
<p><span class="yiyi-st" id="yiyi-662">这些常量在<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_FromAny</span></code></a>(及其宏形式)中用于指定新数组的所需属性。</span></p>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-663"><code class="descname">NPY_ARRAY_FORCECAST</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-664">投射到所需类型,即使它不能在不丢失信息的情况下完成。</span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-665"><code class="descname">NPY_ARRAY_ENSURECOPY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-666">确保生成的数组是原始数据的副本。</span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-667"><code class="descname">NPY_ARRAY_ENSUREARRAY</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-668">确保生成的对象是实际的ndarray(或bigndarray),而不是子类。</span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-669"><code class="descname">NPY_ARRAY_NOTSWAPPED</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-670">仅在<a class="reference internal" href="#c.PyArray_CheckFromAny" title="PyArray_CheckFromAny"><code class="xref c c-func docutils literal"><span class="pre">PyArray_CheckFromAny</span></code></a>中用于覆盖传入的数据类型对象的字节顺序。</span></p>
</dd></dl>
<dl class="var">
<dt><span class="yiyi-st" id="yiyi-671"><code class="descname">NPY_ARRAY_BEHAVED_NS</code></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-672"><a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_NOTSWAPPED" title="NPY_ARRAY_NOTSWAPPED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_NOTSWAPPED</span></code></a></span></p>
</dd></dl>
</div>
<div class="section" id="flag-checking">
<h3><span class="yiyi-st" id="yiyi-673">Flag checking</span></h3>
<p><span class="yiyi-st" id="yiyi-674">对于所有这些宏<em>arr</em>必须是<code class="xref c c-data docutils literal"><span class="pre">PyArray_Type</span></code>(的子类)的实例,但不进行检查。</span></p>
<dl class="function">
<dt id="c.PyArray_CHKFLAGS"><span class="yiyi-st" id="yiyi-675"> <code class="descname">PyArray_CHKFLAGS</code><span class="sig-paren">(</span>arr, flags<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-676">第一个参数arr必须是一个ndarray或子类。</span><span class="yiyi-st" id="yiyi-677">参数<em>flags</em>应为包含数组可能具有的标志的按位组合的整数:<a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a>,<a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a>,<a class="reference internal" href="#c.NPY_ARRAY_OWNDATA" title="NPY_ARRAY_OWNDATA"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_OWNDATA</span></code></a>,<a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a>,<a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a>,<a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a>。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_IS_C_CONTIGUOUS"><span class="yiyi-st" id="yiyi-678"> <code class="descname">PyArray_IS_C_CONTIGUOUS</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-679">如果<em>arr</em>是C样式连续,则计算true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_IS_F_CONTIGUOUS"><span class="yiyi-st" id="yiyi-680"> <code class="descname">PyArray_IS_F_CONTIGUOUS</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-681">如果<em>arr</em>是Fortran风格连续,则计算true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISFORTRAN"><span class="yiyi-st" id="yiyi-682"> <code class="descname">PyArray_ISFORTRAN</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-683">如果<em>arr</em>是Fortran风格连续且<em>不是</em> C风格连续,则评估为true。</span><span class="yiyi-st" id="yiyi-684"><a class="reference internal" href="#c.PyArray_IS_F_CONTIGUOUS" title="PyArray_IS_F_CONTIGUOUS"><code class="xref c c-func docutils literal"><span class="pre">PyArray_IS_F_CONTIGUOUS</span></code></a>是测试Fortran风格邻接的正确方法。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISWRITEABLE"><span class="yiyi-st" id="yiyi-685"> <code class="descname">PyArray_ISWRITEABLE</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-686">如果<em>arr</em>的数据区可以写入,则评估为true</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISALIGNED"><span class="yiyi-st" id="yiyi-687"> <code class="descname">PyArray_ISALIGNED</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-688">如果<em>arr</em>的数据区在机器上正确对齐,则评估为true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISBEHAVED"><span class="yiyi-st" id="yiyi-689"> <code class="descname">PyArray_ISBEHAVED</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-690">如果<em>arr</em>的数据区域根据其描述符对齐和可写,并按机器字节顺序,则计算true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISBEHAVED_RO"><span class="yiyi-st" id="yiyi-691"> <code class="descname">PyArray_ISBEHAVED_RO</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-692">如果<em>arr</em>的数据区域以机器字节顺序对齐,则评估为true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISCARRAY"><span class="yiyi-st" id="yiyi-693"> <code class="descname">PyArray_ISCARRAY</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-694">如果<em>arr</em>的数据区域是C样式连续的,并且<a class="reference internal" href="#c.PyArray_ISBEHAVED" title="PyArray_ISBEHAVED"><code class="xref c c-func docutils literal"><span class="pre">PyArray_ISBEHAVED</span></code></a>(<em>arr</em>)为真,则评估为true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISFARRAY"><span class="yiyi-st" id="yiyi-695"> <code class="descname">PyArray_ISFARRAY</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-696">如果<em>arr</em>的数据区域是Fortran式连续且<a class="reference internal" href="#c.PyArray_ISBEHAVED" title="PyArray_ISBEHAVED"><code class="xref c c-func docutils literal"><span class="pre">PyArray_ISBEHAVED</span></code></a>(<em>arr</em>)为真,则评估为true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISCARRAY_RO"><span class="yiyi-st" id="yiyi-697"> <code class="descname">PyArray_ISCARRAY_RO</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-698">如果<em>arr</em>的数据区是C样式连续,对齐和以机器字节顺序,则评估为true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISFARRAY_RO"><span class="yiyi-st" id="yiyi-699"> <code class="descname">PyArray_ISFARRAY_RO</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-700">如果<em>arr</em>的数据区域是Fortran风格的连续,对齐,并且在机器字节顺序<strong>中,则评估为真。</strong></span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_ISONESEGMENT"><span class="yiyi-st" id="yiyi-701"> <code class="descname">PyArray_ISONESEGMENT</code><span class="sig-paren">(</span>arr<span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-702">如果<em>arr</em>的数据区域由单个(C风格或Fortran风格)连续段组成,则评估为true。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_UpdateFlags"><span class="yiyi-st" id="yiyi-703"> void <code class="descname">PyArray_UpdateFlags</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> flagmask</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-704">可以从数组对象本身“计算”<a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a>,<a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a>和<a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a>数组标志。</span><span class="yiyi-st" id="yiyi-705">此例程通过执行所需的计算,更新<em>flagmask</em>中指定的<em>arr</em>的一个或多个标志。</span></p>
</dd></dl>
<div class="admonition warning">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-706">警告</span></p>
<p class="last"><span class="yiyi-st" id="yiyi-707">每当使用数组进行可能导致它们更改的操作时,保持标记更新(使用<a class="reference internal" href="#c.PyArray_UpdateFlags" title="PyArray_UpdateFlags"><code class="xref c c-func docutils literal"><span class="pre">PyArray_UpdateFlags</span></code></a>可以帮助)是非常重要的。</span><span class="yiyi-st" id="yiyi-708">后来在NumPy中依赖这些标志的状态的计算不重复计算来更新它们。</span></p>
</div>
</div>
</div>
<div class="section" id="array-method-alternative-api">
<h2><span class="yiyi-st" id="yiyi-709">Array method alternative API</span></h2>
<div class="section" id="conversion">
<h3><span class="yiyi-st" id="yiyi-710">Conversion</span></h3>
<dl class="function">
<dt id="c.PyArray_GetField"><span class="yiyi-st" id="yiyi-711"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_GetField</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> offset</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-712">等同于<code class="xref py py-meth docutils literal"><span class="pre">ndarray.getfield</span></code>(<em>self</em>,<em>dtype</em>,<em>offset</em>)。</span><span class="yiyi-st" id="yiyi-713">使用当前数组中指定的<em>偏移量</em>中的数据(以字节为单位)返回给定<em>dtype</em>的新数组。</span><span class="yiyi-st" id="yiyi-714"><em>偏移</em>加上新数组类型的itemsize必须小于<em>self</em> - > descr-> elsize或出现错误。</span><span class="yiyi-st" id="yiyi-715">使用与原数组相同的形状和步幅。</span><span class="yiyi-st" id="yiyi-716">因此,此函数具有从结构化数组返回字段的效果。</span><span class="yiyi-st" id="yiyi-717">但是,它也可以用于从任何数组类型中选择特定字节或字节组。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_SetField"><span class="yiyi-st" id="yiyi-718"> int <code class="descname">PyArray_SetField</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference internal" href="c-api.types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> offset</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>*<em> val</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-719">等效于<code class="xref py py-meth docutils literal"><span class="pre">ndarray.setfield</span></code>(<em>self</em>,<em>val</em>,<em>dtype</em>,<em>offset</em>)。</span><span class="yiyi-st" id="yiyi-720">Set the field starting at <em>offset</em> in bytes and of the given <em>dtype</em> to <em>val</em>. </span><span class="yiyi-st" id="yiyi-721"><em>偏移</em>加上<em>dtype</em> - > elsize必须小于<em>self</em> - > descr-> elsize或出现错误。</span><span class="yiyi-st" id="yiyi-722">否则,<em>val</em>参数将转换为数组并复制到指向的字段中。</span><span class="yiyi-st" id="yiyi-723">如果需要,重复<em>val</em>的元素以填充目标数组。但是,目标中的元素数必须是<em>val</em>中元素数的整数倍数。 。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_Byteswap"><span class="yiyi-st" id="yiyi-724"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_Byteswap</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, Bool<em> inplace</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-725">等效于<code class="xref py py-meth docutils literal"><span class="pre">ndarray.byteswap</span></code>(<em>self</em>,<em>inplace</em>)。</span><span class="yiyi-st" id="yiyi-726">返回其数据区域已进行字节交换的数组。</span><span class="yiyi-st" id="yiyi-727">如果<em>inplace</em>为非零,则执行byteswap inplace并返回对self的引用。</span><span class="yiyi-st" id="yiyi-728">否则,创建字节交换副本并保持不变。</span></p>
</dd></dl>
<dl class="function">
<dt id="c.PyArray_NewCopy"><span class="yiyi-st" id="yiyi-729"> <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.7)">PyObject</a>* <code class="descname">PyArray_NewCopy</code><span class="sig-paren">(</span><a class="reference internal" href="c-api.types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> old</em>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER">NPY_ORDER</a><em> order</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-730">等同于<code class="xref py py-meth docutils literal"><span class="pre">ndarray.copy</span></code>(<em>self</em>,<em>fortran</em>)。</span><span class="yiyi-st" id="yiyi-731">制作<em>旧</em>数组的副本。</span><span class="yiyi-st" id="yiyi-732">返回的数组总是对齐和可写的,数据解释与旧数组相同。</span><span class="yiyi-st" id="yiyi-733">如果<em>order</em>是<a class="reference internal" href="#c.NPY_CORDER" title="NPY_CORDER"><code class="xref c c-data docutils literal"><span class="pre">NPY_CORDER</span></code></a>,则返回C风格的连续数组。</span><span class="yiyi-st" id="yiyi-734">如果<em>order</em>是<a class="reference internal" href="#c.NPY_FORTRANORDER" title="NPY_FORTRANORDER"><code class="xref c c-data docutils literal"><span class="pre">NPY_FORTRANORDER</span></code></a>,则返回Fortran风格的连续数组。</span><span class="yiyi-st" id="yiyi-735">如果<em>顺序是</em> <a class="reference internal" href="#c.NPY_ANYORDER" title="NPY_ANYORDER"><code class="xref c c-data docutils literal"><span class="pre">NPY_ANYORDER</span></code></a>,则返回的数组是Fortran风格的连续的,如果旧的;否则,它是C型连续的。</span></p>
</dd></dl>
<dl class="function">