You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
# shift
22
+
23
+
> Return an array containing a truncated view of an input ndarray and a view of the first element(s) along a specified dimension.
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
+
<sectionclass="intro">
28
+
29
+
</section>
30
+
31
+
<!-- /.intro -->
32
+
33
+
<!-- Package usage documentation. -->
34
+
35
+
<sectionclass="usage">
36
+
37
+
## Usage
38
+
39
+
```javascript
40
+
var shift =require( '@stdlib/ndarray/base/shift' );
41
+
```
42
+
43
+
#### shift( x, dim, writable )
44
+
45
+
Returns an array containing a truncated view of an input ndarray and a view of the first element(s) along a specified dimension.
46
+
47
+
```javascript
48
+
var ndarray =require( '@stdlib/ndarray/ctor' );
49
+
var getShape =require( '@stdlib/ndarray/shape' );
50
+
var ndarray2array =require( '@stdlib/ndarray/to-array' );
51
+
52
+
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
53
+
var shape = [ 3, 2 ];
54
+
var strides = [ 2, 1 ];
55
+
var offset =0;
56
+
57
+
var x =ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
-**dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`.
80
+
-**writable**: boolean indicating whether a returned ndarray should be writable.
81
+
82
+
</section>
83
+
84
+
<!-- /.usage -->
85
+
86
+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
87
+
88
+
<sectionclass="notes">
89
+
90
+
## Notes
91
+
92
+
- The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.
93
+
94
+
</section>
95
+
96
+
<!-- /.notes -->
97
+
98
+
<!-- Package usage examples. -->
99
+
100
+
<sectionclass="examples">
101
+
102
+
## Examples
103
+
104
+
<!-- eslint no-undef: "error" -->
105
+
106
+
```javascript
107
+
var array =require( '@stdlib/ndarray/array' );
108
+
var ndarray2array =require( '@stdlib/ndarray/to-array' );
109
+
var zeroTo =require( '@stdlib/array/base/zero-to' );
110
+
var shift =require( '@stdlib/ndarray/base/shift' );
111
+
112
+
// Create a linear ndarray buffer:
113
+
var buf =zeroTo( 27 );
114
+
115
+
// Create an ndarray which is a stack of three 3x3 matrices:
116
+
var x =array( buf, {
117
+
'shape': [ 3, 3, 3 ]
118
+
});
119
+
120
+
// Remove the first row from each matrix:
121
+
var y =shift( x, 1, false );
122
+
// returns [ <ndarray>, <ndarray> ]
123
+
124
+
console.log( ndarray2array( y[ 0 ] ) );
125
+
console.log( ndarray2array( y[ 1 ] ) );
126
+
```
127
+
128
+
</section>
129
+
130
+
<!-- /.examples -->
131
+
132
+
<!-- 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. -->
133
+
134
+
<sectionclass="references">
135
+
136
+
</section>
137
+
138
+
<!-- /.references -->
139
+
140
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
141
+
142
+
<sectionclass="related">
143
+
144
+
</section>
145
+
146
+
<!-- /.related -->
147
+
148
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
0 commit comments