-
Notifications
You must be signed in to change notification settings - Fork 97
/
index.html
1636 lines (1343 loc) · 193 KB
/
index.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="zh-cn"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>数组 · Julia中文文档</title><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-28835595-9', 'auto');
ga('send', 'pageview', {'page': location.pathname + location.search + location.hash});
</script><link rel="canonical" href="https://juliacn.github.io/JuliaZH.jl/latest/base/arrays/"/><link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.0/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.0/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.0/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL="../.."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../../assets/documenter.js"></script><script src="../../siteinfo.js"></script><script src="../../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/documenter-dark.css" data-theme-name="documenter-dark"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../../assets/themeswap.js"></script><link href="../../assets/julia-manual.css" rel="stylesheet" type="text/css"/></head><body><div id="documenter"><nav class="docs-sidebar"><a class="docs-logo" href="../../"><img src="../../assets/logo.png" alt="Julia中文文档 logo"/></a><div class="docs-package-name"><span class="docs-autofit">Julia中文文档</span></div><form class="docs-search" action="../../search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../../">主页</a></li><li><span class="tocitem">手册</span><ul><li><a class="tocitem" href="../../manual/getting-started/">入门</a></li><li><a class="tocitem" href="../../manual/variables/">变量</a></li><li><a class="tocitem" href="../../manual/integers-and-floating-point-numbers/">整数和浮点数</a></li><li><a class="tocitem" href="../../manual/mathematical-operations/">数学运算和初等函数</a></li><li><a class="tocitem" href="../../manual/complex-and-rational-numbers/">复数和有理数</a></li><li><a class="tocitem" href="../../manual/strings/">字符串</a></li><li><a class="tocitem" href="../../manual/functions/">函数</a></li><li><a class="tocitem" href="../../manual/control-flow/">流程控制</a></li><li><a class="tocitem" href="../../manual/variables-and-scoping/">变量作用域</a></li><li><a class="tocitem" href="../../manual/types/">类型</a></li><li><a class="tocitem" href="../../manual/methods/">方法</a></li><li><a class="tocitem" href="../../manual/constructors/">构造函数</a></li><li><a class="tocitem" href="../../manual/conversion-and-promotion/">类型转换和类型提升</a></li><li><a class="tocitem" href="../../manual/interfaces/">接口</a></li><li><a class="tocitem" href="../../manual/modules/">模块</a></li><li><a class="tocitem" href="../../manual/documentation/">文档</a></li><li><a class="tocitem" href="../../manual/metaprogramming/">元编程</a></li><li><a class="tocitem" href="../../manual/arrays/">多维数组</a></li><li><a class="tocitem" href="../../manual/missing/">缺失值</a></li><li><a class="tocitem" href="../../manual/networking-and-streams/">网络和流</a></li><li><a class="tocitem" href="../../manual/parallel-computing/">并行计算</a></li><li><a class="tocitem" href="../../manual/asynchronous-programming/">异步编程</a></li><li><a class="tocitem" href="../../manual/multi-threading/">多线程</a></li><li><a class="tocitem" href="../../manual/distributed-computing/">多进程和分布式计算</a></li><li><a class="tocitem" href="../../manual/running-external-programs/">运行外部程序</a></li><li><a class="tocitem" href="../../manual/calling-c-and-fortran-code/">调用 C 和 Fortran 代码</a></li><li><a class="tocitem" href="../../manual/handling-operating-system-variation/">处理操作系统差异</a></li><li><a class="tocitem" href="../../manual/environment-variables/">环境变量</a></li><li><a class="tocitem" href="../../manual/embedding/">嵌入 Julia</a></li><li><a class="tocitem" href="../../manual/code-loading/">代码加载</a></li><li><a class="tocitem" href="../../manual/profile/">性能分析</a></li><li><a class="tocitem" href="../../manual/stacktraces/">栈跟踪</a></li><li><a class="tocitem" href="../../manual/performance-tips/">性能建议</a></li><li><a class="tocitem" href="../../manual/workflow-tips/">工作流程建议</a></li><li><a class="tocitem" href="../../manual/style-guide/">代码风格指南</a></li><li><a class="tocitem" href="../../manual/faq/">常见问题</a></li><li><a class="tocitem" href="../../manual/noteworthy-differences/">与其他语言的显著差异</a></li><li><a class="tocitem" href="../../manual/unicode-input/">Unicode 输入表</a></li><li><a class="tocitem" href="../../manual/command-line-options/">命令行选项</a></li></ul></li><li><span class="tocitem">Base</span><ul><li><a class="tocitem" href="../base/">基本功能</a></li><li><a class="tocitem" href="../collections/">集合和数据结构</a></li><li><a class="tocitem" href="../math/">数学相关</a></li><li><a class="tocitem" href="../numbers/">Numbers</a></li><li><a class="tocitem" href="../strings/">字符串</a></li><li class="is-active"><a class="tocitem" href>数组</a><ul class="internal"><li><a class="tocitem" href="#构造函数与类型"><span>构造函数与类型</span></a></li><li><a class="tocitem" href="#基础函数"><span>基础函数</span></a></li><li><a class="tocitem" href="#广播与矢量化"><span>广播与矢量化</span></a></li><li><a class="tocitem" href="#索引与赋值"><span>索引与赋值</span></a></li><li><a class="tocitem" href="#Views-(SubArrays-以及其它-view-类型)"><span>Views (SubArrays 以及其它 view 类型)</span></a></li><li><a class="tocitem" href="#拼接与排列"><span>拼接与排列</span></a></li><li><a class="tocitem" href="#数组函数"><span>数组函数</span></a></li><li><a class="tocitem" href="#组合学"><span>组合学</span></a></li></ul></li><li><a class="tocitem" href="../parallel/">Tasks</a></li><li><a class="tocitem" href="../multi-threading/">Multi-Threading</a></li><li><a class="tocitem" href="../constants/">常量</a></li><li><a class="tocitem" href="../file/">文件系统</a></li><li><a class="tocitem" href="../io-network/">I/O 与网络</a></li><li><a class="tocitem" href="../punctuation/">运算符与记号</a></li><li><a class="tocitem" href="../sort/">排序及相关函数</a></li><li><a class="tocitem" href="../iterators/">迭代相关</a></li><li><a class="tocitem" href="../c/">C 接口</a></li><li><a class="tocitem" href="../libc/">C 标准库</a></li><li><a class="tocitem" href="../stacktraces/">堆栈跟踪</a></li><li><a class="tocitem" href="../simd-types/">SIMD 支持</a></li></ul></li><li><span class="tocitem">Standard Library</span><ul><li><a class="tocitem" href="../../stdlib/Artifacts/">Artifacts</a></li><li><a class="tocitem" href="../../stdlib/Base64/">Base64</a></li><li><a class="tocitem" href="../../stdlib/CRC32c/">CRC32c</a></li><li><a class="tocitem" href="../../stdlib/Dates/">日期</a></li><li><a class="tocitem" href="../../stdlib/DelimitedFiles/">分隔符文件</a></li><li><a class="tocitem" href="../../stdlib/Distributed/">Distributed Computing</a></li><li><a class="tocitem" href="../../stdlib/FileWatching/">文件相关事件</a></li><li><a class="tocitem" href="../../stdlib/Future/">Future</a></li><li><a class="tocitem" href="../../stdlib/InteractiveUtils/">Interactive Utilities</a></li><li><a class="tocitem" href="../../stdlib/LazyArtifacts/">Lazy Artifacts</a></li><li><a class="tocitem" href="../../stdlib/LibGit2/">LibGit2</a></li><li><a class="tocitem" href="../../stdlib/Libdl/">动态链接器</a></li><li><a class="tocitem" href="../../stdlib/LinearAlgebra/">Linear Algebra</a></li><li><a class="tocitem" href="../../stdlib/Logging/">日志记录</a></li><li><a class="tocitem" href="../../stdlib/Markdown/">Markdown</a></li><li><a class="tocitem" href="../../stdlib/Mmap/">内存映射 I/O</a></li><li><a class="tocitem" href="../../stdlib/Printf/">Printf</a></li><li><a class="tocitem" href="../../stdlib/Profile/">性能分析</a></li><li><a class="tocitem" href="../../stdlib/REPL/">Julia REPL</a></li><li><a class="tocitem" href="../../stdlib/Random/">随机数</a></li><li><a class="tocitem" href="../../stdlib/SHA/">SHA</a></li><li><a class="tocitem" href="../../stdlib/Serialization/">序列化</a></li><li><a class="tocitem" href="../../stdlib/SharedArrays/">共享数组</a></li><li><a class="tocitem" href="../../stdlib/Sockets/">套接字</a></li><li><a class="tocitem" href="../../stdlib/SparseArrays/">稀疏数组</a></li><li><a class="tocitem" href="../../stdlib/Statistics/">统计</a></li><li><a class="tocitem" href="../../stdlib/TOML/">TOML</a></li><li><a class="tocitem" href="../../stdlib/Test/">单元测试</a></li><li><a class="tocitem" href="../../stdlib/UUIDs/">UUIDs</a></li><li><a class="tocitem" href="../../stdlib/Unicode/">Unicode</a></li></ul></li><li><span class="tocitem">Developer Documentation</span><ul><li><a class="tocitem" href="../../devdocs/reflection/">反射 与 自我检查</a></li><li><input class="collapse-toggle" id="menuitem-5-2" type="checkbox"/><label class="tocitem" for="menuitem-5-2"><span class="docs-label">Documentation of Julia's Internals</span><i class="docs-chevron"></i></label><ul class="collapsed"><li><a class="tocitem" href="../../devdocs/init/">Julia 运行时的初始化</a></li><li><a class="tocitem" href="../../devdocs/ast/">Julia 的 AST</a></li><li><a class="tocitem" href="../../devdocs/types/">More about types</a></li><li><a class="tocitem" href="../../devdocs/object/">Memory layout of Julia Objects</a></li><li><a class="tocitem" href="../../devdocs/eval/">Julia 代码的 eval</a></li><li><a class="tocitem" href="../../devdocs/callconv/">Calling Conventions</a></li><li><a class="tocitem" href="../../devdocs/compiler/">本机代码生成过程的高级概述</a></li><li><a class="tocitem" href="../../devdocs/functions/">Julia 函数</a></li><li><a class="tocitem" href="../../devdocs/cartesian/">笛卡尔</a></li><li><a class="tocitem" href="../../devdocs/meta/">Talking to the compiler (the <code>:meta</code> mechanism)</a></li><li><a class="tocitem" href="../../devdocs/subarrays/">子数组</a></li><li><a class="tocitem" href="../../devdocs/isbitsunionarrays/">isbits Union Optimizations</a></li><li><a class="tocitem" href="../../devdocs/sysimg/">System Image Building</a></li><li><a class="tocitem" href="../../devdocs/llvm/">Working with LLVM</a></li><li><a class="tocitem" href="../../devdocs/stdio/">printf() and stdio in the Julia runtime</a></li><li><a class="tocitem" href="../../devdocs/boundscheck/">边界检查</a></li><li><a class="tocitem" href="../../devdocs/locks/">Proper maintenance and care of multi-threading locks</a></li><li><a class="tocitem" href="../../devdocs/offset-arrays/">Arrays with custom indices</a></li><li><a class="tocitem" href="../../devdocs/require/">Module loading</a></li><li><a class="tocitem" href="../../devdocs/inference/">类型推导</a></li><li><a class="tocitem" href="../../devdocs/ssair/">Julia SSA-form IR</a></li><li><a class="tocitem" href="../../devdocs/gc-sa/">Static analyzer annotations for GC correctness in C code</a></li></ul></li><li><input class="collapse-toggle" id="menuitem-5-3" type="checkbox"/><label class="tocitem" for="menuitem-5-3"><span class="docs-label">Developing/debugging Julia's C code</span><i class="docs-chevron"></i></label><ul class="collapsed"><li><a class="tocitem" href="../../devdocs/backtraces/">报告和分析崩溃(段错误)</a></li><li><a class="tocitem" href="../../devdocs/debuggingtips/">gdb 调试提示</a></li><li><a class="tocitem" href="../../devdocs/valgrind/">在Julia中使用Valgrind</a></li><li><a class="tocitem" href="../../devdocs/sanitizers/">Sanitizer support</a></li></ul></li></ul></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li><a class="is-disabled">Base</a></li><li class="is-active"><a href>数组</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>数组</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://www.transifex.com/juliacn/base-zh_cn/translate/#zh_CN/arraysmd" title=" 完善 Transifex 上的翻译"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch"> 完善 Transifex 上的翻译</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="设置"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="lib-arrays"><a class="docs-heading-anchor" href="#lib-arrays">数组</a><a id="lib-arrays-1"></a><a class="docs-heading-anchor-permalink" href="#lib-arrays" title="Permalink"></a></h1><h2 id="构造函数与类型"><a class="docs-heading-anchor" href="#构造函数与类型">构造函数与类型</a><a id="构造函数与类型-1"></a><a class="docs-heading-anchor-permalink" href="#构造函数与类型" title="Permalink"></a></h2><article class="docstring"><header><a class="docstring-binding" id="Core.AbstractArray" href="#Core.AbstractArray"><code>Core.AbstractArray</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">AbstractArray{T,N}</code></pre><p>Supertype for <code>N</code>-dimensional arrays (or array-like types) with elements of type <code>T</code>. <a href="#Core.Array"><code>Array</code></a> and other types are subtypes of this. See the manual section on the <a href="../../manual/interfaces/#man-interface-array"><code>AbstractArray</code> interface</a>.</p><p>See also: <a href="#Base.AbstractVector"><code>AbstractVector</code></a>, <a href="#Base.AbstractMatrix"><code>AbstractMatrix</code></a>, <a href="../collections/#Base.eltype"><code>eltype</code></a>, <a href="#Base.ndims"><code>ndims</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L5-L13">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.AbstractVector" href="#Base.AbstractVector"><code>Base.AbstractVector</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">AbstractVector{T}</code></pre><p>Supertype for one-dimensional arrays (or array-like types) with elements of type <code>T</code>. Alias for <a href="#Core.AbstractArray"><code>AbstractArray{T,1}</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L17-L22">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.AbstractMatrix" href="#Base.AbstractMatrix"><code>Base.AbstractMatrix</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">AbstractMatrix{T}</code></pre><p>Supertype for two-dimensional arrays (or array-like types) with elements of type <code>T</code>. Alias for <a href="#Core.AbstractArray"><code>AbstractArray{T,2}</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L25-L30">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.AbstractVecOrMat" href="#Base.AbstractVecOrMat"><code>Base.AbstractVecOrMat</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">AbstractVecOrMat{T}</code></pre><p>Union type of <a href="#Base.AbstractVector"><code>AbstractVector{T}</code></a> and <a href="#Base.AbstractMatrix"><code>AbstractMatrix{T}</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L33-L37">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Core.Array" href="#Core.Array"><code>Core.Array</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">Array{T,N} <: AbstractArray{T,N}</code></pre><p><code>N</code>-dimensional dense array with elements of type <code>T</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L45-L49">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Core.Array-Tuple{UndefInitializer, Any}" href="#Core.Array-Tuple{UndefInitializer, Any}"><code>Core.Array</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">Array{T}(undef, dims)
Array{T,N}(undef, dims)</code></pre><p>Construct an uninitialized <code>N</code>-dimensional <a href="#Core.Array"><code>Array</code></a> containing elements of type <code>T</code>. <code>N</code> can either be supplied explicitly, as in <code>Array{T,N}(undef, dims)</code>, or be determined by the length or number of <code>dims</code>. <code>dims</code> may be a tuple or a series of integer arguments corresponding to the lengths in each dimension. If the rank <code>N</code> is supplied explicitly, then it must match the length or number of <code>dims</code>. Here <a href="#Core.undef"><code>undef</code></a> is the <a href="#Core.UndefInitializer"><code>UndefInitializer</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = Array{Float64, 2}(undef, 2, 3) # N given explicitly
2×3 Matrix{Float64}:
6.90198e-310 6.90198e-310 6.90198e-310
6.90198e-310 6.90198e-310 0.0
julia> B = Array{Float64}(undef, 4) # N determined by the input
4-element Vector{Float64}:
2.360075077e-314
NaN
2.2671131793e-314
2.299821756e-314
julia> similar(B, 2, 4, 1) # use typeof(B), and the given size
2×4×1 Array{Float64, 3}:
[:, :, 1] =
2.26703e-314 2.26708e-314 0.0 2.80997e-314
0.0 2.26703e-314 2.26708e-314 0.0</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2222-L2254">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Core.Array-Tuple{Nothing, Any}" href="#Core.Array-Tuple{Nothing, Any}"><code>Core.Array</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">Array{T}(nothing, dims)
Array{T,N}(nothing, dims)</code></pre><p>Construct an <code>N</code>-dimensional <a href="#Core.Array"><code>Array</code></a> containing elements of type <code>T</code>, initialized with <a href="../constants/#Core.nothing"><code>nothing</code></a> entries. Element type <code>T</code> must be able to hold these values, i.e. <code>Nothing <: T</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Array{Union{Nothing, String}}(nothing, 2)
2-element Vector{Union{Nothing, String}}:
nothing
nothing
julia> Array{Union{Nothing, Int}}(nothing, 2, 3)
2×3 Matrix{Union{Nothing, Int64}}:
nothing nothing nothing
nothing nothing nothing</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2257-L2277">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Core.Array-Tuple{Missing, Any}" href="#Core.Array-Tuple{Missing, Any}"><code>Core.Array</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">Array{T}(missing, dims)
Array{T,N}(missing, dims)</code></pre><p>Construct an <code>N</code>-dimensional <a href="#Core.Array"><code>Array</code></a> containing elements of type <code>T</code>, initialized with <a href="../base/#Base.missing"><code>missing</code></a> entries. Element type <code>T</code> must be able to hold these values, i.e. <code>Missing <: T</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Array{Union{Missing, String}}(missing, 2)
2-element Vector{Union{Missing, String}}:
missing
missing
julia> Array{Union{Missing, Int}}(missing, 2, 3)
2×3 Matrix{Union{Missing, Int64}}:
missing missing missing
missing missing missing</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2281-L2301">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Core.UndefInitializer" href="#Core.UndefInitializer"><code>Core.UndefInitializer</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">UndefInitializer</code></pre><p>Singleton type used in array initialization, indicating the array-constructor-caller would like an uninitialized array. See also <a href="#Core.undef"><code>undef</code></a>, an alias for <code>UndefInitializer()</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Array{Float64, 1}(UndefInitializer(), 3)
3-element Array{Float64, 1}:
2.2752528595e-314
2.202942107e-314
2.275252907e-314</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2304-L2319">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Core.undef" href="#Core.undef"><code>Core.undef</code></a> — <span class="docstring-category">Constant</span></header><section><div><pre><code class="language-julia">undef</code></pre><p>Alias for <code>UndefInitializer()</code>, which constructs an instance of the singleton type <a href="#Core.UndefInitializer"><code>UndefInitializer</code></a>, used in array initialization to indicate the array-constructor-caller would like an uninitialized array.</p><p>See also: <a href="../base/#Base.missing"><code>missing</code></a>, <a href="#Base.similar"><code>similar</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Array{Float64, 1}(undef, 3)
3-element Vector{Float64}:
2.2752528595e-314
2.202942107e-314
2.275252907e-314</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2322-L2339">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Vector" href="#Base.Vector"><code>Base.Vector</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">Vector{T} <: AbstractVector{T}</code></pre><p>One-dimensional dense array with elements of type <code>T</code>, often used to represent a mathematical vector. Alias for <a href="#Core.Array"><code>Array{T,1}</code></a>.</p><p>See also <a href="#Base.empty"><code>empty</code></a>, <a href="#Base.similar"><code>similar</code></a> and <a href="../numbers/#Base.zero"><code>zero</code></a> for creating vectors.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L52-L59">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Vector-Tuple{UndefInitializer, Any}" href="#Base.Vector-Tuple{UndefInitializer, Any}"><code>Base.Vector</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">Vector{T}(undef, n)</code></pre><p>Construct an uninitialized <a href="#Base.Vector"><code>Vector{T}</code></a> of length <code>n</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Vector{Float64}(undef, 3)
3-element Array{Float64, 1}:
6.90966e-310
6.90966e-310
6.90966e-310</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2118-L2131">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Vector-Tuple{Nothing, Any}" href="#Base.Vector-Tuple{Nothing, Any}"><code>Base.Vector</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">Vector{T}(nothing, m)</code></pre><p>Construct a <a href="#Base.Vector"><code>Vector{T}</code></a> of length <code>m</code>, initialized with <a href="../constants/#Core.nothing"><code>nothing</code></a> entries. Element type <code>T</code> must be able to hold these values, i.e. <code>Nothing <: T</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Vector{Union{Nothing, String}}(nothing, 2)
2-element Vector{Union{Nothing, String}}:
nothing
nothing</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2134-L2148">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Vector-Tuple{Missing, Any}" href="#Base.Vector-Tuple{Missing, Any}"><code>Base.Vector</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">Vector{T}(missing, m)</code></pre><p>Construct a <a href="#Base.Vector"><code>Vector{T}</code></a> of length <code>m</code>, initialized with <a href="../base/#Base.missing"><code>missing</code></a> entries. Element type <code>T</code> must be able to hold these values, i.e. <code>Missing <: T</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Vector{Union{Missing, String}}(missing, 2)
2-element Vector{Union{Missing, String}}:
missing
missing</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2151-L2165">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Matrix" href="#Base.Matrix"><code>Base.Matrix</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">Matrix{T} <: AbstractMatrix{T}</code></pre><p>Two-dimensional dense array with elements of type <code>T</code>, often used to represent a mathematical matrix. Alias for <a href="#Core.Array"><code>Array{T,2}</code></a>.</p><p>See also <a href="#Base.fill"><code>fill</code></a>, <a href="#Base.zeros"><code>zeros</code></a>, <a href="#Core.undef"><code>undef</code></a> and <a href="#Base.similar"><code>similar</code></a> for creating matrices.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L62-L70">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Matrix-Tuple{UndefInitializer, Any, Any}" href="#Base.Matrix-Tuple{UndefInitializer, Any, Any}"><code>Base.Matrix</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">Matrix{T}(undef, m, n)</code></pre><p>Construct an uninitialized <a href="#Base.Matrix"><code>Matrix{T}</code></a> of size <code>m</code>×<code>n</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Matrix{Float64}(undef, 2, 3)
2×3 Array{Float64, 2}:
2.36365e-314 2.28473e-314 5.0e-324
2.26704e-314 2.26711e-314 NaN
julia> similar(ans, Int32, 2, 2)
2×2 Matrix{Int32}:
490537216 1277177453
1 1936748399</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2168-L2185">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Matrix-Tuple{Nothing, Any, Any}" href="#Base.Matrix-Tuple{Nothing, Any, Any}"><code>Base.Matrix</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">Matrix{T}(nothing, m, n)</code></pre><p>Construct a <a href="#Base.Matrix"><code>Matrix{T}</code></a> of size <code>m</code>×<code>n</code>, initialized with <a href="../constants/#Core.nothing"><code>nothing</code></a> entries. Element type <code>T</code> must be able to hold these values, i.e. <code>Nothing <: T</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Matrix{Union{Nothing, String}}(nothing, 2, 3)
2×3 Matrix{Union{Nothing, String}}:
nothing nothing nothing
nothing nothing nothing</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2188-L2202">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Matrix-Tuple{Missing, Any, Any}" href="#Base.Matrix-Tuple{Missing, Any, Any}"><code>Base.Matrix</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">Matrix{T}(missing, m, n)</code></pre><p>Construct a <a href="#Base.Matrix"><code>Matrix{T}</code></a> of size <code>m</code>×<code>n</code>, initialized with <a href="../base/#Base.missing"><code>missing</code></a> entries. Element type <code>T</code> must be able to hold these values, i.e. <code>Missing <: T</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Matrix{Union{Missing, String}}(missing, 2, 3)
2×3 Matrix{Union{Missing, String}}:
missing missing missing
missing missing missing</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2205-L2219">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.VecOrMat" href="#Base.VecOrMat"><code>Base.VecOrMat</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">VecOrMat{T}</code></pre><p>Union type of <a href="#Base.Vector"><code>Vector{T}</code></a> and <a href="#Base.Matrix"><code>Matrix{T}</code></a> which allows functions to accept either a Matrix or a Vector.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Vector{Float64} <: VecOrMat{Float64}
true
julia> Matrix{Float64} <: VecOrMat{Float64}
true
julia> Array{Float64, 3} <: VecOrMat{Float64}
false</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L73-L89">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Core.DenseArray" href="#Core.DenseArray"><code>Core.DenseArray</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">DenseArray{T, N} <: AbstractArray{T,N}</code></pre><p><code>N</code>-dimensional dense array with elements of type <code>T</code>. The elements of a dense array are stored contiguously in memory.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L92-L97">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.DenseVector" href="#Base.DenseVector"><code>Base.DenseVector</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">DenseVector{T}</code></pre><p>One-dimensional <a href="#Core.DenseArray"><code>DenseArray</code></a> with elements of type <code>T</code>. Alias for <code>DenseArray{T,1}</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L100-L104">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.DenseMatrix" href="#Base.DenseMatrix"><code>Base.DenseMatrix</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">DenseMatrix{T}</code></pre><p>Two-dimensional <a href="#Core.DenseArray"><code>DenseArray</code></a> with elements of type <code>T</code>. Alias for <code>DenseArray{T,2}</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L107-L111">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.DenseVecOrMat" href="#Base.DenseVecOrMat"><code>Base.DenseVecOrMat</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">DenseVecOrMat{T}</code></pre><p>Union type of <a href="#Base.DenseVector"><code>DenseVector{T}</code></a> and <a href="#Base.DenseMatrix"><code>DenseMatrix{T}</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L114-L118">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.StridedArray" href="#Base.StridedArray"><code>Base.StridedArray</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">StridedArray{T, N}</code></pre><p>A hard-coded <a href="../base/#Core.Union"><code>Union</code></a> of common array types that follow the <a href="../../manual/interfaces/#man-interface-strided-arrays">strided array interface</a>, with elements of type <code>T</code> and <code>N</code> dimensions.</p><p>If <code>A</code> is a <code>StridedArray</code>, then its elements are stored in memory with offsets, which may vary between dimensions but are constant within a dimension. For example, <code>A</code> could have stride 2 in dimension 1, and stride 3 in dimension 2. Incrementing <code>A</code> along dimension <code>d</code> jumps in memory by [<code>strides(A, d)</code>] slots. Strided arrays are particularly important and useful because they can sometimes be passed directly as pointers to foreign language libraries like BLAS.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2776-L2788">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.StridedVector" href="#Base.StridedVector"><code>Base.StridedVector</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">StridedVector{T}</code></pre><p>One dimensional <a href="#Base.StridedArray"><code>StridedArray</code></a> with elements of type <code>T</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2791-L2795">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.StridedMatrix" href="#Base.StridedMatrix"><code>Base.StridedMatrix</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">StridedMatrix{T}</code></pre><p>Two dimensional <a href="#Base.StridedArray"><code>StridedArray</code></a> with elements of type <code>T</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2798-L2802">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.StridedVecOrMat" href="#Base.StridedVecOrMat"><code>Base.StridedVecOrMat</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">StridedVecOrMat{T}</code></pre><p>Union type of <a href="#Base.StridedVector"><code>StridedVector</code></a> and <a href="#Base.StridedMatrix"><code>StridedMatrix</code></a> with elements of type <code>T</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/docs/basedocs.jl#L2805-L2809">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.getindex-Tuple{Type, Vararg{Any}}" href="#Base.getindex-Tuple{Type, Vararg{Any}}"><code>Base.getindex</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">getindex(type[, elements...])</code></pre><p>Construct a 1-d array of the specified type. This is usually called with the syntax <code>Type[]</code>. Element values can be specified using <code>Type[a,b,c,...]</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Int8[1, 2, 3]
3-element Vector{Int8}:
1
2
3
julia> getindex(Int8, 1, 2, 3)
3-element Vector{Int8}:
1
2
3</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L382-L402">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.zeros" href="#Base.zeros"><code>Base.zeros</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">zeros([T=Float64,] dims::Tuple)
zeros([T=Float64,] dims...)</code></pre><p>Create an <code>Array</code>, with element type <code>T</code>, of all zeros with size specified by <code>dims</code>. See also <a href="#Base.fill"><code>fill</code></a>, <a href="#Base.ones"><code>ones</code></a>, <a href="../numbers/#Base.zero"><code>zero</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> zeros(1)
1-element Vector{Float64}:
0.0
julia> zeros(Int8, 2, 3)
2×3 Matrix{Int8}:
0 0 0
0 0 0</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L539-L557">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.ones" href="#Base.ones"><code>Base.ones</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">ones([T=Float64,] dims::Tuple)
ones([T=Float64,] dims...)</code></pre><p>Create an <code>Array</code>, with element type <code>T</code>, of all ones with size specified by <code>dims</code>. See also <a href="#Base.fill"><code>fill</code></a>, <a href="#Base.zeros"><code>zeros</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> ones(1,2)
1×2 Matrix{Float64}:
1.0 1.0
julia> ones(ComplexF64, 2, 3)
2×3 Matrix{ComplexF64}:
1.0+0.0im 1.0+0.0im 1.0+0.0im
1.0+0.0im 1.0+0.0im 1.0+0.0im</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L560-L578">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.BitArray" href="#Base.BitArray"><code>Base.BitArray</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">BitArray{N} <: AbstractArray{Bool, N}</code></pre><p>Space-efficient <code>N</code>-dimensional boolean array, using just one bit for each boolean value.</p><p><code>BitArray</code>s pack up to 64 values into every 8 bytes, resulting in an 8x space efficiency over <code>Array{Bool, N}</code> and allowing some operations to work on 64 values at once.</p><p>By default, Julia returns <code>BitArrays</code> from <a href="../../manual/arrays/#Broadcasting">broadcasting</a> operations that generate boolean elements (including dotted-comparisons like <code>.==</code>) as well as from the functions <a href="#Base.trues"><code>trues</code></a> and <a href="#Base.falses"><code>falses</code></a>.</p><div class="admonition is-info"><header class="admonition-header">Note</header><div class="admonition-body"><p>Due to its packed storage format, concurrent access to the elements of a <code>BitArray</code> where at least one of them is a write is not thread safe.</p></div></div></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/bitarray.jl#L7-L23">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.BitArray-Tuple{UndefInitializer, Vararg{Integer}}" href="#Base.BitArray-Tuple{UndefInitializer, Vararg{Integer}}"><code>Base.BitArray</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">BitArray(undef, dims::Integer...)
BitArray{N}(undef, dims::NTuple{N,Int})</code></pre><p>Construct an undef <a href="#Base.BitArray"><code>BitArray</code></a> with the given dimensions. Behaves identically to the <a href="#Core.Array"><code>Array</code></a> constructor. See <a href="#Core.undef"><code>undef</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> BitArray(undef, 2, 2)
2×2 BitMatrix:
0 0
0 0
julia> BitArray(undef, (3, 1))
3×1 BitMatrix:
0
0
0</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/bitarray.jl#L48-L68">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.BitArray-Tuple{Any}" href="#Base.BitArray-Tuple{Any}"><code>Base.BitArray</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">BitArray(itr)</code></pre><p>Construct a <a href="#Base.BitArray"><code>BitArray</code></a> generated by the given iterable object. The shape is inferred from the <code>itr</code> object.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> BitArray([1 0; 0 1])
2×2 BitMatrix:
1 0
0 1
julia> BitArray(x+y == 3 for x = 1:2, y = 1:3)
2×3 BitMatrix:
0 1 0
1 0 0
julia> BitArray(x+y == 3 for x = 1:2 for y = 1:3)
6-element BitVector:
0
1
0
1
0
0</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/bitarray.jl#L549-L576">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.trues" href="#Base.trues"><code>Base.trues</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">trues(dims)</code></pre><p>Create a <code>BitArray</code> with all values set to <code>true</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> trues(2,3)
2×3 BitMatrix:
1 1 1
1 1 1</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/bitarray.jl#L408-L420">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.falses" href="#Base.falses"><code>Base.falses</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">falses(dims)</code></pre><p>Create a <code>BitArray</code> with all values set to <code>false</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> falses(2,3)
2×3 BitMatrix:
0 0 0
0 0 0</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/bitarray.jl#L390-L402">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.fill" href="#Base.fill"><code>Base.fill</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">fill(value, dims::Tuple)
fill(value, dims...)</code></pre><p>Create an array of size <code>dims</code> with every location set to <code>value</code>.</p><p>For example, <code>fill(1.0, (5,5))</code> returns a 5×5 array of floats, with <code>1.0</code> in every location of the array.</p><p>The dimension lengths <code>dims</code> may be specified as either a tuple or a sequence of arguments. An <code>N</code>-length tuple or <code>N</code> arguments following the <code>value</code> specify an <code>N</code>-dimensional array. Thus, a common idiom for creating a zero-dimensional array with its only location set to <code>x</code> is <code>fill(x)</code>.</p><p>Every location of the returned array is set to (and is thus <a href="../base/#Core.:==="><code>===</code></a> to) the <code>value</code> that was passed; this means that if the <code>value</code> is itself modified, all elements of the <code>fill</code>ed array will reflect that modification because they're <em>still</em> that very <code>value</code>. This is of no concern with <code>fill(1.0, (5,5))</code> as the <code>value</code> <code>1.0</code> is immutable and cannot itself be modified, but can be unexpected with mutable values like — most commonly — arrays. For example, <code>fill([], 3)</code> places <em>the very same</em> empty array in all three locations of the returned vector:</p><pre><code class="language-julia-repl">julia> v = fill([], 3)
3-element Vector{Vector{Any}}:
[]
[]
[]
julia> v[1] === v[2] === v[3]
true
julia> value = v[1]
Any[]
julia> push!(value, 867_5309)
1-element Vector{Any}:
8675309
julia> v
3-element Vector{Vector{Any}}:
[8675309]
[8675309]
[8675309]</code></pre><p>To create an array of many independent inner arrays, use a <a href="../../manual/arrays/#man-comprehensions">comprehension</a> instead. This creates a new and distinct array on each iteration of the loop:</p><pre><code class="language-julia-repl">julia> v2 = [[] for _ in 1:3]
3-element Vector{Vector{Any}}:
[]
[]
[]
julia> v2[1] === v2[2] === v2[3]
false
julia> push!(v2[1], 8675309)
1-element Vector{Any}:
8675309
julia> v2
3-element Vector{Vector{Any}}:
[8675309]
[]
[]</code></pre><p>See also: <a href="#Base.fill!"><code>fill!</code></a>, <a href="#Base.zeros"><code>zeros</code></a>, <a href="#Base.ones"><code>ones</code></a>, <a href="#Base.similar"><code>similar</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> fill(1.0, (2,3))
2×3 Matrix{Float64}:
1.0 1.0 1.0
1.0 1.0 1.0
julia> fill(42)
0-dimensional Array{Int64, 0}:
42
julia> A = fill(zeros(2), 2) # sets both elements to the same [0.0, 0.0] vector
2-element Vector{Vector{Float64}}:
[0.0, 0.0]
[0.0, 0.0]
julia> A[1][1] = 42; # modifies the filled value to be [42.0, 0.0]
julia> A # both A[1] and A[2] are the very same vector
2-element Vector{Vector{Float64}}:
[42.0, 0.0]
[42.0, 0.0]</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L436-L531">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.fill!" href="#Base.fill!"><code>Base.fill!</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">fill!(A, x)</code></pre><p>Fill array <code>A</code> with the value <code>x</code>. If <code>x</code> is an object reference, all elements will refer to the same object. <code>fill!(A, Foo())</code> will return <code>A</code> filled with the result of evaluating <code>Foo()</code> once.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = zeros(2,3)
2×3 Matrix{Float64}:
0.0 0.0 0.0
0.0 0.0 0.0
julia> fill!(A, 2.)
2×3 Matrix{Float64}:
2.0 2.0 2.0
2.0 2.0 2.0
julia> a = [1, 1, 1]; A = fill!(Vector{Vector{Int}}(undef, 3), a); a[1] = 2; A
3-element Vector{Vector{Int64}}:
[2, 1, 1]
[2, 1, 1]
[2, 1, 1]
julia> x = 0; f() = (global x += 1; x); fill!(Vector{Int}(undef, 3), f())
3-element Vector{Int64}:
1
1
1</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/multidimensional.jl#L1065-L1096">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.empty" href="#Base.empty"><code>Base.empty</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">empty(x::Tuple)</code></pre><p>Returns an empty tuple, <code>()</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/tuple.jl#L548-L552">source</a></section><section><div><pre><code class="language-none">empty(v::AbstractVector, [eltype])</code></pre><p>Create an empty vector similar to <code>v</code>, optionally changing the <code>eltype</code>.</p><p>See also: <a href="../collections/#Base.empty!"><code>empty!</code></a>, <a href="../collections/#Base.isempty"><code>isempty</code></a>, <a href="#Base.isassigned"><code>isassigned</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> empty([1.0, 2.0, 3.0])
Float64[]
julia> empty([1.0, 2.0, 3.0], String)
String[]</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L843-L859">source</a></section><section><div><pre><code class="language-none">empty(a::AbstractDict, [index_type=keytype(a)], [value_type=valtype(a)])</code></pre><p>Create an empty <code>AbstractDict</code> container which can accept indices of type <code>index_type</code> and values of type <code>value_type</code>. The second and third arguments are optional and default to the input's <code>keytype</code> and <code>valtype</code>, respectively. (If only one of the two types is specified, it is assumed to be the <code>value_type</code>, and the <code>index_type</code> we default to <code>keytype(a)</code>).</p><p>Custom <code>AbstractDict</code> subtypes may choose which specific dictionary type is best suited to return for the given index and value types, by specializing on the three-argument signature. The default is to return an empty <code>Dict</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractdict.jl#L176-L187">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.similar" href="#Base.similar"><code>Base.similar</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">similar(array, [element_type=eltype(array)], [dims=size(array)])</code></pre><p>Create an uninitialized mutable array with the given element type and size, based upon the given source array. The second and third arguments are both optional, defaulting to the given array's <code>eltype</code> and <code>size</code>. The dimensions may be specified either as a single tuple argument or as a series of integer arguments.</p><p>Custom AbstractArray subtypes may choose which specific array type is best-suited to return for the given element type and dimensionality. If they do not specialize this method, the default is an <code>Array{element_type}(undef, dims...)</code>.</p><p>For example, <code>similar(1:10, 1, 4)</code> returns an uninitialized <code>Array{Int,2}</code> since ranges are neither mutable nor support 2 dimensions:</p><pre><code class="language-julia-repl">julia> similar(1:10, 1, 4)
1×4 Matrix{Int64}:
4419743872 4374413872 4419743888 0</code></pre><p>Conversely, <code>similar(trues(10,10), 2)</code> returns an uninitialized <code>BitVector</code> with two elements since <code>BitArray</code>s are both mutable and can support 1-dimensional arrays:</p><pre><code class="language-julia-repl">julia> similar(trues(10,10), 2)
2-element BitVector:
0
0</code></pre><p>Since <code>BitArray</code>s can only store elements of type <a href="../numbers/#Core.Bool"><code>Bool</code></a>, however, if you request a different element type it will create a regular <code>Array</code> instead:</p><pre><code class="language-julia-repl">julia> similar(falses(10), Float64, 2, 4)
2×4 Matrix{Float64}:
2.18425e-314 2.18425e-314 2.18425e-314 2.18425e-314
2.18425e-314 2.18425e-314 2.18425e-314 2.18425e-314</code></pre><p>See also: <a href="#Core.undef"><code>undef</code></a>, <a href="#Base.isassigned"><code>isassigned</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L750-L792">source</a></section><section><div><pre><code class="language-none">similar(storagetype, axes)</code></pre><p>Create an uninitialized mutable array analogous to that specified by <code>storagetype</code>, but with <code>axes</code> specified by the last argument.</p><p><strong>Examples</strong>:</p><pre><code class="language-none">similar(Array{Int}, axes(A))</code></pre><p>creates an array that "acts like" an <code>Array{Int}</code> (and might indeed be backed by one), but which is indexed identically to <code>A</code>. If <code>A</code> has conventional indexing, this will be identical to <code>Array{Int}(undef, size(A))</code>, but if <code>A</code> has unconventional indexing then the indices of the result will match <code>A</code>.</p><pre><code class="language-none">similar(BitArray, (axes(A, 2),))</code></pre><p>would create a 1-dimensional logical array whose indices match those of the columns of <code>A</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L817-L838">source</a></section></article><h2 id="基础函数"><a class="docs-heading-anchor" href="#基础函数">基础函数</a><a id="基础函数-1"></a><a class="docs-heading-anchor-permalink" href="#基础函数" title="Permalink"></a></h2><article class="docstring"><header><a class="docstring-binding" id="Base.ndims" href="#Base.ndims"><code>Base.ndims</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">ndims(A::AbstractArray) -> Integer</code></pre><p>Return the number of dimensions of <code>A</code>.</p><p>See also: <a href="#Base.size"><code>size</code></a>, <a href="#Base.axes-Tuple{Any}"><code>axes</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = fill(1, (3,4,5));
julia> ndims(A)
3</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L224-L238">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.size" href="#Base.size"><code>Base.size</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">size(A::AbstractArray, [dim])</code></pre><p>Return a tuple containing the dimensions of <code>A</code>. Optionally you can specify a dimension to just get the length of that dimension.</p><p>Note that <code>size</code> may not be defined for arrays with non-standard indices, in which case <a href="#Base.axes-Tuple{Any}"><code>axes</code></a> may be useful. See the manual chapter on <a href="../../devdocs/offset-arrays/#man-custom-indices">arrays with custom indices</a>.</p><p>See also: <a href="../collections/#Base.length"><code>length</code></a>, <a href="#Base.ndims"><code>ndims</code></a>, <a href="#Base.eachindex"><code>eachindex</code></a>, <a href="../base/#Base.sizeof-Tuple{Type}"><code>sizeof</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = fill(1, (2,3,4));
julia> size(A)
(2, 3, 4)
julia> size(A, 2)
3</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L20-L41">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.axes-Tuple{Any}" href="#Base.axes-Tuple{Any}"><code>Base.axes</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">axes(A)</code></pre><p>Return the tuple of valid indices for array <code>A</code>.</p><p>See also: <a href="#Base.size"><code>size</code></a>, <a href="../collections/#Base.keys"><code>keys</code></a>, <a href="#Base.eachindex"><code>eachindex</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = fill(1, (5,6,7));
julia> axes(A)
(Base.OneTo(5), Base.OneTo(6), Base.OneTo(7))</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L77-L92">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.axes-Tuple{AbstractArray, Any}" href="#Base.axes-Tuple{AbstractArray, Any}"><code>Base.axes</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">axes(A, d)</code></pre><p>Return the valid range of indices for array <code>A</code> along dimension <code>d</code>.</p><p>See also <a href="#Base.size"><code>size</code></a>, and the manual chapter on <a href="../../devdocs/offset-arrays/#man-custom-indices">arrays with custom indices</a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = fill(1, (5,6,7));
julia> axes(A, 2)
Base.OneTo(6)</code></pre><p><strong>Usage note</strong></p><p>Each of the indices has to be an <code>AbstractUnitRange{<:Integer}</code>, but at the same time can be a type that uses custom indices. So, for example, if you need a subset, use generalized indexing constructs like <code>begin</code>/<code>end</code> or <a href="../collections/#Base.firstindex"><code>firstindex</code></a>/<a href="../collections/#Base.lastindex"><code>lastindex</code></a>:</p><pre><code class="language-julia">ix = axes(v, 1)
ix[2:end] # will work for eg Vector, but may fail in general
ix[(begin+1):end] # works for generalized indexes</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L44-L71">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.length-Tuple{AbstractArray}" href="#Base.length-Tuple{AbstractArray}"><code>Base.length</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">length(A::AbstractArray)</code></pre><p>Return the number of elements in the array, defaults to <code>prod(size(A))</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> length([1, 2, 3, 4])
4
julia> length([1 2; 3 4])
4</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L265-L278">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.keys-Tuple{AbstractArray}" href="#Base.keys-Tuple{AbstractArray}"><code>Base.keys</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">keys(a::AbstractArray)</code></pre><p>Return an efficient array describing all valid indices for <code>a</code> arranged in the shape of <code>a</code> itself.</p><p>They keys of 1-dimensional arrays (vectors) are integers, whereas all other N-dimensional arrays use <a href="#Base.IteratorsMD.CartesianIndex"><code>CartesianIndex</code></a> to describe their locations. Often the special array types <a href="#Base.LinearIndices"><code>LinearIndices</code></a> and <a href="#Base.IteratorsMD.CartesianIndices"><code>CartesianIndices</code></a> are used to efficiently represent these arrays of integers and <code>CartesianIndex</code>es, respectively.</p><p>Note that the <code>keys</code> of an array might not be the most efficient index type; for maximum performance use <a href="#Base.eachindex"><code>eachindex</code></a> instead.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L119-L131">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.eachindex" href="#Base.eachindex"><code>Base.eachindex</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">eachindex(A...)</code></pre><p>Create an iterable object for visiting each index of an <code>AbstractArray</code> <code>A</code> in an efficient manner. For array types that have opted into fast linear indexing (like <code>Array</code>), this is simply the range <code>1:length(A)</code>. For other array types, return a specialized Cartesian range to efficiently index into the array with indices specified for every dimension. For other iterables, including strings and dictionaries, return an iterator object supporting arbitrary index types (e.g. unevenly spaced or non-integer indices).</p><p>If you supply more than one <code>AbstractArray</code> argument, <code>eachindex</code> will create an iterable object that is fast for all arguments (a <a href="../collections/#Base.UnitRange"><code>UnitRange</code></a> if all inputs have fast linear indexing, a <a href="#Base.IteratorsMD.CartesianIndices"><code>CartesianIndices</code></a> otherwise). If the arrays have different sizes and/or dimensionalities, a <code>DimensionMismatch</code> exception will be thrown.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [1 2; 3 4];
julia> for i in eachindex(A) # linear indexing
println(i)
end
1
2
3
4
julia> for i in eachindex(view(A, 1:2, 1:1)) # Cartesian indexing
println(i)
end
CartesianIndex(1, 1)
CartesianIndex(2, 1)</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L295-L329">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.IndexStyle" href="#Base.IndexStyle"><code>Base.IndexStyle</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">IndexStyle(A)
IndexStyle(typeof(A))</code></pre><p><code>IndexStyle</code> specifies the "native indexing style" for array <code>A</code>. When you define a new <a href="#Core.AbstractArray"><code>AbstractArray</code></a> type, you can choose to implement either linear indexing (with <a href="#Base.IndexLinear"><code>IndexLinear</code></a>) or cartesian indexing. If you decide to only implement linear indexing, then you must set this trait for your array type:</p><pre><code class="language-none">Base.IndexStyle(::Type{<:MyArray}) = IndexLinear()</code></pre><p>The default is <a href="#Base.IndexCartesian"><code>IndexCartesian()</code></a>.</p><p>Julia's internal indexing machinery will automatically (and invisibly) recompute all indexing operations into the preferred style. This allows users to access elements of your array using any indexing style, even when explicit methods have not been provided.</p><p>If you define both styles of indexing for your <code>AbstractArray</code>, this trait can be used to select the most performant indexing style. Some methods check this trait on their inputs, and dispatch to different algorithms depending on the most efficient access pattern. In particular, <a href="#Base.eachindex"><code>eachindex</code></a> creates an iterator whose type depends on the setting of this trait.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/indices.jl#L68-L93">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.IndexLinear" href="#Base.IndexLinear"><code>Base.IndexLinear</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">IndexLinear()</code></pre><p>Subtype of <a href="#Base.IndexStyle"><code>IndexStyle</code></a> used to describe arrays which are optimally indexed by one linear index.</p><p>A linear indexing style uses one integer index to describe the position in the array (even if it's a multidimensional array) and column-major ordering is used to efficiently access the elements. This means that requesting <a href="#Base.eachindex"><code>eachindex</code></a> from an array that is <code>IndexLinear</code> will return a simple one-dimensional range, even if it is multidimensional.</p><p>A custom array that reports its <code>IndexStyle</code> as <code>IndexLinear</code> only needs to implement indexing (and indexed assignment) with a single <code>Int</code> index; all other indexing expressions — including multidimensional accesses — will be recomputed to the linear index. For example, if <code>A</code> were a <code>2×3</code> custom matrix with linear indexing, and we referenced <code>A[1, 3]</code>, this would be recomputed to the equivalent linear index and call <code>A[5]</code> since <code>2*1 + 3 = 5</code>.</p><p>See also <a href="#Base.IndexCartesian"><code>IndexCartesian</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/indices.jl#L16-L36">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.IndexCartesian" href="#Base.IndexCartesian"><code>Base.IndexCartesian</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">IndexCartesian()</code></pre><p>Subtype of <a href="#Base.IndexStyle"><code>IndexStyle</code></a> used to describe arrays which are optimally indexed by a Cartesian index. This is the default for new custom <a href="#Core.AbstractArray"><code>AbstractArray</code></a> subtypes.</p><p>A Cartesian indexing style uses multiple integer indices to describe the position in a multidimensional array, with exactly one index per dimension. This means that requesting <a href="#Base.eachindex"><code>eachindex</code></a> from an array that is <code>IndexCartesian</code> will return a range of <a href="#Base.IteratorsMD.CartesianIndices"><code>CartesianIndices</code></a>.</p><p>A <code>N</code>-dimensional custom array that reports its <code>IndexStyle</code> as <code>IndexCartesian</code> needs to implement indexing (and indexed assignment) with exactly <code>N</code> <code>Int</code> indices; all other indexing expressions — including linear indexing — will be recomputed to the equivalent Cartesian location. For example, if <code>A</code> were a <code>2×3</code> custom matrix with cartesian indexing, and we referenced <code>A[5]</code>, this would be recomputed to the equivalent Cartesian index and call <code>A[1, 3]</code> since <code>5 = 2*1 + 3</code>.</p><p>It is significantly more expensive to compute Cartesian indices from a linear index than it is to go the other way. The former operation requires division — a very costly operation — whereas the latter only uses multiplication and addition and is essentially free. This asymmetry means it is far more costly to use linear indexing with an <code>IndexCartesian</code> array than it is to use Cartesian indexing with an <code>IndexLinear</code> array.</p><p>See also <a href="#Base.IndexLinear"><code>IndexLinear</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/indices.jl#L39-L65">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.conj!" href="#Base.conj!"><code>Base.conj!</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">conj!(A)</code></pre><p>Transform an array to its complex conjugate in-place.</p><p>See also <a href="../math/#Base.conj"><code>conj</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [1+im 2-im; 2+2im 3+im]
2×2 Matrix{Complex{Int64}}:
1+1im 2-1im
2+2im 3+1im
julia> conj!(A);
julia> A
2×2 Matrix{Complex{Int64}}:
1-1im 2+1im
2-2im 3-1im</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarraymath.jl#L98-L119">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.stride" href="#Base.stride"><code>Base.stride</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">stride(A, k::Integer)</code></pre><p>Return the distance in memory (in number of elements) between adjacent elements in dimension <code>k</code>.</p><p>See also: <a href="#Base.strides"><code>strides</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = fill(1, (3,4,5));
julia> stride(A,2)
3
julia> stride(A,3)
12</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L528-L545">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.strides" href="#Base.strides"><code>Base.strides</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">strides(A)</code></pre><p>Return a tuple of the memory strides in each dimension.</p><p>See also: <a href="#Base.stride"><code>stride</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = fill(1, (3,4,5));
julia> strides(A)
(1, 3, 12)</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L511-L525">source</a></section></article><h2 id="广播与矢量化"><a class="docs-heading-anchor" href="#广播与矢量化">广播与矢量化</a><a id="广播与矢量化-1"></a><a class="docs-heading-anchor-permalink" href="#广播与矢量化" title="Permalink"></a></h2><p>也可参照 <a href="../../manual/functions/#man-vectorized">dot syntax for vectorizing functions</a>; 例如,<code>f.(args...)</code> 隐式调用 <code>broadcast(f, args...)</code>。 与其依赖如 <code>sin</code> 函数的“已矢量化”方法,你应该使用 <code>sin.(a)</code> 来使用<code>broadcast</code>来矢量化。</p><article class="docstring"><header><a class="docstring-binding" id="Base.Broadcast.broadcast" href="#Base.Broadcast.broadcast"><code>Base.Broadcast.broadcast</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">broadcast(f, As...)</code></pre><p>Broadcast the function <code>f</code> over the arrays, tuples, collections, <a href="../c/#Core.Ref"><code>Ref</code></a>s and/or scalars <code>As</code>.</p><p>Broadcasting applies the function <code>f</code> over the elements of the container arguments and the scalars themselves in <code>As</code>. Singleton and missing dimensions are expanded to match the extents of the other arguments by virtually repeating the value. By default, only a limited number of types are considered scalars, including <code>Number</code>s, <code>String</code>s, <code>Symbol</code>s, <code>Type</code>s, <code>Function</code>s and some common singletons like <a href="../base/#Base.missing"><code>missing</code></a> and <a href="../constants/#Core.nothing"><code>nothing</code></a>. All other arguments are iterated over or indexed into elementwise.</p><p>The resulting container type is established by the following rules:</p><ul><li>If all the arguments are scalars or zero-dimensional arrays, it returns an unwrapped scalar.</li><li>If at least one argument is a tuple and all others are scalars or zero-dimensional arrays, it returns a tuple.</li><li>All other combinations of arguments default to returning an <code>Array</code>, but custom container types can define their own implementation and promotion-like rules to customize the result when they appear as arguments.</li></ul><p>A special syntax exists for broadcasting: <code>f.(args...)</code> is equivalent to <code>broadcast(f, args...)</code>, and nested <code>f.(g.(args...))</code> calls are fused into a single broadcast loop.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [1, 2, 3, 4, 5]
5-element Vector{Int64}:
1
2
3
4
5
julia> B = [1 2; 3 4; 5 6; 7 8; 9 10]
5×2 Matrix{Int64}:
1 2
3 4
5 6
7 8
9 10
julia> broadcast(+, A, B)
5×2 Matrix{Int64}:
2 3
5 6
8 9
11 12
14 15
julia> parse.(Int, ["1", "2"])
2-element Vector{Int64}:
1
2
julia> abs.((1, -2))
(1, 2)
julia> broadcast(+, 1.0, (0, -2.0))
(1.0, -1.0)
julia> (+).([[0,2], [1,3]], Ref{Vector{Int}}([1,-1]))
2-element Vector{Vector{Int64}}:
[1, 1]
[2, 2]
julia> string.(("one","two","three","four"), ": ", 1:4)
4-element Vector{String}:
"one: 1"
"two: 2"
"three: 3"
"four: 4"
</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/broadcast.jl#L722-L797">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Broadcast.broadcast!" href="#Base.Broadcast.broadcast!"><code>Base.Broadcast.broadcast!</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">broadcast!(f, dest, As...)</code></pre><p>Like <a href="#Base.Broadcast.broadcast"><code>broadcast</code></a>, but store the result of <code>broadcast(f, As...)</code> in the <code>dest</code> array. Note that <code>dest</code> is only used to store the result, and does not supply arguments to <code>f</code> unless it is also listed in the <code>As</code>, as in <code>broadcast!(f, A, A, B)</code> to perform <code>A[:] = broadcast(f, A, B)</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [1.0; 0.0]; B = [0.0; 0.0];
julia> broadcast!(+, B, A, (0, -2.0));
julia> B
2-element Vector{Float64}:
1.0
-2.0
julia> A
2-element Vector{Float64}:
1.0
0.0
julia> broadcast!(+, A, A, (0, -2.0));
julia> A
2-element Vector{Float64}:
1.0
-2.0</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/broadcast.jl#L804-L836">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Broadcast.@__dot__" href="#Base.Broadcast.@__dot__"><code>Base.Broadcast.@__dot__</code></a> — <span class="docstring-category">Macro</span></header><section><div><pre><code class="language-julia">@. expr</code></pre><p>Convert every function call or operator in <code>expr</code> into a "dot call" (e.g. convert <code>f(x)</code> to <code>f.(x)</code>), and convert every assignment in <code>expr</code> to a "dot assignment" (e.g. convert <code>+=</code> to <code>.+=</code>).</p><p>If you want to <em>avoid</em> adding dots for selected function calls in <code>expr</code>, splice those function calls in with <code>$</code>. For example, <code>@. sqrt(abs($sort(x)))</code> is equivalent to <code>sqrt.(abs.(sort(x)))</code> (no dot for <code>sort</code>).</p><p>(<code>@.</code> is equivalent to a call to <code>@__dot__</code>.)</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> x = 1.0:3.0; y = similar(x);
julia> @. y = x + 3 * sin(x)
3-element Vector{Float64}:
3.5244129544236893
4.727892280477045
3.4233600241796016</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/broadcast.jl#L1251-L1275">source</a></section></article><p>自定义类型的广播,请参照</p><article class="docstring"><header><a class="docstring-binding" id="Base.Broadcast.BroadcastStyle" href="#Base.Broadcast.BroadcastStyle"><code>Base.Broadcast.BroadcastStyle</code></a> — <span class="docstring-category">Type</span></header><section><div><p><code>BroadcastStyle</code> is an abstract type and trait-function used to determine behavior of objects under broadcasting. <code>BroadcastStyle(typeof(x))</code> returns the style associated with <code>x</code>. To customize the broadcasting behavior of a type, one can declare a style by defining a type/method pair</p><pre><code class="language-none">struct MyContainerStyle <: BroadcastStyle end
Base.BroadcastStyle(::Type{<:MyContainer}) = MyContainerStyle()</code></pre><p>One then writes method(s) (at least <a href="#Base.similar"><code>similar</code></a>) operating on <code>Broadcasted{MyContainerStyle}</code>. There are also several pre-defined subtypes of <code>BroadcastStyle</code> that you may be able to leverage; see the <a href="../../manual/interfaces/#man-interfaces-broadcasting">Interfaces chapter</a> for more information.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/broadcast.jl#L21-L34">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Broadcast.AbstractArrayStyle" href="#Base.Broadcast.AbstractArrayStyle"><code>Base.Broadcast.AbstractArrayStyle</code></a> — <span class="docstring-category">Type</span></header><section><div><p><code>Broadcast.AbstractArrayStyle{N} <: BroadcastStyle</code> is the abstract supertype for any style associated with an <code>AbstractArray</code> type. The <code>N</code> parameter is the dimensionality, which can be handy for AbstractArray types that only support specific dimensionalities:</p><pre><code class="language-none">struct SparseMatrixStyle <: Broadcast.AbstractArrayStyle{2} end
Base.BroadcastStyle(::Type{<:SparseMatrixCSC}) = SparseMatrixStyle()</code></pre><p>For <code>AbstractArray</code> types that support arbitrary dimensionality, <code>N</code> can be set to <code>Any</code>:</p><pre><code class="language-none">struct MyArrayStyle <: Broadcast.AbstractArrayStyle{Any} end
Base.BroadcastStyle(::Type{<:MyArray}) = MyArrayStyle()</code></pre><p>In cases where you want to be able to mix multiple <code>AbstractArrayStyle</code>s and keep track of dimensionality, your style needs to support a <a href="../base/#Base.Val"><code>Val</code></a> constructor:</p><pre><code class="language-none">struct MyArrayStyleDim{N} <: Broadcast.AbstractArrayStyle{N} end
(::Type{<:MyArrayStyleDim})(::Val{N}) where N = MyArrayStyleDim{N}()</code></pre><p>Note that if two or more <code>AbstractArrayStyle</code> subtypes conflict, broadcasting machinery will fall back to producing <code>Array</code>s. If this is undesirable, you may need to define binary <a href="#Base.Broadcast.BroadcastStyle"><code>BroadcastStyle</code></a> rules to control the output type.</p><p>See also <a href="#Base.Broadcast.DefaultArrayStyle"><code>Broadcast.DefaultArrayStyle</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/broadcast.jl#L51-L76">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Broadcast.ArrayStyle" href="#Base.Broadcast.ArrayStyle"><code>Base.Broadcast.ArrayStyle</code></a> — <span class="docstring-category">Type</span></header><section><div><p><code>Broadcast.ArrayStyle{MyArrayType}()</code> is a <a href="#Base.Broadcast.BroadcastStyle"><code>BroadcastStyle</code></a> indicating that an object behaves as an array for broadcasting. It presents a simple way to construct <a href="#Base.Broadcast.AbstractArrayStyle"><code>Broadcast.AbstractArrayStyle</code></a>s for specific <code>AbstractArray</code> container types. Broadcast styles created this way lose track of dimensionality; if keeping track is important for your type, you should create your own custom <a href="#Base.Broadcast.AbstractArrayStyle"><code>Broadcast.AbstractArrayStyle</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/broadcast.jl#L79-L85">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Broadcast.DefaultArrayStyle" href="#Base.Broadcast.DefaultArrayStyle"><code>Base.Broadcast.DefaultArrayStyle</code></a> — <span class="docstring-category">Type</span></header><section><div><p><code>Broadcast.DefaultArrayStyle{N}()</code> is a <a href="#Base.Broadcast.BroadcastStyle"><code>BroadcastStyle</code></a> indicating that an object behaves as an <code>N</code>-dimensional array for broadcasting. Specifically, <code>DefaultArrayStyle</code> is used for any <code>AbstractArray</code> type that hasn't defined a specialized style, and in the absence of overrides from other <code>broadcast</code> arguments the resulting output type is <code>Array</code>. When there are multiple inputs to <code>broadcast</code>, <code>DefaultArrayStyle</code> "loses" to any other <a href="#Base.Broadcast.ArrayStyle"><code>Broadcast.ArrayStyle</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/broadcast.jl#L89-L96">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Broadcast.broadcastable" href="#Base.Broadcast.broadcastable"><code>Base.Broadcast.broadcastable</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">Broadcast.broadcastable(x)</code></pre><p>Return either <code>x</code> or an object like <code>x</code> such that it supports <a href="#Base.axes-Tuple{Any}"><code>axes</code></a>, indexing, and its type supports <a href="#Base.ndims"><code>ndims</code></a>.</p><p>If <code>x</code> supports iteration, the returned value should have the same <code>axes</code> and indexing behaviors as <a href="../collections/#Base.collect-Tuple{Any}"><code>collect(x)</code></a>.</p><p>If <code>x</code> is not an <code>AbstractArray</code> but it supports <code>axes</code>, indexing, and its type supports <code>ndims</code>, then <code>broadcastable(::typeof(x))</code> may be implemented to just return itself. Further, if <code>x</code> defines its own <a href="#Base.Broadcast.BroadcastStyle"><code>BroadcastStyle</code></a>, then it must define its <code>broadcastable</code> method to return itself for the custom style to have any effect.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Broadcast.broadcastable([1,2,3]) # like `identity` since arrays already support axes and indexing
3-element Vector{Int64}:
1
2
3
julia> Broadcast.broadcastable(Int) # Types don't support axes, indexing, or iteration but are commonly used as scalars
Base.RefValue{Type{Int64}}(Int64)
julia> Broadcast.broadcastable("hello") # Strings break convention of matching iteration and act like a scalar instead
Base.RefValue{String}("hello")</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/broadcast.jl#L672-L699">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Broadcast.combine_axes" href="#Base.Broadcast.combine_axes"><code>Base.Broadcast.combine_axes</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">combine_axes(As...) -> Tuple</code></pre><p>Determine the result axes for broadcasting across all values in <code>As</code>.</p><pre><code class="language-julia-repl">julia> Broadcast.combine_axes([1], [1 2; 3 4; 5 6])
(Base.OneTo(3), Base.OneTo(2))
julia> Broadcast.combine_axes(1, 1, 1)
()</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/broadcast.jl#L485-L497">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Broadcast.combine_styles" href="#Base.Broadcast.combine_styles"><code>Base.Broadcast.combine_styles</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">combine_styles(cs...) -> BroadcastStyle</code></pre><p>Decides which <code>BroadcastStyle</code> to use for any number of value arguments. Uses <a href="#Base.Broadcast.BroadcastStyle"><code>BroadcastStyle</code></a> to get the style for each argument, and uses <a href="#Base.Broadcast.result_style"><code>result_style</code></a> to combine styles.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Broadcast.combine_styles([1], [1 2; 3 4])
Base.Broadcast.DefaultArrayStyle{2}()</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/broadcast.jl#L418-L431">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Broadcast.result_style" href="#Base.Broadcast.result_style"><code>Base.Broadcast.result_style</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">result_style(s1::BroadcastStyle[, s2::BroadcastStyle]) -> BroadcastStyle</code></pre><p>Takes one or two <code>BroadcastStyle</code>s and combines them using <a href="#Base.Broadcast.BroadcastStyle"><code>BroadcastStyle</code></a> to determine a common <code>BroadcastStyle</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Broadcast.result_style(Broadcast.DefaultArrayStyle{0}(), Broadcast.DefaultArrayStyle{3}())
Base.Broadcast.DefaultArrayStyle{3}()
julia> Broadcast.result_style(Broadcast.Unknown(), Broadcast.DefaultArrayStyle{1}())
Base.Broadcast.DefaultArrayStyle{1}()</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/broadcast.jl#L439-L454">source</a></section></article><h2 id="索引与赋值"><a class="docs-heading-anchor" href="#索引与赋值">索引与赋值</a><a id="索引与赋值-1"></a><a class="docs-heading-anchor-permalink" href="#索引与赋值" title="Permalink"></a></h2><article class="docstring"><header><a class="docstring-binding" id="Base.getindex-Tuple{AbstractArray, Vararg{Any}}" href="#Base.getindex-Tuple{AbstractArray, Vararg{Any}}"><code>Base.getindex</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">getindex(A, inds...)</code></pre><p>Return a subset of array <code>A</code> as specified by <code>inds</code>, where each <code>ind</code> may be, for example, an <code>Int</code>, an <a href="../collections/#Base.AbstractRange"><code>AbstractRange</code></a>, or a <a href="#Base.Vector"><code>Vector</code></a>. See the manual section on <a href="../../manual/arrays/#man-array-indexing">array indexing</a> for details.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [1 2; 3 4]
2×2 Matrix{Int64}:
1 2
3 4
julia> getindex(A, 1)
1
julia> getindex(A, [2, 1])
2-element Vector{Int64}:
3
1
julia> getindex(A, 2:4)
3-element Vector{Int64}:
3
2
4</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L1209-L1237">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.setindex!-Tuple{AbstractArray, Any, Vararg{Any}}" href="#Base.setindex!-Tuple{AbstractArray, Any, Vararg{Any}}"><code>Base.setindex!</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">setindex!(A, X, inds...)
A[inds...] = X</code></pre><p>Store values from array <code>X</code> within some subset of <code>A</code> as specified by <code>inds</code>. The syntax <code>A[inds...] = X</code> is equivalent to <code>(setindex!(A, X, inds...); X)</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = zeros(2,2);
julia> setindex!(A, [10, 20], [1, 2]);
julia> A[[3, 4]] = [30, 40];
julia> A
2×2 Matrix{Float64}:
10.0 30.0
20.0 40.0</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L1320-L1340">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.copyto!-Tuple{AbstractArray, CartesianIndices, AbstractArray, CartesianIndices}" href="#Base.copyto!-Tuple{AbstractArray, CartesianIndices, AbstractArray, CartesianIndices}"><code>Base.copyto!</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">copyto!(dest, Rdest::CartesianIndices, src, Rsrc::CartesianIndices) -> dest</code></pre><p>Copy the block of <code>src</code> in the range of <code>Rsrc</code> to the block of <code>dest</code> in the range of <code>Rdest</code>. The sizes of the two regions must match.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = zeros(5, 5);
julia> B = [1 2; 3 4];
julia> Ainds = CartesianIndices((2:3, 2:3));
julia> Binds = CartesianIndices(B);
julia> copyto!(A, Ainds, B, Binds)
5×5 Matrix{Float64}:
0.0 0.0 0.0 0.0 0.0
0.0 1.0 2.0 0.0 0.0
0.0 3.0 4.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/multidimensional.jl#L1133-L1157">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.copy!" href="#Base.copy!"><code>Base.copy!</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">copy!(dst, src) -> dst</code></pre><p>In-place <a href="../base/#Base.copy"><code>copy</code></a> of <code>src</code> into <code>dst</code>, discarding any pre-existing elements in <code>dst</code>. If <code>dst</code> and <code>src</code> are of the same type, <code>dst == src</code> should hold after the call. If <code>dst</code> and <code>src</code> are multidimensional arrays, they must have equal <a href="#Base.axes-Tuple{Any}"><code>axes</code></a>.</p><p>See also <a href="../c/#Base.copyto!"><code>copyto!</code></a>.</p><div class="admonition is-compat"><header class="admonition-header">Julia 1.1</header><div class="admonition-body"><p>This method requires at least Julia 1.1. In Julia 1.0 this method is available from the <code>Future</code> standard library as <code>Future.copy!</code>.</p></div></div></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L866-L880">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.isassigned" href="#Base.isassigned"><code>Base.isassigned</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">isassigned(array, i) -> Bool</code></pre><p>Test whether the given array has a value associated with index <code>i</code>. Return <code>false</code> if the index is out of bounds, or has an undefined reference.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> isassigned(rand(3, 3), 5)
true
julia> isassigned(rand(3, 3), 3 * 3 + 1)
false
julia> mutable struct Foo end
julia> v = similar(rand(3), Foo)
3-element Vector{Foo}:
#undef
#undef
#undef
julia> isassigned(v, 1)
false</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/essentials.jl#L641-L666">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Colon" href="#Base.Colon"><code>Base.Colon</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">Colon()</code></pre><p>Colons (:) are used to signify indexing entire objects or dimensions at once.</p><p>Very few operations are defined on Colons directly; instead they are converted by <a href="#Base.to_indices"><code>to_indices</code></a> to an internal vector type (<code>Base.Slice</code>) to represent the collection of indices they span before being used.</p><p>The singleton instance of <code>Colon</code> is also a function used to construct ranges; see <a href="../math/#Base.::"><code>:</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/essentials.jl#L675-L686">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.IteratorsMD.CartesianIndex" href="#Base.IteratorsMD.CartesianIndex"><code>Base.IteratorsMD.CartesianIndex</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">CartesianIndex(i, j, k...) -> I
CartesianIndex((i, j, k...)) -> I</code></pre><p>Create a multidimensional index <code>I</code>, which can be used for indexing a multidimensional array <code>A</code>. In particular, <code>A[I]</code> is equivalent to <code>A[i,j,k...]</code>. One can freely mix integer and <code>CartesianIndex</code> indices; for example, <code>A[Ipre, i, Ipost]</code> (where <code>Ipre</code> and <code>Ipost</code> are <code>CartesianIndex</code> indices and <code>i</code> is an <code>Int</code>) can be a useful expression when writing algorithms that work along a single dimension of an array of arbitrary dimensionality.</p><p>A <code>CartesianIndex</code> is sometimes produced by <a href="#Base.eachindex"><code>eachindex</code></a>, and always when iterating with an explicit <a href="#Base.IteratorsMD.CartesianIndices"><code>CartesianIndices</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = reshape(Vector(1:16), (2, 2, 2, 2))
2×2×2×2 Array{Int64, 4}:
[:, :, 1, 1] =
1 3
2 4
[:, :, 2, 1] =
5 7
6 8
[:, :, 1, 2] =
9 11
10 12
[:, :, 2, 2] =
13 15
14 16
julia> A[CartesianIndex((1, 1, 1, 1))]
1
julia> A[CartesianIndex((1, 1, 1, 2))]
9
julia> A[CartesianIndex((1, 1, 2, 1))]
5</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/multidimensional.jl#L18-L63">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.IteratorsMD.CartesianIndices" href="#Base.IteratorsMD.CartesianIndices"><code>Base.IteratorsMD.CartesianIndices</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">CartesianIndices(sz::Dims) -> R
CartesianIndices((istart:[istep:]istop, jstart:[jstep:]jstop, ...)) -> R</code></pre><p>Define a region <code>R</code> spanning a multidimensional rectangular range of integer indices. These are most commonly encountered in the context of iteration, where <code>for I in R ... end</code> will return <a href="#Base.IteratorsMD.CartesianIndex"><code>CartesianIndex</code></a> indices <code>I</code> equivalent to the nested loops</p><pre><code class="language-none">for j = jstart:jstep:jstop
for i = istart:istep:istop
...
end
end</code></pre><p>Consequently these can be useful for writing algorithms that work in arbitrary dimensions.</p><pre><code class="language-none">CartesianIndices(A::AbstractArray) -> R</code></pre><p>As a convenience, constructing a <code>CartesianIndices</code> from an array makes a range of its indices.</p><div class="admonition is-compat"><header class="admonition-header">Julia 1.6</header><div class="admonition-body"><p>The step range method <code>CartesianIndices((istart:istep:istop, jstart:[jstep:]jstop, ...))</code> requires at least Julia 1.6.</p></div></div><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> foreach(println, CartesianIndices((2, 2, 2)))
CartesianIndex(1, 1, 1)
CartesianIndex(2, 1, 1)
CartesianIndex(1, 2, 1)
CartesianIndex(2, 2, 1)
CartesianIndex(1, 1, 2)
CartesianIndex(2, 1, 2)
CartesianIndex(1, 2, 2)
CartesianIndex(2, 2, 2)
julia> CartesianIndices(fill(1, (2,3)))
CartesianIndices((2, 3))</code></pre><p><strong>Conversion between linear and cartesian indices</strong></p><p>Linear index to cartesian index conversion exploits the fact that a <code>CartesianIndices</code> is an <code>AbstractArray</code> and can be indexed linearly:</p><pre><code class="language-julia-repl">julia> cartesian = CartesianIndices((1:3, 1:2))
CartesianIndices((1:3, 1:2))
julia> cartesian[4]
CartesianIndex(1, 2)
julia> cartesian = CartesianIndices((1:2:5, 1:2))
CartesianIndices((1:2:5, 1:2))
julia> cartesian[2, 2]
CartesianIndex(3, 2)</code></pre><p><strong>Broadcasting</strong></p><p><code>CartesianIndices</code> support broadcasting arithmetic (+ and -) with a <code>CartesianIndex</code>.</p><div class="admonition is-compat"><header class="admonition-header">Julia 1.1</header><div class="admonition-body"><p>Broadcasting of CartesianIndices requires at least Julia 1.1.</p></div></div><pre><code class="language-julia-repl">julia> CIs = CartesianIndices((2:3, 5:6))
CartesianIndices((2:3, 5:6))
julia> CI = CartesianIndex(3, 4)
CartesianIndex(3, 4)
julia> CIs .+ CI
CartesianIndices((5:6, 9:10))</code></pre><p>For cartesian to linear index conversion, see <a href="#Base.LinearIndices"><code>LinearIndices</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/multidimensional.jl#L166-L247">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.Dims" href="#Base.Dims"><code>Base.Dims</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">Dims{N}</code></pre><p>An <code>NTuple</code> of <code>N</code> <code>Int</code>s used to represent the dimensions of an <a href="#Core.AbstractArray"><code>AbstractArray</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/indices.jl#L3-L8">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.LinearIndices" href="#Base.LinearIndices"><code>Base.LinearIndices</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">LinearIndices(A::AbstractArray)</code></pre><p>Return a <code>LinearIndices</code> array with the same shape and <a href="#Base.axes-Tuple{Any}"><code>axes</code></a> as <code>A</code>, holding the linear index of each entry in <code>A</code>. Indexing this array with cartesian indices allows mapping them to linear indices.</p><p>For arrays with conventional indexing (indices start at 1), or any multidimensional array, linear indices range from 1 to <code>length(A)</code>. However, for <code>AbstractVector</code>s linear indices are <code>axes(A, 1)</code>, and therefore do not start at 1 for vectors with unconventional indexing.</p><p>Calling this function is the "safe" way to write algorithms that exploit linear indexing.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = fill(1, (5,6,7));
julia> b = LinearIndices(A);
julia> extrema(b)
(1, 210)</code></pre><pre><code class="language-none">LinearIndices(inds::CartesianIndices) -> R
LinearIndices(sz::Dims) -> R
LinearIndices((istart:istop, jstart:jstop, ...)) -> R</code></pre><p>Return a <code>LinearIndices</code> array with the specified shape or <a href="#Base.axes-Tuple{Any}"><code>axes</code></a>.</p><p><strong>Example</strong></p><p>The main purpose of this constructor is intuitive conversion from cartesian to linear indexing:</p><pre><code class="language-julia-repl">julia> linear = LinearIndices((1:3, 1:2))
3×2 LinearIndices{2, Tuple{UnitRange{Int64}, UnitRange{Int64}}}:
1 4
2 5
3 6
julia> linear[1,2]
4</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/indices.jl#L401-L447">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.to_indices" href="#Base.to_indices"><code>Base.to_indices</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">to_indices(A, I::Tuple)</code></pre><p>Convert the tuple <code>I</code> to a tuple of indices for use in indexing into array <code>A</code>.</p><p>The returned tuple must only contain either <code>Int</code>s or <code>AbstractArray</code>s of scalar indices that are supported by array <code>A</code>. It will error upon encountering a novel index type that it does not know how to process.</p><p>For simple index types, it defers to the unexported <code>Base.to_index(A, i)</code> to process each index <code>i</code>. While this internal function is not intended to be called directly, <code>Base.to_index</code> may be extended by custom array or index types to provide custom indexing behaviors.</p><p>More complicated index types may require more context about the dimension into which they index. To support those cases, <code>to_indices(A, I)</code> calls <code>to_indices(A, axes(A), I)</code>, which then recursively walks through both the given tuple of indices and the dimensional indices of <code>A</code> in tandem. As such, not all index types are guaranteed to propagate to <code>Base.to_index</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/indices.jl#L304-L323">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.checkbounds" href="#Base.checkbounds"><code>Base.checkbounds</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">checkbounds(Bool, A, I...)</code></pre><p>Return <code>true</code> if the specified indices <code>I</code> are in bounds for the given array <code>A</code>. Subtypes of <code>AbstractArray</code> should specialize this method if they need to provide custom bounds checking behaviors; however, in many cases one can rely on <code>A</code>'s indices and <a href="#Base.checkindex"><code>checkindex</code></a>.</p><p>See also <a href="#Base.checkindex"><code>checkindex</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = rand(3, 3);
julia> checkbounds(Bool, A, 2)
true
julia> checkbounds(Bool, A, 3, 4)
false
julia> checkbounds(Bool, A, 1:3)
true
julia> checkbounds(Bool, A, 1:3, 2:4)
false</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L618-L644">source</a></section><section><div><pre><code class="language-none">checkbounds(A, I...)</code></pre><p>Throw an error if the specified indices <code>I</code> are not in bounds for the given array <code>A</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L661-L665">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.checkindex" href="#Base.checkindex"><code>Base.checkindex</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">checkindex(Bool, inds::AbstractUnitRange, index)</code></pre><p>Return <code>true</code> if the given <code>index</code> is within the bounds of <code>inds</code>. Custom types that would like to behave as indices for all arrays can extend this method in order to provide a specialized bounds checking implementation.</p><p>See also <a href="#Base.checkbounds"><code>checkbounds</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> checkindex(Bool, 1:20, 8)
true
julia> checkindex(Bool, 1:20, 21)
false</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L706-L724">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.elsize" href="#Base.elsize"><code>Base.elsize</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">elsize(type)</code></pre><p>Compute the memory stride in bytes between consecutive elements of <code>eltype</code> stored inside the given <code>type</code>, if the array elements are stored densely with a uniform linear stride.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> Base.elsize(rand(Float32, 10))
4</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L209-L221">source</a></section></article><h2 id="Views-(SubArrays-以及其它-view-类型)"><a class="docs-heading-anchor" href="#Views-(SubArrays-以及其它-view-类型)">Views (SubArrays 以及其它 view 类型)</a><a id="Views-(SubArrays-以及其它-view-类型)-1"></a><a class="docs-heading-anchor-permalink" href="#Views-(SubArrays-以及其它-view-类型)" title="Permalink"></a></h2><p>“视图”是一种表现和数组相似的数据结构(它是 <code>AbstractArray</code> 的子类型),但是它的底层数据实际上是另一个数组的一部分。</p><p>例如,<code>x</code> 是一个数组,<code>v = @view x[1:10]</code>,则 <code>v</code> 表现得就像一个含有 10 个元素的数组,但是它的数据实际上是访问 <code>x</code> 的前 10 个元素。对视图的写入,如 <code>v[3] = 2</code>,直接写入了底层的数组 <code>x</code> (这里是修改 <code>x[3]</code>)。</p><p>在 Julia 中,像 <code>x[1:10]</code> 这样的切片操作会创建一个副本。<code>@view x[1:10]</code> 将它变成创建一个视图。 <code>@views</code> 宏可以用于整个代码块(如 <code>@views function foo() .... end</code> 或 <code>@views begin ... end</code>)来将整个代码块中的切片操作变为使用视图。 如<a href="../../manual/performance-tips/#man-performance-views">性能建议</a>所描述的,有时候使用数据的副本更快,而有时候使用视图会更快。</p><article class="docstring"><header><a class="docstring-binding" id="Base.view" href="#Base.view"><code>Base.view</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">view(A, inds...)</code></pre><p>Like <a href="../collections/#Base.getindex"><code>getindex</code></a>, but returns a lightweight array that lazily references (or is effectively a <em>view</em> into) the parent array <code>A</code> at the given index or indices <code>inds</code> instead of eagerly extracting elements or constructing a copied subset. Calling <a href="../collections/#Base.getindex"><code>getindex</code></a> or <a href="../collections/#Base.setindex!"><code>setindex!</code></a> on the returned value (often a <a href="#Base.SubArray"><code>SubArray</code></a>) computes the indices to access or modify the parent array on the fly. The behavior is undefined if the shape of the parent array is changed after <code>view</code> is called because there is no bound check for the parent array; e.g., it may cause a segmentation fault.</p><p>Some immutable parent arrays (like ranges) may choose to simply recompute a new array in some circumstances instead of returning a <code>SubArray</code> if doing so is efficient and provides compatible semantics.</p><div class="admonition is-compat"><header class="admonition-header">Julia 1.6</header><div class="admonition-body"><p>In Julia 1.6 or later, <code>view</code> can be called on an <code>AbstractString</code>, returning a <code>SubString</code>.</p></div></div><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [1 2; 3 4]
2×2 Matrix{Int64}:
1 2
3 4
julia> b = view(A, :, 1)
2-element view(::Matrix{Int64}, :, 1) with eltype Int64:
1
3
julia> fill!(b, 0)
2-element view(::Matrix{Int64}, :, 1) with eltype Int64:
0
0
julia> A # Note A has changed even though we modified b
2×2 Matrix{Int64}:
0 2
0 4
julia> view(2:5, 2:3) # returns a range as type is immutable
3:4</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/subarray.jl#L128-L173">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.@view" href="#Base.@view"><code>Base.@view</code></a> — <span class="docstring-category">Macro</span></header><section><div><pre><code class="language-julia">@view A[inds...]</code></pre><p>Transform the indexing expression <code>A[inds...]</code> into the equivalent <a href="#Base.view"><code>view</code></a> call.</p><p>This can only be applied directly to a single indexing expression and is particularly helpful for expressions that include the special <code>begin</code> or <code>end</code> indexing syntaxes like <code>A[begin, 2:end-1]</code> (as those are not supported by the normal <a href="#Base.view"><code>view</code></a> function).</p><p>Note that <code>@view</code> cannot be used as the target of a regular assignment (e.g., <code>@view(A[1, 2:end]) = ...</code>), nor would the un-decorated <a href="../../manual/arrays/#man-indexed-assignment">indexed assignment</a> (<code>A[1, 2:end] = ...</code>) or broadcasted indexed assignment (<code>A[1, 2:end] .= ...</code>) make a copy. It can be useful, however, for <em>updating</em> broadcasted assignments like <code>@view(A[1, 2:end]) .+= 1</code> because this is a simple syntax for <code>@view(A[1, 2:end]) .= @view(A[1, 2:end]) + 1</code>, and the indexing expression on the right-hand side would otherwise make a copy without the <code>@view</code>.</p><p>See also <a href="#Base.@views"><code>@views</code></a> to switch an entire block of code to use views for non-scalar indexing.</p><div class="admonition is-compat"><header class="admonition-header">Julia 1.5</header><div class="admonition-body"><p>Using <code>begin</code> in an indexing expression to refer to the first index requires at least Julia 1.5.</p></div></div><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [1 2; 3 4]
2×2 Matrix{Int64}:
1 2
3 4
julia> b = @view A[:, 1]
2-element view(::Matrix{Int64}, :, 1) with eltype Int64:
1
3
julia> fill!(b, 0)
2-element view(::Matrix{Int64}, :, 1) with eltype Int64:
0
0
julia> A
2×2 Matrix{Int64}:
0 2
0 4</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/views.jl#L77-L124">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.@views" href="#Base.@views"><code>Base.@views</code></a> — <span class="docstring-category">Macro</span></header><section><div><pre><code class="language-julia">@views expression</code></pre><p>Convert every array-slicing operation in the given expression (which may be a <code>begin</code>/<code>end</code> block, loop, function, etc.) to return a view. Scalar indices, non-array types, and explicit <a href="../collections/#Base.getindex"><code>getindex</code></a> calls (as opposed to <code>array[...]</code>) are unaffected.</p><div class="admonition is-info"><header class="admonition-header">Note</header><div class="admonition-body"><p>The <code>@views</code> macro only affects <code>array[...]</code> expressions that appear explicitly in the given <code>expression</code>, not array slicing that occurs in functions called by that code.</p></div></div><div class="admonition is-compat"><header class="admonition-header">Julia 1.5</header><div class="admonition-body"><p>Using <code>begin</code> in an indexing expression to refer to the first index requires at least Julia 1.5.</p></div></div><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = zeros(3, 3);
julia> @views for row in 1:3
b = A[row, :]
b[:] .= row
end
julia> A
3×3 Matrix{Float64}:
1.0 1.0 1.0
2.0 2.0 2.0
3.0 3.0 3.0</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/views.jl#L208-L241">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.parent" href="#Base.parent"><code>Base.parent</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">parent(A)</code></pre><p>Return the underlying "parent array”. This parent array of objects of types <code>SubArray</code>, <code>ReshapedArray</code> or <code>LinearAlgebra.Transpose</code> is what was passed as an argument to <code>view</code>, <code>reshape</code>, <code>transpose</code>, etc. during object creation. If the input is not a wrapped object, return the input itself. If the input is wrapped multiple times, only the outermost wrapper will be removed.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [1 2; 3 4]
2×2 Matrix{Int64}:
1 2
3 4
julia> V = view(A, 1:2, :)
2×2 view(::Matrix{Int64}, 1:2, :) with eltype Int64:
1 2
3 4
julia> parent(V)
2×2 Matrix{Int64}:
1 2
3 4</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L1383-L1408">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.parentindices" href="#Base.parentindices"><code>Base.parentindices</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">parentindices(A)</code></pre><p>Return the indices in the <a href="#Base.parent"><code>parent</code></a> which correspond to the array view <code>A</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [1 2; 3 4];
julia> V = view(A, 1, :)
2-element view(::Matrix{Int64}, 1, :) with eltype Int64:
1
2
julia> parentindices(V)
(1, Base.Slice(Base.OneTo(2)))</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/subarray.jl#L81-L98">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.selectdim" href="#Base.selectdim"><code>Base.selectdim</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">selectdim(A, d::Integer, i)</code></pre><p>Return a view of all the data of <code>A</code> where the index for dimension <code>d</code> equals <code>i</code>.</p><p>Equivalent to <code>view(A,:,:,...,i,:,:,...)</code> where <code>i</code> is in position <code>d</code>.</p><p>See also: <a href="#Base.eachslice"><code>eachslice</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [1 2 3 4; 5 6 7 8]
2×4 Matrix{Int64}:
1 2 3 4
5 6 7 8
julia> selectdim(A, 2, 3)
2-element view(::Matrix{Int64}, :, 3) with eltype Int64:
3
7
julia> selectdim(A, 2, 3:4)
2×2 view(::Matrix{Int64}, :, 3:4) with eltype Int64:
3 4
7 8</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarraymath.jl#L225-L251">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.reinterpret" href="#Base.reinterpret"><code>Base.reinterpret</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">reinterpret(type, A)</code></pre><p>Change the type-interpretation of a block of memory. For arrays, this constructs a view of the array with the same binary data as the given array, but with the specified element type. For example, <code>reinterpret(Float32, UInt32(7))</code> interprets the 4 bytes corresponding to <code>UInt32(7)</code> as a <a href="../numbers/#Core.Float32"><code>Float32</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> reinterpret(Float32, UInt32(7))
1.0f-44
julia> reinterpret(Float32, UInt32[1 2 3 4 5])
1×5 reinterpret(Float32, ::Matrix{UInt32}):
1.0f-45 3.0f-45 4.0f-45 6.0f-45 7.0f-45</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/essentials.jl#L418-L437">source</a></section><section><div><pre><code class="language-none">reinterpret(reshape, T, A::AbstractArray{S}) -> B</code></pre><p>Change the type-interpretation of <code>A</code> while consuming or adding a "channel dimension."</p><p>If <code>sizeof(T) = n*sizeof(S)</code> for <code>n>1</code>, <code>A</code>'s first dimension must be of size <code>n</code> and <code>B</code> lacks <code>A</code>'s first dimension. Conversely, if <code>sizeof(S) = n*sizeof(T)</code> for <code>n>1</code>, <code>B</code> gets a new first dimension of size <code>n</code>. The dimensionality is unchanged if <code>sizeof(T) == sizeof(S)</code>.</p><div class="admonition is-compat"><header class="admonition-header">Julia 1.6</header><div class="admonition-body"><p>This method requires at least Julia 1.6.</p></div></div><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [1 2; 3 4]
2×2 Matrix{Int64}:
1 2
3 4
julia> reinterpret(reshape, Complex{Int}, A) # the result is a vector
2-element reinterpret(reshape, Complex{Int64}, ::Matrix{Int64}) with eltype Complex{Int64}:
1 + 3im
2 + 4im
julia> a = [(1,2,3), (4,5,6)]
2-element Vector{Tuple{Int64, Int64, Int64}}:
(1, 2, 3)
(4, 5, 6)
julia> reinterpret(reshape, Int, a) # the result is a matrix
3×2 reinterpret(reshape, Int64, ::Vector{Tuple{Int64, Int64, Int64}}) with eltype Int64:
1 4
2 5
3 6</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/reinterpretarray.jl#L98-L134">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.reshape" href="#Base.reshape"><code>Base.reshape</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">reshape(A, dims...) -> AbstractArray
reshape(A, dims) -> AbstractArray</code></pre><p>Return an array with the same data as <code>A</code>, but with different dimension sizes or number of dimensions. The two arrays share the same underlying data, so that the result is mutable if and only if <code>A</code> is mutable, and setting elements of one alters the values of the other.</p><p>The new dimensions may be specified either as a list of arguments or as a shape tuple. At most one dimension may be specified with a <code>:</code>, in which case its length is computed such that its product with all the specified dimensions is equal to the length of the original array <code>A</code>. The total number of elements must not change.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = Vector(1:16)
16-element Vector{Int64}:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
julia> reshape(A, (4, 4))
4×4 Matrix{Int64}:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
julia> reshape(A, 2, :)
2×8 Matrix{Int64}:
1 3 5 7 9 11 13 15
2 4 6 8 10 12 14 16
julia> reshape(1:6, 2, 3)
2×3 reshape(::UnitRange{Int64}, 2, 3) with eltype Int64:
1 3 5
2 4 6</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/reshapedarray.jl#L54-L107">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.dropdims" href="#Base.dropdims"><code>Base.dropdims</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">dropdims(A; dims)</code></pre><p>Return an array with the same data as <code>A</code>, but with the dimensions specified by <code>dims</code> removed. <code>size(A,d)</code> must equal 1 for every <code>d</code> in <code>dims</code>, and repeated dimensions or numbers outside <code>1:ndims(A)</code> are forbidden.</p><p>The result shares the same underlying data as <code>A</code>, such that the result is mutable if and only if <code>A</code> is mutable, and setting elements of one alters the values of the other.</p><p>See also: <a href="#Base.reshape"><code>reshape</code></a>, <a href="#Base.vec"><code>vec</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> a = reshape(Vector(1:4),(2,2,1,1))
2×2×1×1 Array{Int64, 4}:
[:, :, 1, 1] =
1 3
2 4
julia> b = dropdims(a; dims=3)
2×2×1 Array{Int64, 3}:
[:, :, 1] =
1 3
2 4
julia> b[1,1,1] = 5; a
2×2×1×1 Array{Int64, 4}:
[:, :, 1, 1] =
5 3
2 4</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarraymath.jl#L48-L81">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.vec" href="#Base.vec"><code>Base.vec</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">vec(a::AbstractArray) -> AbstractVector</code></pre><p>Reshape the array <code>a</code> as a one-dimensional column vector. Return <code>a</code> if it is already an <code>AbstractVector</code>. The resulting array shares the same underlying data as <code>a</code>, so it will only be mutable if <code>a</code> is mutable, in which case modifying one will also modify the other.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> a = [1 2 3; 4 5 6]
2×3 Matrix{Int64}:
1 2 3
4 5 6
julia> vec(a)
6-element Vector{Int64}:
1
4
2
5
3
6
julia> vec(1:3)
1:3</code></pre><p>See also <a href="#Base.reshape"><code>reshape</code></a>, <a href="#Base.dropdims"><code>dropdims</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarraymath.jl#L11-L40">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.SubArray" href="#Base.SubArray"><code>Base.SubArray</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia">SubArray{T,N,P,I,L} <: AbstractArray{T,N}</code></pre><p><code>N</code>-dimensional view into a parent array (of type <code>P</code>) with an element type <code>T</code>, restricted by a tuple of indices (of type <code>I</code>). <code>L</code> is true for types that support fast linear indexing, and <code>false</code> otherwise.</p><p>Construct <code>SubArray</code>s using the <a href="#Base.view"><code>view</code></a> function.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/subarray.jl#L7-L13">source</a></section></article><h2 id="拼接与排列"><a class="docs-heading-anchor" href="#拼接与排列">拼接与排列</a><a id="拼接与排列-1"></a><a class="docs-heading-anchor-permalink" href="#拼接与排列" title="Permalink"></a></h2><article class="docstring"><header><a class="docstring-binding" id="Base.cat" href="#Base.cat"><code>Base.cat</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">cat(A...; dims)</code></pre><p>Concatenate the input arrays along the specified dimensions in the iterable <code>dims</code>. For dimensions not in <code>dims</code>, all input arrays should have the same size, which will also be the size of the output array along that dimension. For dimensions in <code>dims</code>, the size of the output array is the sum of the sizes of the input arrays along that dimension. If <code>dims</code> is a single number, the different arrays are tightly stacked along that dimension. If <code>dims</code> is an iterable containing several dimensions, this allows one to construct block diagonal matrices and their higher-dimensional analogues by simultaneously increasing several dimensions for every new input array and putting zero blocks elsewhere. For example, <code>cat(matrices...; dims=(1,2))</code> builds a block diagonal matrix, i.e. a block matrix with <code>matrices[1]</code>, <code>matrices[2]</code>, ... as diagonal blocks and matching zero blocks away from the diagonal.</p><p>See also <a href="#Base.hcat"><code>hcat</code></a>, <a href="#Base.vcat"><code>vcat</code></a>, <a href="#Base.hvcat"><code>hvcat</code></a>, <a href="#Base.repeat"><code>repeat</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> cat([1 2; 3 4], [pi, pi], fill(10, 2,3,1); dims=2)
2×6×1 Array{Float64, 3}:
[:, :, 1] =
1.0 2.0 3.14159 10.0 10.0 10.0
3.0 4.0 3.14159 10.0 10.0 10.0
julia> cat(true, trues(2,2), trues(4)', dims=(1,2))
4×7 Matrix{Bool}:
1 0 0 0 0 0 0
0 1 1 0 0 0 0
0 1 1 0 0 0 0
0 0 0 1 1 1 1</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L1883-L1915">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.vcat" href="#Base.vcat"><code>Base.vcat</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">vcat(A...)</code></pre><p>Concatenate along dimension 1. To efficiently concatenate a large vector of arrays, use <code>reduce(vcat, x)</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> a = [1 2 3 4 5]
1×5 Matrix{Int64}:
1 2 3 4 5
julia> b = [6 7 8 9 10; 11 12 13 14 15]
2×5 Matrix{Int64}:
6 7 8 9 10
11 12 13 14 15
julia> vcat(a,b)
3×5 Matrix{Int64}:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
julia> c = ([1 2 3], [4 5 6])
([1 2 3], [4 5 6])
julia> vcat(c...)
2×3 Matrix{Int64}:
1 2 3
4 5 6
julia> vs = [[1, 2], [3, 4], [5, 6]]
3-element Vector{Vector{Int64}}:
[1, 2]
[3, 4]
[5, 6]
julia> reduce(vcat, vs)
6-element Vector{Int64}:
1
2
3
4
5
6</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L1768-L1814">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.hcat" href="#Base.hcat"><code>Base.hcat</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">hcat(A...)</code></pre><p>Concatenate along dimension 2. To efficiently concatenate a large vector of arrays, use <code>reduce(hcat, x)</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> a = [1; 2; 3; 4; 5]
5-element Vector{Int64}:
1
2
3
4
5
julia> b = [6 7; 8 9; 10 11; 12 13; 14 15]
5×2 Matrix{Int64}:
6 7
8 9
10 11
12 13
14 15
julia> hcat(a,b)
5×3 Matrix{Int64}:
1 6 7
2 8 9
3 10 11
4 12 13
5 14 15
julia> c = ([1; 2; 3], [4; 5; 6])
([1, 2, 3], [4, 5, 6])
julia> hcat(c...)
3×2 Matrix{Int64}:
1 4
2 5
3 6
julia> x = Matrix(undef, 3, 0) # x = [] would have created an Array{Any, 1}, but need an Array{Any, 2}
3×0 Matrix{Any}
julia> hcat(x, [1; 2; 3])
3×1 Matrix{Any}:
1
2
3
julia> vs = [[1, 2], [3, 4], [5, 6]]
3-element Vector{Vector{Int64}}:
[1, 2]
[3, 4]
[5, 6]
julia> reduce(hcat, vs)
2×3 Matrix{Int64}:
1 3 5
2 4 6</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L1816-L1877">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.hvcat" href="#Base.hvcat"><code>Base.hvcat</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">hvcat(rows::Tuple{Vararg{Int}}, values...)</code></pre><p>Horizontal and vertical concatenation in one call. This function is called for block matrix syntax. The first argument specifies the number of arguments to concatenate in each block row.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> a, b, c, d, e, f = 1, 2, 3, 4, 5, 6
(1, 2, 3, 4, 5, 6)
julia> [a b c; d e f]
2×3 Matrix{Int64}:
1 2 3
4 5 6
julia> hvcat((3,3), a,b,c,d,e,f)
2×3 Matrix{Int64}:
1 2 3
4 5 6
julia> [a b; c d; e f]
3×2 Matrix{Int64}:
1 2
3 4
5 6
julia> hvcat((2,2,2), a,b,c,d,e,f)
3×2 Matrix{Int64}:
1 2
3 4
5 6</code></pre><p>If the first argument is a single integer <code>n</code>, then all block rows are assumed to have <code>n</code> block columns.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L1951-L1988">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.hvncat" href="#Base.hvncat"><code>Base.hvncat</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">hvncat(dim::Int, row_first, values...)
hvncat(dims::Tuple{Vararg{Int}}, row_first, values...)
hvncat(shape::Tuple{Vararg{Tuple}}, row_first, values...)</code></pre><p>Horizontal, vertical, and n-dimensional concatenation of many <code>values</code> in one call.</p><p>This function is called for block matrix syntax. The first argument either specifies the shape of the concatenation, similar to <code>hvcat</code>, as a tuple of tuples, or the dimensions that specify the key number of elements along each axis, and is used to determine the output dimensions. The <code>dims</code> form is more performant, and is used by default when the concatenation operation has the same number of elements along each axis (e.g., [a b; c d;;; e f ; g h]). The <code>shape</code> form is used when the number of elements along each axis is unbalanced (e.g., [a b ; c]). Unbalanced syntax needs additional validation overhead. The <code>dim</code> form is an optimization for concatenation along just one dimension. <code>row_first</code> indicates how <code>values</code> are ordered. The meaning of the first and second elements of <code>shape</code> are also swapped based on <code>row_first</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> a, b, c, d, e, f = 1, 2, 3, 4, 5, 6
(1, 2, 3, 4, 5, 6)
julia> [a b c;;; d e f]
1×3×2 Array{Int64, 3}:
[:, :, 1] =
1 2 3
[:, :, 2] =
4 5 6
julia> hvncat((2,1,3), false, a,b,c,d,e,f)
2×1×3 Array{Int64, 3}:
[:, :, 1] =
1
2
[:, :, 2] =
3
4
[:, :, 3] =
5
6
julia> [a b;;; c d;;; e f]
1×2×3 Array{Int64, 3}:
[:, :, 1] =
1 2
[:, :, 2] =
3 4
[:, :, 3] =
5 6
julia> hvncat(((3, 3), (3, 3), (6,)), true, a, b, c, d, e, f)
1×3×2 Array{Int64, 3}:
[:, :, 1] =
1 2 3
[:, :, 2] =
4 5 6</code></pre><p><strong>Examples for construction of the arguments:</strong></p><pre><code class="language-julia">[a b c ; d e f ;;;
g h i ; j k l ;;;
m n o ; p q r ;;;
s t u ; v w x]
=> dims = (2, 3, 4)
[a b ; c ;;; d ;;;;]
___ _ _
2 1 1 = elements in each row (2, 1, 1)
_______ _
3 1 = elements in each column (3, 1)
_____________
4 = elements in each 3d slice (4,)
_____________
4 = elements in each 4d slice (4,)
=> shape = ((2, 1, 1), (3, 1), (4,), (4,)) with `rowfirst` = true</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L2102-L2187">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.vect" href="#Base.vect"><code>Base.vect</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">vect(X...)</code></pre><p>Create a <a href="#Base.Vector"><code>Vector</code></a> with element type computed from the <code>promote_typeof</code> of the argument, containing the argument list.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> a = Base.vect(UInt8(1), 2.5, 1//2)
3-element Vector{Float64}:
1.0
2.5
0.5</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L128-L142">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.circshift" href="#Base.circshift"><code>Base.circshift</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">circshift(A, shifts)</code></pre><p>Circularly shift, i.e. rotate, the data in an array. The second argument is a tuple or vector giving the amount to shift in each dimension, or an integer to shift only in the first dimension.</p><p>See also: <a href="#Base.circshift!"><code>circshift!</code></a>, <a href="#Base.circcopy!"><code>circcopy!</code></a>, <a href="../math/#Base.bitrotate"><code>bitrotate</code></a>, <a href="../math/#Base.:<<"><code><<</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> b = reshape(Vector(1:16), (4,4))
4×4 Matrix{Int64}:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
julia> circshift(b, (0,2))
4×4 Matrix{Int64}:
9 13 1 5
10 14 2 6
11 15 3 7
12 16 4 8
julia> circshift(b, (-1,0))
4×4 Matrix{Int64}:
2 6 10 14
3 7 11 15
4 8 12 16
1 5 9 13
julia> a = BitArray([true, true, false, false, true])
5-element BitVector:
1
1
0
0
1
julia> circshift(a, 1)
5-element BitVector:
1
1
1
0
0
julia> circshift(a, -1)
5-element BitVector:
1
0
0
1
1</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarraymath.jl#L264-L320">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.circshift!" href="#Base.circshift!"><code>Base.circshift!</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">circshift!(dest, src, shifts)</code></pre><p>Circularly shift, i.e. rotate, the data in <code>src</code>, storing the result in <code>dest</code>. <code>shifts</code> specifies the amount to shift in each dimension.</p><p>The <code>dest</code> array must be distinct from the <code>src</code> array (they cannot alias each other).</p><p>See also <a href="#Base.circshift"><code>circshift</code></a>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/multidimensional.jl#L1162-L1172">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.circcopy!" href="#Base.circcopy!"><code>Base.circcopy!</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">circcopy!(dest, src)</code></pre><p>Copy <code>src</code> to <code>dest</code>, indexing each dimension modulo its length. <code>src</code> and <code>dest</code> must have the same size, but can be offset in their indices; any offset results in a (circular) wraparound. If the arrays have overlapping indices, then on the domain of the overlap <code>dest</code> agrees with <code>src</code>.</p><p>See also: <a href="#Base.circshift"><code>circshift</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> src = reshape(Vector(1:16), (4,4))
4×4 Array{Int64,2}:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
julia> dest = OffsetArray{Int}(undef, (0:3,2:5))
julia> circcopy!(dest, src)
OffsetArrays.OffsetArray{Int64,2,Array{Int64,2}} with indices 0:3×2:5:
8 12 16 4
5 9 13 1
6 10 14 2
7 11 15 3
julia> dest[1:3,2:4] == src[1:3,2:4]
true</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/multidimensional.jl#L1218-L1250">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.findall-Tuple{Any}" href="#Base.findall-Tuple{Any}"><code>Base.findall</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">findall(A)</code></pre><p>Return a vector <code>I</code> of the <code>true</code> indices or keys of <code>A</code>. If there are no such elements of <code>A</code>, return an empty array. To search for other kinds of values, pass a predicate as the first argument.</p><p>Indices or keys are of the same type as those returned by <a href="#Base.keys-Tuple{AbstractArray}"><code>keys(A)</code></a> and <a href="../collections/#Base.pairs"><code>pairs(A)</code></a>.</p><p>See also: <a href="#Base.findfirst-Tuple{Any}"><code>findfirst</code></a>, <a href="../sort/#Base.Sort.searchsorted"><code>searchsorted</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> A = [true, false, false, true]
4-element Vector{Bool}:
1
0
0
1
julia> findall(A)
2-element Vector{Int64}:
1
4
julia> A = [true false; false true]
2×2 Matrix{Bool}:
1 0
0 1
julia> findall(A)
2-element Vector{CartesianIndex{2}}:
CartesianIndex(1, 1)
CartesianIndex(2, 2)
julia> findall(falses(3))
Int64[]</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/array.jl#L2313-L2352">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Base.findall-Tuple{Function, Any}" href="#Base.findall-Tuple{Function, Any}"><code>Base.findall</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia">findall(f::Function, A)</code></pre><p>Return a vector <code>I</code> of the indices or keys of <code>A</code> where <code>f(A[I])</code> returns <code>true</code>. If there are no such elements of <code>A</code>, return an empty array.</p><p>Indices or keys are of the same type as those returned by <a href="#Base.keys-Tuple{AbstractArray}"><code>keys(A)</code></a> and <a href="../collections/#Base.pairs"><code>pairs(A)</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl">julia> x = [1, 3, 4]
3-element Vector{Int64}:
1
3
4
julia> findall(isodd, x)
2-element Vector{Int64}:
1
2
julia> A = [1 2 0; 3 4 0]
2×3 Matrix{Int64}:
1 2 0
3 4 0
julia> findall(isodd, A)
2-element Vector{CartesianIndex{2}}:
CartesianIndex(1, 1)
CartesianIndex(2, 1)
julia> findall(!iszero, A)
4-element Vector{CartesianIndex{2}}:
CartesianIndex(1, 1)
CartesianIndex(2, 1)
CartesianIndex(1, 2)
CartesianIndex(2, 2)
julia> d = Dict(:A => 10, :B => -1, :C => 0)
Dict{Symbol, Int64} with 3 entries:
:A => 10
:B => -1
:C => 0
julia> findall(x -> x >= 0, d)