shape

Syntax

shape(X)

Details

Returns the dimension of a scalar/vector/matrix as a PAIR.

Note:

DolphinDB shape provides the same core functionality as numpy.shape. The differences are as follows:

  • DolphinDB shape returns a dimension pair in the form rows:columns to describe an object. It returns1:1for a scalar, length:1 for a vector, and rows:columns for a matrix or table.
  • numpy.shape returns a tuple that gives the length of each array dimension. It returns () for a scalar, (n,) for a one-dimensional array, and (m, n) for a two-dimensional array.

Parameters

X is a scalar/vector/matrix/table.

Examples

Dimension of a scalar is 1 by 1:

shape 6;
// output: 1:1

s;

Dimension of a vector is the length of the vector by 1:

shape 1 5 3 7 8;
// output: 5:1

Dimension of a matrix:

m=(5 3 1 4 9 10)$3:2;
m;
#0 #1
5 4
3 9
1 10
shape m;
// output: 3 :2

Dimension of a table:

t=table(1 2 3 as x, 4 5 6 as y);
t;
x y
1 4
2 5
3 6
shape t;
// output: 3 :2