-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy patharray.html
5874 lines (5166 loc) · 719 KB
/
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
<!DOCTYPE html>
<html lang="en" data-content_root="../../" data-theme="light">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Array API — NumPy v2.3.dev0 Manual</title>
<script data-cfasync="false">
document.documentElement.dataset.mode = localStorage.getItem("mode") || "light";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "light";
</script>
<!--
this give us a css class that will be invisible only if js is disabled
-->
<noscript>
<style>
.pst-js-only { display: none !important; }
</style>
</noscript>
<!-- Loaded before other Sphinx assets -->
<link href="../../_static/styles/theme.css?digest=8878045cc6db502f8baf" rel="stylesheet" />
<link href="../../_static/styles/pydata-sphinx-theme.css?digest=8878045cc6db502f8baf" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=8f2a1f02" />
<link rel="stylesheet" type="text/css" href="../../_static/graphviz.css?v=eafc0fe6" />
<link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
<link rel="stylesheet" type="text/css" href="../../_static/copybutton.css?v=76b2166b" />
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Vibur" />
<link rel="stylesheet" type="text/css" href="../../_static/jupyterlite_sphinx.css?v=2c9f8f05" />
<link rel="stylesheet" type="text/css" href="../../_static/sphinx-design.min.css?v=95c83b7e" />
<link rel="stylesheet" type="text/css" href="../../_static/numpy.css?v=a1b581f7" />
<!-- So that users can add custom icons -->
<script src="../../_static/scripts/fontawesome.js?digest=8878045cc6db502f8baf"></script>
<!-- Pre-loaded scripts that we'll load fully later -->
<link rel="preload" as="script" href="../../_static/scripts/bootstrap.js?digest=8878045cc6db502f8baf" />
<link rel="preload" as="script" href="../../_static/scripts/pydata-sphinx-theme.js?digest=8878045cc6db502f8baf" />
<script src="../../_static/documentation_options.js?v=22d62b46"></script>
<script src="../../_static/doctools.js?v=888ff710"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/clipboard.min.js?v=a7894cd8"></script>
<script src="../../_static/copybutton.js?v=30646c52"></script>
<script src="../../_static/jupyterlite_sphinx.js?v=96e329c5"></script>
<script src="../../_static/design-tabs.js?v=f930bc37"></script>
<script async="async" src="../../_static/scipy-mathjax/MathJax.js?config=scipy-mathjax"></script>
<script>DOCUMENTATION_OPTIONS.pagename = 'reference/c-api/array';</script>
<script>
DOCUMENTATION_OPTIONS.theme_version = '0.16.1';
DOCUMENTATION_OPTIONS.theme_switcher_json_url = 'https://numpy.org/doc/_static/versions.json';
DOCUMENTATION_OPTIONS.theme_switcher_version_match = 'devdocs';
DOCUMENTATION_OPTIONS.show_version_warning_banner =
true;
</script>
<link rel="icon" href="../../_static/favicon.ico"/>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Array iterator API" href="iterator.html" />
<link rel="prev" title="Data type API" href="dtype.html" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="docsearch:language" content="en"/>
<meta name="docsearch:version" content="2.3.dev0" />
<meta name="docbuild:last-update" content="Apr 24, 2025"/>
</head>
<body data-bs-spy="scroll" data-bs-target=".bd-toc-nav" data-offset="180" data-bs-root-margin="0px 0px -60%" data-default-mode="light">
<div id="pst-skip-link" class="skip-link d-print-none"><a href="#main-content">Skip to main content</a></div>
<div id="pst-scroll-pixel-helper"></div>
<button type="button" class="btn rounded-pill" id="pst-back-to-top">
<i class="fa-solid fa-arrow-up"></i>Back to top</button>
<dialog id="pst-search-dialog">
<form class="bd-search d-flex align-items-center"
action="../../search.html"
method="get">
<i class="fa-solid fa-magnifying-glass"></i>
<input type="search"
class="form-control"
name="q"
placeholder="Search the docs ..."
aria-label="Search the docs ..."
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"/>
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span>
</form>
</dialog>
<div class="pst-async-banner-revealer d-none">
<aside id="bd-header-version-warning" class="d-none d-print-none" aria-label="Version warning"></aside>
</div>
<header class="bd-header navbar navbar-expand-lg bd-navbar d-print-none">
<div class="bd-header__inner bd-page-width">
<button class="pst-navbar-icon sidebar-toggle primary-toggle" aria-label="Site navigation">
<span class="fa-solid fa-bars"></span>
</button>
<div class="col-lg-3 navbar-header-items__start">
<div class="navbar-item">
<a class="navbar-brand logo" href="../../index.html">
<img src="../../_static/numpylogo.svg" class="logo__image only-light" alt="NumPy v2.3.dev0 Manual - Home"/>
<img src="../../_static/numpylogo_dark.svg" class="logo__image only-dark pst-js-only" alt="NumPy v2.3.dev0 Manual - Home"/>
</a></div>
</div>
<div class="col-lg-9 navbar-header-items">
<div class="me-auto navbar-header-items__center">
<div class="navbar-item">
<nav>
<ul class="bd-navbar-elements navbar-nav">
<li class="nav-item ">
<a class="nav-link nav-internal" href="../../user/index.html">
User Guide
</a>
</li>
<li class="nav-item current active">
<a class="nav-link nav-internal" href="../index.html">
API reference
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="../../building/index.html">
Building from source
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="../../dev/index.html">
Development
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="../../release.html">
Release notes
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-external" href="https://numpy.org/numpy-tutorials/">
Learn
</a>
</li>
<li class="nav-item dropdown">
<button class="btn dropdown-toggle nav-item" type="button"
data-bs-toggle="dropdown" aria-expanded="false"
aria-controls="pst-nav-more-links">
More
</button>
<ul id="pst-nav-more-links" class="dropdown-menu">
<li class=" ">
<a class="nav-link dropdown-item nav-external" href="https://numpy.org/neps">
NEPs
</a>
</li>
</ul>
</li>
</ul>
</nav></div>
</div>
<div class="navbar-header-items__end">
<div class="navbar-item">
<button class="btn btn-sm pst-navbar-icon search-button search-button__button pst-js-only" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass fa-lg"></i>
</button></div>
<div class="navbar-item">
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" aria-label="Color mode" data-bs-title="Color mode" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light" title="Light"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark" title="Dark"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto" title="System Settings"></i>
</button></div>
<div class="navbar-item">
<div class="version-switcher__container dropdown pst-js-only">
<button id="pst-version-switcher-button-2"
type="button"
class="version-switcher__button btn btn-sm dropdown-toggle"
data-bs-toggle="dropdown"
aria-haspopup="listbox"
aria-controls="pst-version-switcher-list-2"
aria-label="Version switcher list"
>
Choose version <!-- this text may get changed later by javascript -->
<span class="caret"></span>
</button>
<div id="pst-version-switcher-list-2"
class="version-switcher__menu dropdown-menu list-group-flush py-0"
role="listbox" aria-labelledby="pst-version-switcher-button-2">
<!-- dropdown will be populated by javascript on page load -->
</div>
</div></div>
<div class="navbar-item"><ul class="navbar-icon-links"
aria-label="Icon Links">
<li class="nav-item">
<a href="https://github.com/numpy/numpy" title="GitHub" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-square-github fa-lg" aria-hidden="true"></i>
<span class="sr-only">GitHub</span></a>
</li>
</ul></div>
</div>
</div>
<button class="pst-navbar-icon sidebar-toggle secondary-toggle" aria-label="On this page">
<span class="fa-solid fa-outdent"></span>
</button>
</div>
</header>
<div class="bd-container">
<div class="bd-container__inner bd-page-width">
<dialog id="pst-primary-sidebar-modal"></dialog>
<div id="pst-primary-sidebar" class="bd-sidebar-primary bd-sidebar">
<div class="sidebar-header-items sidebar-primary__section">
<div class="sidebar-header-items__center">
<div class="navbar-item">
<nav>
<ul class="bd-navbar-elements navbar-nav">
<li class="nav-item ">
<a class="nav-link nav-internal" href="../../user/index.html">
User Guide
</a>
</li>
<li class="nav-item current active">
<a class="nav-link nav-internal" href="../index.html">
API reference
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="../../building/index.html">
Building from source
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="../../dev/index.html">
Development
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-internal" href="../../release.html">
Release notes
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-external" href="https://numpy.org/numpy-tutorials/">
Learn
</a>
</li>
<li class="nav-item ">
<a class="nav-link nav-external" href="https://numpy.org/neps">
NEPs
</a>
</li>
</ul>
</nav></div>
</div>
<div class="sidebar-header-items__end">
<div class="navbar-item">
<button class="btn btn-sm pst-navbar-icon search-button search-button__button pst-js-only" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass fa-lg"></i>
</button></div>
<div class="navbar-item">
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" aria-label="Color mode" data-bs-title="Color mode" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light" title="Light"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark" title="Dark"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto" title="System Settings"></i>
</button></div>
<div class="navbar-item">
<div class="version-switcher__container dropdown pst-js-only">
<button id="pst-version-switcher-button-3"
type="button"
class="version-switcher__button btn btn-sm dropdown-toggle"
data-bs-toggle="dropdown"
aria-haspopup="listbox"
aria-controls="pst-version-switcher-list-3"
aria-label="Version switcher list"
>
Choose version <!-- this text may get changed later by javascript -->
<span class="caret"></span>
</button>
<div id="pst-version-switcher-list-3"
class="version-switcher__menu dropdown-menu list-group-flush py-0"
role="listbox" aria-labelledby="pst-version-switcher-button-3">
<!-- dropdown will be populated by javascript on page load -->
</div>
</div></div>
<div class="navbar-item"><ul class="navbar-icon-links"
aria-label="Icon Links">
<li class="nav-item">
<a href="https://github.com/numpy/numpy" title="GitHub" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-square-github fa-lg" aria-hidden="true"></i>
<span class="sr-only">GitHub</span></a>
</li>
</ul></div>
</div>
</div>
<div class="sidebar-primary-items__start sidebar-primary__section">
<div class="sidebar-primary-item">
<nav class="bd-docs-nav bd-links"
aria-label="Section Navigation">
<p class="bd-links__title" role="heading" aria-level="1">Section Navigation</p>
<div class="bd-toc-item navbar-nav"><ul class="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="../module_structure.html">NumPy’s module structure</a></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="../arrays.html">Array objects</a></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="../ufuncs.html">Universal functions (<code class="xref py py-class docutils literal notranslate"><span class="pre">ufunc</span></code>)</a></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="../routines.html">Routines and objects by topic</a></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="../typing.html">Typing (<code class="xref py py-mod docutils literal notranslate"><span class="pre">numpy.typing</span></code>)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../distutils.html">Packaging</a></li>
</ul>
<ul class="current nav bd-sidenav">
<li class="toctree-l1 current active has-children"><a class="reference internal" href="index.html">NumPy C-API</a><details open="open"><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="types-and-structures.html">Python types and C-structures</a></li>
<li class="toctree-l2"><a class="reference internal" href="config.html">System configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="dtype.html">Data type API</a></li>
<li class="toctree-l2 current active"><a class="current reference internal" href="#">Array API</a></li>
<li class="toctree-l2"><a class="reference internal" href="iterator.html">Array iterator API</a></li>
<li class="toctree-l2"><a class="reference internal" href="ufunc.html">ufunc API</a></li>
<li class="toctree-l2"><a class="reference internal" href="generalized-ufuncs.html">Generalized universal function API</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html">NpyString API</a></li>
<li class="toctree-l2"><a class="reference internal" href="coremath.html">NumPy core math library</a></li>
<li class="toctree-l2"><a class="reference internal" href="datetimes.html">Datetime API</a></li>
<li class="toctree-l2"><a class="reference internal" href="deprecations.html">C API deprecations</a></li>
<li class="toctree-l2"><a class="reference internal" href="data_memory.html">Memory management in NumPy</a></li>
</ul>
</details></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="../array_api.html">Array API standard compatibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="../simd/index.html">CPU/SIMD optimizations</a></li>
<li class="toctree-l1"><a class="reference internal" href="../thread_safety.html">Thread Safety</a></li>
<li class="toctree-l1"><a class="reference internal" href="../global_state.html">Global Configuration Options</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security.html">NumPy security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../distutils_status_migration.html">Status of <code class="docutils literal notranslate"><span class="pre">numpy.distutils</span></code> and migration advice</a></li>
<li class="toctree-l1"><a class="reference internal" href="../distutils_guide.html"><code class="docutils literal notranslate"><span class="pre">numpy.distutils</span></code> user guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../swig.html">NumPy and SWIG</a></li>
</ul>
</div>
</nav></div>
</div>
<div class="sidebar-primary-items__end sidebar-primary__section">
<div class="sidebar-primary-item">
<div id="ethical-ad-placement"
class="flat"
data-ea-publisher="readthedocs"
data-ea-type="readthedocs-sidebar"
data-ea-manual="true">
</div></div>
</div>
</div>
<main id="main-content" class="bd-main" role="main">
<div class="bd-content">
<div class="bd-article-container">
<div class="bd-header-article d-print-none">
<div class="header-article-items header-article__inner">
<div class="header-article-items__start">
<div class="header-article-item">
<nav aria-label="Breadcrumb" class="d-print-none">
<ul class="bd-breadcrumbs">
<li class="breadcrumb-item breadcrumb-home">
<a href="../../index.html" class="nav-link" aria-label="Home">
<i class="fa-solid fa-home"></i>
</a>
</li>
<li class="breadcrumb-item"><a href="../index.html" class="nav-link">NumPy reference</a></li>
<li class="breadcrumb-item"><a href="index.html" class="nav-link">NumPy C-API</a></li>
<li class="breadcrumb-item active" aria-current="page"><span class="ellipsis">Array API</span></li>
</ul>
</nav>
</div>
</div>
</div>
</div>
<div id="searchbox"></div>
<article class="bd-article">
<section id="array-api">
<h1>Array API<a class="headerlink" href="#array-api" title="Link to this heading">#</a></h1>
<div class="line-block">
<div class="line">The test of a first-rate intelligence is the ability to hold two</div>
<div class="line">opposed ideas in the mind at the same time, and still retain the</div>
<div class="line">ability to function.</div>
<div class="line">— <em>F. Scott Fitzgerald</em></div>
</div>
<div class="line-block">
<div class="line">For a successful technology, reality must take precedence over public</div>
<div class="line">relations, for Nature cannot be fooled.</div>
<div class="line">— <em>Richard P. Feynman</em></div>
</div>
<section id="array-structure-and-data-access">
<span id="index-0"></span><h2>Array structure and data access<a class="headerlink" href="#array-structure-and-data-access" title="Link to this heading">#</a></h2>
<p>These macros access the <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArrayObject</span></code></a> structure members and are
defined in <code class="docutils literal notranslate"><span class="pre">ndarraytypes.h</span></code>. The input argument, <em>arr</em>, can be any
<span class="c-expr sig sig-inline c"><a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n">PyObject</span></a><span class="p">*</span></span> that is directly interpretable as a
<span class="c-expr sig sig-inline c"><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n">PyArrayObject</span></a><span class="p">*</span></span> (any instance of the <a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_Type</span></code></a>
and its sub-types).</p>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_NDIM">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_NDIM</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_NDIM" title="Link to this definition">#</a><br /></dt>
<dd><p>The number of dimensions in the array.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_FLAGS">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_FLAGS</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FLAGS" title="Link to this definition">#</a><br /></dt>
<dd><p>Returns an integer representing the <a class="reference internal" href="#array-flags"><span class="std std-ref">array-flags</span></a>.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_TYPE">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_TYPE</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_TYPE" title="Link to this definition">#</a><br /></dt>
<dd><p>Return the (builtin) typenumber for the elements of this array.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_Pack">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_Pack</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><span class="n"><span class="pre">PyArray_Descr</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">descr</span></span>, <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">item</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">value</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Pack" title="Link to this definition">#</a><br /></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 2.0.</span></p>
</div>
<p>Sets the memory location <code class="docutils literal notranslate"><span class="pre">item</span></code> of dtype <code class="docutils literal notranslate"><span class="pre">descr</span></code> to <code class="docutils literal notranslate"><span class="pre">value</span></code>.</p>
<p>The function is equivalent to setting a single array element with a Python
assignment. Returns 0 on success and -1 with an error set on failure.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If the <code class="docutils literal notranslate"><span class="pre">descr</span></code> has the <a class="reference internal" href="types-and-structures.html#c.NPY_NEEDS_INIT" title="NPY_NEEDS_INIT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_NEEDS_INIT</span></code></a> flag set, the
data must be valid or the memory zeroed.</p>
</div>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_SETITEM">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_SETITEM</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span>, <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">itemptr</span></span>, <a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SETITEM" title="Link to this definition">#</a><br /></dt>
<dd><p>Convert obj and place it in the ndarray, <em>arr</em>, at the place
pointed to by itemptr. Return -1 if an error occurs or 0 on
success.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>In general, prefer the use of <a class="reference internal" href="#c.PyArray_Pack" title="PyArray_Pack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Pack</span></code></a> when
handling arbitrary Python objects. Setitem is for example not able
to handle arbitrary casts between different dtypes.</p>
</div>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_ENABLEFLAGS">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_ENABLEFLAGS</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ENABLEFLAGS" title="Link to this definition">#</a><br /></dt>
<dd><p>Enables the specified array flags. This function does no validation,
and assumes that you know what you’re doing.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_CLEARFLAGS">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_CLEARFLAGS</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CLEARFLAGS" title="Link to this definition">#</a><br /></dt>
<dd><p>Clears the specified array flags. This function does no validation,
and assumes that you know what you’re doing.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_DATA">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_DATA</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DATA" title="Link to this definition">#</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_BYTES">
<span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_BYTES</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_BYTES" title="Link to this definition">#</a><br /></dt>
<dd><p>These two macros are similar and obtain the pointer to the
data-buffer for the array. The first macro can (and should be)
assigned to a particular pointer where the second is for generic
processing. If you have not guaranteed a contiguous and/or aligned
array then be sure you understand how to access the data in the
array to avoid memory and/or alignment problems.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_DIMS">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_DIMS</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DIMS" title="Link to this definition">#</a><br /></dt>
<dd><p>Returns a pointer to the dimensions/shape of the array. The
number of elements matches the number of dimensions
of the array. Can return <code class="docutils literal notranslate"><span class="pre">NULL</span></code> for 0-dimensional arrays.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_SHAPE">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_SHAPE</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SHAPE" title="Link to this definition">#</a><br /></dt>
<dd><p>A synonym for <a class="reference internal" href="#c.PyArray_DIMS" title="PyArray_DIMS"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DIMS</span></code></a>, named to be consistent with the
<a class="reference internal" href="../generated/numpy.ndarray.shape.html#numpy.ndarray.shape" title="numpy.ndarray.shape"><code class="xref py py-obj docutils literal notranslate"><span class="pre">shape</span></code></a> usage within Python.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_STRIDES">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_STRIDES</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_STRIDES" title="Link to this definition">#</a><br /></dt>
<dd><p>Returns a pointer to the strides of the array. The
number of elements matches the number of dimensions
of the array.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_DIM">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_DIM</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">n</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DIM" title="Link to this definition">#</a><br /></dt>
<dd><p>Return the shape in the <em>n</em> <span class="math notranslate nohighlight">\(^{\textrm{th}}\)</span> dimension.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_STRIDE">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_STRIDE</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">n</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_STRIDE" title="Link to this definition">#</a><br /></dt>
<dd><p>Return the stride in the <em>n</em> <span class="math notranslate nohighlight">\(^{\textrm{th}}\)</span> dimension.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_ITEMSIZE">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_ITEMSIZE</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ITEMSIZE" title="Link to this definition">#</a><br /></dt>
<dd><p>Return the itemsize for the elements of this array.</p>
<p>Note that, in the old API that was deprecated in version 1.7, this function
had the return type <code class="docutils literal notranslate"><span class="pre">int</span></code>.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_SIZE">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_SIZE</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SIZE" title="Link to this definition">#</a><br /></dt>
<dd><p>Returns the total size (in number of elements) of the array.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_Size">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_Size</span></span></span><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Size" title="Link to this definition">#</a><br /></dt>
<dd><p>Returns 0 if <em>obj</em> is not a sub-class of ndarray. Otherwise,
returns the total number of elements in the array. Safer version
of <a class="reference internal" href="#c.PyArray_SIZE" title="PyArray_SIZE"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_SIZE</span></code></a> (<em>obj</em>).</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_NBYTES">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_NBYTES</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_NBYTES" title="Link to this definition">#</a><br /></dt>
<dd><p>Returns the total number of bytes consumed by the array.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_BASE">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_BASE</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_BASE" title="Link to this definition">#</a><br /></dt>
<dd><p>This returns the base object of the array. In most cases, this
means the object which owns the memory the array is pointing at.</p>
<p>If you are constructing an array using the C API, and specifying
your own memory, you should use the function <a class="reference internal" href="#c.PyArray_SetBaseObject" title="PyArray_SetBaseObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_SetBaseObject</span></code></a>
to set the base to an object which owns the memory.</p>
<p>If the <a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a> flag is set, it has a different
meaning, namely base is the array into which the current array will
be copied upon copy resolution. This overloading of the base property
for two functions is likely to change in a future version of NumPy.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_DESCR">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><span class="n"><span class="pre">PyArray_Descr</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_DESCR</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DESCR" title="Link to this definition">#</a><br /></dt>
<dd><p>Returns a borrowed reference to the dtype property of the array.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_DTYPE">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><span class="n"><span class="pre">PyArray_Descr</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_DTYPE</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DTYPE" title="Link to this definition">#</a><br /></dt>
<dd><p>A synonym for PyArray_DESCR, named to be consistent with the
‘dtype’ usage within Python.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_GETITEM">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_GETITEM</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span>, <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">itemptr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GETITEM" title="Link to this definition">#</a><br /></dt>
<dd><p>Get a Python object of a builtin type from the ndarray, <em>arr</em>,
at the location pointed to by itemptr. Return <code class="docutils literal notranslate"><span class="pre">NULL</span></code> on failure.</p>
<p><a class="reference internal" href="../generated/numpy.ndarray.item.html#numpy.ndarray.item" title="numpy.ndarray.item"><code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.ndarray.item</span></code></a> is identical to PyArray_GETITEM.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_FinalizeFunc">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_FinalizeFunc</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span>, <a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FinalizeFunc" title="Link to this definition">#</a><br /></dt>
<dd><p>The function pointed to by the <a class="reference external" href="https://docs.python.org/3/c-api/capsule.html#c.PyCapsule" title="(in Python v3.13)"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyCapsule</span></code></a>
<a class="reference internal" href="../arrays.classes.html#numpy.class.__array_finalize__" title="numpy.class.__array_finalize__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array_finalize__</span></code></a>.
The first argument is the newly created sub-type. The second argument
(if not NULL) is the “parent” array (if the array was created using
slicing or some other operation where a clearly-distinguishable parent
is present). This routine can do anything it wants to. It should
return a -1 on error and 0 otherwise.</p>
</dd></dl>
<section id="data-access">
<h3>Data access<a class="headerlink" href="#data-access" title="Link to this heading">#</a></h3>
<p>These functions and macros provide easy access to elements of the
ndarray from C. These work for all arrays. You may need to take care
when accessing the data in the array, however, if it is not in machine
byte-order, misaligned, or not writeable. In other words, be sure to
respect the state of the flags unless you know what you are doing, or
have previously guaranteed an array that is writeable, aligned, and in
machine byte-order using <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a>. If you wish to handle all
types of arrays, the copyswap function for each type is useful for
handling misbehaved arrays. Some platforms (e.g. Solaris) do not like
misaligned data and will crash if you de-reference a misaligned
pointer. Other platforms (e.g. x86 Linux) will just work more slowly
with misaligned data.</p>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_GetPtr">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_GetPtr</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">aobj</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ind</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GetPtr" title="Link to this definition">#</a><br /></dt>
<dd><p>Return a pointer to the data of the ndarray, <em>aobj</em>, at the
N-dimensional index given by the c-array, <em>ind</em>, (which must be
at least <em>aobj</em> ->nd in size). You may want to typecast the
returned pointer to the data type of the ndarray.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_GETPTR1">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_GETPTR1</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="n"><span class="pre">i</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GETPTR1" title="Link to this definition">#</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_GETPTR2">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_GETPTR2</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="n"><span class="pre">i</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="n"><span class="pre">j</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GETPTR2" title="Link to this definition">#</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_GETPTR3">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_GETPTR3</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="n"><span class="pre">i</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="n"><span class="pre">j</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="n"><span class="pre">k</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GETPTR3" title="Link to this definition">#</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_GETPTR4">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_GETPTR4</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="n"><span class="pre">i</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="n"><span class="pre">j</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="n"><span class="pre">k</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="n"><span class="pre">l</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GETPTR4" title="Link to this definition">#</a><br /></dt>
<dd><p>Quick, inline access to the element at the given coordinates in
the ndarray, <em>obj</em>, which must have respectively 1, 2, 3, or 4
dimensions (this is not checked). The corresponding <em>i</em>, <em>j</em>,
<em>k</em>, and <em>l</em> coordinates can be any integer but will be
interpreted as <code class="docutils literal notranslate"><span class="pre">npy_intp</span></code>. You may want to typecast the
returned pointer to the data type of the ndarray.</p>
</dd></dl>
</section>
</section>
<section id="creating-arrays">
<h2>Creating arrays<a class="headerlink" href="#creating-arrays" title="Link to this heading">#</a></h2>
<section id="from-scratch">
<h3>From scratch<a class="headerlink" href="#from-scratch" title="Link to this heading">#</a></h3>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_NewFromDescr">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_NewFromDescr</span></span></span><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/3/c-api/type.html#c.PyTypeObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyTypeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">subtype</span></span>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><span class="n"><span class="pre">PyArray_Descr</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">descr</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">nd</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dims</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">strides</span></span>, <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">data</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">flags</span></span>, <a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_NewFromDescr" title="Link to this definition">#</a><br /></dt>
<dd><p>This function steals a reference to <em>descr</em>. The easiest way to get one
is using <a class="reference internal" href="#c.PyArray_DescrFromType" title="PyArray_DescrFromType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DescrFromType</span></code></a>.</p>
<p>This is the main array creation function. Most new arrays are
created with this flexible function.</p>
<p>The returned object is an object of Python-type <em>subtype</em>, which
must be a subtype of <a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_Type</span></code></a>. The array has <em>nd</em>
dimensions, described by <em>dims</em>. The data-type descriptor of the
new array is <em>descr</em>.</p>
<p>If <em>subtype</em> is of an array subclass instead of the base
<a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">&PyArray_Type</span></code></a>, then <em>obj</em> is the object to pass to
the <a class="reference internal" href="../arrays.classes.html#numpy.class.__array_finalize__" title="numpy.class.__array_finalize__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array_finalize__</span></code></a> method of the subclass.</p>
<p>If <em>data</em> is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, then new unitinialized memory will be allocated and
<em>flags</em> can be non-zero to indicate a Fortran-style contiguous array. Use
<a class="reference internal" href="#c.PyArray_FILLWBYTE" title="PyArray_FILLWBYTE"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FILLWBYTE</span></code></a> to initialize the memory.</p>
<p>If <em>data</em> is not <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, then it is assumed to point to the memory
to be used for the array and the <em>flags</em> argument is used as the
new flags for the array (except the state of <a class="reference internal" href="#c.NPY_ARRAY_OWNDATA" title="NPY_ARRAY_OWNDATA"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_OWNDATA</span></code></a>,
<a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a> flag of the new array will be reset).</p>
<p>In addition, if <em>data</em> is non-NULL, then <em>strides</em> can
also be provided. If <em>strides</em> is <code class="docutils literal notranslate"><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 notranslate"><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 notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> is nonzero non-NULL <em>data</em>). Any
provided <em>dims</em> and <em>strides</em> are copied into newly allocated
dimension and strides arrays for the new array object.</p>
<p><a class="reference internal" href="#c.PyArray_CheckStrides" title="PyArray_CheckStrides"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_CheckStrides</span></code></a> can help verify non- <code class="docutils literal notranslate"><span class="pre">NULL</span></code> stride
information.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">data</span></code> is provided, it must stay alive for the life of the array. One
way to manage this is through <a class="reference internal" href="#c.PyArray_SetBaseObject" title="PyArray_SetBaseObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_SetBaseObject</span></code></a></p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_NewLikeArray">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_NewLikeArray</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">prototype</span></span>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER"><span class="n"><span class="pre">NPY_ORDER</span></span></a><span class="w"> </span><span class="n"><span class="pre">order</span></span>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><span class="n"><span class="pre">PyArray_Descr</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">descr</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">subok</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_NewLikeArray" title="Link to this definition">#</a><br /></dt>
<dd><p>This function steals a reference to <em>descr</em> if it is not NULL.
This array creation routine allows for the convenient creation of
a new array matching an existing array’s shapes and memory layout,
possibly changing the layout and/or data type.</p>
<p>When <em>order</em> is <a class="reference internal" href="#c.NPY_ORDER.NPY_ANYORDER" title="NPY_ANYORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ANYORDER</span></code></a>, the result order is
<a class="reference internal" href="#c.NPY_ORDER.NPY_FORTRANORDER" title="NPY_FORTRANORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FORTRANORDER</span></code></a> if <em>prototype</em> is a fortran array,
<a class="reference internal" href="#c.NPY_ORDER.NPY_CORDER" title="NPY_CORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_CORDER</span></code></a> otherwise. When <em>order</em> is
<a class="reference internal" href="#c.NPY_ORDER.NPY_KEEPORDER" title="NPY_KEEPORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_KEEPORDER</span></code></a>, the result order matches that of <em>prototype</em>, even
when the axes of <em>prototype</em> aren’t in C or Fortran order.</p>
<p>If <em>descr</em> is NULL, the data type of <em>prototype</em> is used.</p>
<p>If <em>subok</em> is 1, the newly created array will use the sub-type of
<em>prototype</em> to create the new array, otherwise it will create a
base-class array.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_New">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_New</span></span></span><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/3/c-api/type.html#c.PyTypeObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyTypeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">subtype</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">nd</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dims</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">type_num</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">strides</span></span>, <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">data</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">itemsize</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">flags</span></span>, <a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_New" title="Link to this definition">#</a><br /></dt>
<dd><p>This is similar to <a class="reference internal" href="#c.PyArray_NewFromDescr" title="PyArray_NewFromDescr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_NewFromDescr</span></code></a> (…) except you
specify the data-type descriptor with <em>type_num</em> and <em>itemsize</em>,
where <em>type_num</em> corresponds to a builtin (or user-defined)
type. If the type always has the same number of bytes, then
itemsize is ignored. Otherwise, itemsize specifies the particular
size of this array.</p>
</dd></dl>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>If data is passed to <a class="reference internal" href="#c.PyArray_NewFromDescr" title="PyArray_NewFromDescr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_NewFromDescr</span></code></a> or <a class="reference internal" href="#c.PyArray_New" title="PyArray_New"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_New</span></code></a>,
this memory must not be deallocated until the new array is
deleted. If this data came from another Python object, this can
be accomplished using <a class="reference external" href="https://docs.python.org/3/c-api/refcounting.html#c.Py_INCREF" title="(in Python v3.13)"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_INCREF</span></code></a> on that object and setting the
base member of the new array to point to that object. If strides
are passed in they must be consistent with the dimensions, the
itemsize, and the data of the array.</p>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_SimpleNew">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_SimpleNew</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">nd</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dims</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">typenum</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SimpleNew" title="Link to this definition">#</a><br /></dt>
<dd><p>Create a new uninitialized array of type, <em>typenum</em>, whose size in
each of <em>nd</em> dimensions is given by the integer array, <em>dims</em>.The memory
for the array is uninitialized (unless typenum is <a class="reference internal" href="dtype.html#c.NPY_TYPES.NPY_OBJECT" title="NPY_OBJECT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_OBJECT</span></code></a>
in which case each element in the array is set to NULL). The
<em>typenum</em> argument allows specification of any of the builtin
data-types such as <a class="reference internal" href="dtype.html#c.NPY_TYPES.NPY_FLOAT" title="NPY_FLOAT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FLOAT</span></code></a> or <a class="reference internal" href="dtype.html#c.NPY_TYPES.NPY_LONG" title="NPY_LONG"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_LONG</span></code></a>. The
memory for the array can be set to zero if desired using
<a class="reference internal" href="#c.PyArray_FILLWBYTE" title="PyArray_FILLWBYTE"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FILLWBYTE</span></code></a> (return_object, 0).This function cannot be
used to create a flexible-type array (no itemsize given).</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_SimpleNewFromData">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_SimpleNewFromData</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">nd</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dims</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">typenum</span></span>, <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">data</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SimpleNewFromData" title="Link to this definition">#</a><br /></dt>
<dd><p>Create an array wrapper around <em>data</em> pointed to by the given
pointer. The array flags will have a default that the data area is
well-behaved and C-style contiguous. The shape of the array is
given by the <em>dims</em> c-array of length <em>nd</em>. The data-type of the
array is indicated by <em>typenum</em>. If data comes from another
reference-counted Python object, the reference count on this object
should be increased after the pointer is passed in, and the base member
of the returned ndarray should point to the Python object that owns
the data. This will ensure that the provided memory is not
freed while the returned array is in existence.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_SimpleNewFromDescr">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_SimpleNewFromDescr</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">nd</span></span>, <a class="reference internal" href="dtype.html#c.npy_int" title="npy_int"><span class="n"><span class="pre">npy_int</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dims</span></span>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><span class="n"><span class="pre">PyArray_Descr</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">descr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SimpleNewFromDescr" title="Link to this definition">#</a><br /></dt>
<dd><p>This function steals a reference to <em>descr</em>.</p>
<p>Create a new array with the provided data-type descriptor, <em>descr</em>,
of the shape determined by <em>nd</em> and <em>dims</em>.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_FILLWBYTE">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_FILLWBYTE</span></span></span><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">val</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FILLWBYTE" title="Link to this definition">#</a><br /></dt>
<dd><p>Fill the array pointed to by <em>obj</em> —which must be a (subclass
of) ndarray—with the contents of <em>val</em> (evaluated as a byte).
This macro calls memset, so obj must be contiguous.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_Zeros">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_Zeros</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">nd</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dims</span></span>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><span class="n"><span class="pre">PyArray_Descr</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dtype</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">fortran</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Zeros" title="Link to this definition">#</a><br /></dt>
<dd><p>Construct a new <em>nd</em> -dimensional array with shape given by <em>dims</em>
and data type given by <em>dtype</em>. If <em>fortran</em> is non-zero, then a
Fortran-order array is created, otherwise a C-order array is
created. Fill the memory with zeros (or the 0 object if <em>dtype</em>
corresponds to <a class="reference internal" href="dtype.html#c.NPY_TYPES.NPY_OBJECT" title="NPY_OBJECT"><code class="xref c c-type docutils literal notranslate"><span class="pre">NPY_OBJECT</span></code></a> ).</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_ZEROS">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_ZEROS</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">nd</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dims</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">type_num</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">fortran</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ZEROS" title="Link to this definition">#</a><br /></dt>
<dd><p>Macro form of <a class="reference internal" href="#c.PyArray_Zeros" title="PyArray_Zeros"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Zeros</span></code></a> which takes a type-number instead
of a data-type object.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_Empty">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_Empty</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">nd</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dims</span></span>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><span class="n"><span class="pre">PyArray_Descr</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dtype</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">fortran</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Empty" title="Link to this definition">#</a><br /></dt>
<dd><p>Construct a new <em>nd</em> -dimensional array with shape given by <em>dims</em>
and data type given by <em>dtype</em>. If <em>fortran</em> is non-zero, then a
Fortran-order array is created, otherwise a C-order array is
created. The array is uninitialized unless the data type
corresponds to <a class="reference internal" href="dtype.html#c.NPY_TYPES.NPY_OBJECT" title="NPY_OBJECT"><code class="xref c c-type docutils literal notranslate"><span class="pre">NPY_OBJECT</span></code></a> in which case the array is
filled with <a class="reference external" href="https://docs.python.org/3/c-api/none.html#c.Py_None" title="(in Python v3.13)"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_None</span></code></a>.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_EMPTY">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_EMPTY</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">nd</span></span>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><span class="n"><span class="pre">npy_intp</span></span></a><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dims</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">typenum</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">fortran</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_EMPTY" title="Link to this definition">#</a><br /></dt>
<dd><p>Macro form of <a class="reference internal" href="#c.PyArray_Empty" title="PyArray_Empty"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Empty</span></code></a> which takes a type-number,
<em>typenum</em>, instead of a data-type object.</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_Arange">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_Arange</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">double</span></span><span class="w"> </span><span class="n"><span class="pre">start</span></span>, <span class="kt"><span class="pre">double</span></span><span class="w"> </span><span class="n"><span class="pre">stop</span></span>, <span class="kt"><span class="pre">double</span></span><span class="w"> </span><span class="n"><span class="pre">step</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">typenum</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Arange" title="Link to this definition">#</a><br /></dt>
<dd><p>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>
. Equivalent to <strong>arange</strong> (<em>start</em>, <em>stop</em>, <em>step</em>, dtype).</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_ArangeObj">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_ArangeObj</span></span></span><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">start</span></span>, <a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">stop</span></span>, <a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">step</span></span>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><span class="n"><span class="pre">PyArray_Descr</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">descr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ArangeObj" title="Link to this definition">#</a><br /></dt>
<dd><p>Construct a new 1-dimensional array of data-type determined by
<code class="docutils literal notranslate"><span class="pre">descr</span></code>, that ranges from <code class="docutils literal notranslate"><span class="pre">start</span></code> to <code class="docutils literal notranslate"><span class="pre">stop</span></code> (exclusive) in
increments of <code class="docutils literal notranslate"><span class="pre">step</span></code>. Equivalent to arange( <code class="docutils literal notranslate"><span class="pre">start</span></code>,
<code class="docutils literal notranslate"><span class="pre">stop</span></code>, <code class="docutils literal notranslate"><span class="pre">step</span></code>, <code class="docutils literal notranslate"><span class="pre">typenum</span></code> ).</p>
</dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_SetBaseObject">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_SetBaseObject</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><span class="n"><span class="pre">PyArrayObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">arr</span></span>, <a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SetBaseObject" title="Link to this definition">#</a><br /></dt>
<dd><p>This function <strong>steals a reference</strong> to <code class="docutils literal notranslate"><span class="pre">obj</span></code> and sets it as the
base property of <code class="docutils literal notranslate"><span class="pre">arr</span></code>.</p>
<p>If you construct an array by passing in your own memory buffer as
a parameter, you need to set the array’s <em class="xref py py-obj">base</em> property to ensure
the lifetime of the memory buffer is appropriate.</p>
<p>The return value is 0 on success, -1 on failure.</p>
<p>If the object provided is an array, this function traverses the
chain of <em class="xref py py-obj">base</em> pointers so that each array points to the owner
of the memory directly. Once the base is set, it may not be changed
to another value.</p>
</dd></dl>
</section>
<section id="from-other-objects">
<h3>From other objects<a class="headerlink" href="#from-other-objects" title="Link to this heading">#</a></h3>
<dl class="c function">
<dt class="sig sig-object c" id="c.PyArray_FromAny">
<a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyArray_FromAny</span></span></span><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">op</span></span>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><span class="n"><span class="pre">PyArray_Descr</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dtype</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">min_depth</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">max_depth</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">requirements</span></span>, <a class="reference external" href="https://docs.python.org/3/c-api/structures.html#c.PyObject" title="(in Python v3.13)"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">context</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FromAny" title="Link to this definition">#</a><br /></dt>
<dd><p>This is the main function used to obtain an array from any nested
sequence, or object that exposes the array interface, <em>op</em>. 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. This
function <strong>steals a reference</strong> to the dtype argument, which needs
to be a <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArray_Descr</span></code></a> structure
indicating the desired data-type (including required
byteorder). The <em>dtype</em> argument may be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, indicating that any
data-type (and byteorder) is acceptable. Unless
<a class="reference internal" href="#c.NPY_ARRAY_FORCECAST" title="NPY_ARRAY_FORCECAST"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_FORCECAST</span></code></a> is present in <code class="docutils literal notranslate"><span class="pre">flags</span></code>,
this call will generate an error if the data
type cannot be safely obtained from the object. If you want to use
<code class="docutils literal notranslate"><span class="pre">NULL</span></code> for the <em>dtype</em> and ensure the array is not swapped then
use <a class="reference internal" href="#c.PyArray_CheckFromAny" title="PyArray_CheckFromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_CheckFromAny</span></code></a>. A value of 0 for either of the
depth parameters causes the parameter to be ignored. Any of the
following array flags can be added (<em>e.g.</em> using |) to get the
<em>requirements</em> argument. If your code can handle general (<em>e.g.</em>
strided, byte-swapped, or unaligned arrays) then <em>requirements</em>