# How to make a matrix in python

To make a matrix in python we use the array function of the numpy library.

import numpy as np

np.array (x)

Where x is the matrix to be created.

The function defines a matrix or vector object.

**Example**

This is a 2x2 matrix

np.array ([[1,2], [3,4]])

The elements of the row are separated by commas.

The rows of the array are enclosed in square brackets [ ] and separated by commas.

All rows in the array are enclosed in square brackets [ ].

**Note**. The array function can create vectors, matrices with two dimensions (3x3) or more dimensions (eg 3x3x3).

**Other practical examples**

__Example 1 (3x2 matrix)__

This command makes a rectangular 3x2 matrix

array ([[1,2], [3,4], [5,6]])

__Example 2 (3x3 matrix)__

This command makes a 3x3 square matrix

Array ([[1,2,3], [4,5,6], [7,8,9]])

**Report an error or share a suggestion to enhance this page**