README.md (3565B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Array Shape 22 23 > Determine (nested) array dimensions. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var arrayShape = require( '@stdlib/array/shape' ); 41 ``` 42 43 #### arrayShape( arr ) 44 45 Returns array dimensions. 46 47 ```javascript 48 var arr = [ 49 [ 1, 2, 3 ], 50 [ 4, 5, 6 ], 51 [ 7, 8, 9 ] 52 ]; 53 54 var shape = arrayShape( arr ); 55 // returns [ 3, 3 ] 56 ``` 57 58 The function **ignores** inconsistent dimensions. 59 60 ```javascript 61 var arr = [ 62 [ 1, 2, 3 ], 63 [ 4, 5, 6 ], 64 [ 7, 8 ] 65 ]; 66 67 var shape = arrayShape( arr ); 68 // returns [ 3 ] 69 ``` 70 71 </section> 72 73 <!-- /.usage --> 74 75 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 76 77 <section class="notes"> 78 79 </section> 80 81 <!-- /.notes --> 82 83 <!-- Package usage examples. --> 84 85 <section class="examples"> 86 87 ## Examples 88 89 <!-- eslint no-undef: "error" --> 90 91 ```javascript 92 var arrayShape = require( '@stdlib/array/shape' ); 93 94 var shape; 95 var arr; 96 97 arr = [ 1, 2, 3 ]; 98 shape = arrayShape( arr ); 99 // returns [ 3 ] 100 101 arr = [ 102 [ 1 ], 103 [ 2 ], 104 [ 3 ] 105 ]; 106 shape = arrayShape( arr ); 107 // returns [ 3, 1 ] 108 109 arr = [ 110 [], 111 [], 112 [] 113 ]; 114 shape = arrayShape( arr ); 115 // returns [ 3, 0 ] 116 117 arr = [ 118 [ 1, 2, 3 ] 119 ]; 120 shape = arrayShape( arr ); 121 // returns [ 1, 3 ] 122 123 arr = [ 124 [ [ 1 ] ], 125 [ [ 2 ] ], 126 [ [ 3 ] ] 127 ]; 128 shape = arrayShape( arr ); 129 // returns [ 3, 1, 1 ] 130 131 arr = [ [ [ [ 1, 2, 3 ] ] ] ]; 132 shape = arrayShape( arr ); 133 // returns [ 1, 1, 1, 3 ] 134 135 arr = [ 136 [ 1, 2 ], 137 [ 3, 4 ] 138 ]; 139 shape = arrayShape( arr ); 140 // returns [ 2, 2 ] 141 142 arr = [ 143 [ 1, 2, 3 ], 144 [ 4, 5, 6 ], 145 [ 7, 8, 9 ] 146 ]; 147 shape = arrayShape( arr ); 148 // returns [ 3, 3 ] 149 150 arr = [ 151 [ 1, 2, 3 ], 152 null, 153 [ 7, 8, 9 ] 154 ]; 155 shape = arrayShape( arr ); 156 // returns [ 3 ] 157 158 arr = [ 159 [ 1, 2, 3 ], 160 [ [ 4, 5, 6 ] ], 161 [ [ 7, 8, 9 ] ] 162 ]; 163 shape = arrayShape( arr ); 164 // returns [ 3 ] 165 166 arr = [ 167 [ [ 1, 2, 3 ] ], 168 [ 4, 5, 6 ], 169 [ [ 7, 8, 9 ] ] 170 ]; 171 shape = arrayShape( arr ); 172 // returns [ 3 ] 173 174 arr = [ 175 [ [ 1, 2, 3 ] ], 176 [ [ 4, 5, 6 ] ], 177 [ 7, 8, 9 ] 178 ]; 179 shape = arrayShape( arr ); 180 // returns [ 3 ] 181 182 arr = [ 183 [ [ [ 1, 2, 3 ] ] ], 184 [ [ 4, 5, 6 ] ], 185 [ [ [ 7, 8, 9 ] ] ] 186 ]; 187 shape = arrayShape( arr ); 188 // returns [ 3, 1 ] 189 ``` 190 191 </section> 192 193 <!-- /.examples --> 194 195 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 196 197 <section class="references"> 198 199 </section> 200 201 <!-- /.references --> 202 203 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 204 205 <section class="links"> 206 207 </section> 208 209 <!-- /.links -->