# Difference Between Scalar, Vector, Matrix and Tensor

## Scalar

A scalar is just a single number

## Vector

A vector is an array of numbers. One-dimensional array of numbers.

numpy.array(object, dtype=None, *, copy=True, order='K', subok=False, ndmin=0, like=None)

Create an array.
In :
import numpy as np
vector1 = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
vector1

Out:
array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10])

### Dimension of vector1

In :
vector1.ndim

Out:
1

### Shape of vector1

In :
vector1.shape

Out:
(10,)

The value is 10.

## Matrix

A matrix is a 2-D array of numbers, so each element is identiﬁed by two indices instead of just one.

### 2x2 matrix

In :
matrix1 = np.array([
[1, 2],
[3, 4]
])
matrix1

Out:
array([[1, 2],
[3, 4]])
In :
matrix1.shape

Out:
(2, 2)
In :
matrix1.ndim

Out:
2

### 4x3 matrix

In :
matrix2 = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]
])
matrix2

Out:
array([[ 1,  2,  3],
[ 4,  5,  6],
[ 7,  8,  9],
[10, 11, 12]])
In :
matrix2.shape

Out:
(4, 3)
In :
matrix2.ndim

Out:
2

Another way we can create a matrix is by using the matrix function.

class numpy.matrix(data, dtype=None, copy=True)

Returns a matrix from an array-like object, or from a string of data. A matrix is a specialized 2-D array that retains its 2-D nature through operations.

Parameters

dataarray_like or string

If data is a string, it is interpreted as a matrix with commas or spaces separating columns, and semicolons separating rows.
dtypedata-type

Data-type of the output matrix.
copybool

If data is already an ndarray, then this flag determines whether the data is copied (the default), or whether a view is constructed.
In :
matrix3 = np.matrix([
[1, 2],
[3, 4]
])
matrix3

Out:
matrix([[1, 2],
[3, 4]])
In :
matrix3.shape

Out:
(2, 2)
In :
matrix3.ndim

Out:
2

## Tensor

An array with more than two axes is called tensor. We can create 3-dimensional array, or tensor, by numpy array function.

In :
tensor1 = np.array([
[
[1, 2, 3],
[4, 5, 6]
],
[
[7, 8, 9],
[10, 11, 12]

]
])
tensor1

Out:
array([[[ 1,  2,  3],
[ 4,  5,  6]],

[[ 7,  8,  9],
[10, 11, 12]]])
In :
tensor1.shape

Out:
(2, 2, 3)
In :
tensor1.ndim

Out:
3
In [ ]:


In [ ]: