Pythondex
Python Programs

NxNxN Matrix Python 3 Program

Last updated June 8, 2023 by Jarvis Silva

Looking for what is NXNXN Matrix then you are at the right place today I will show you what is NXNXN Matrix python program and how to create it.

In computer science, a matrix is a multidimensional array of numbers which are arranged in rows and columns. The numbers in the matrix represent data which are used to solve complicated calculations.

What is the NxNxN Matrix in Python?

The NXNXN Matrix simply means N by N by N, also known as the cube matrix. The value of N should be the same in all 3 N, for example 4x4x4 or 9x9x9.

In python, a NxNxN matrix is just a list of lists. It is very easy to create a NxNxN Matrix in python 3 programming, Now let’s see it in code.

Create a NxNxN Matrix In Python


import numpy as np
x =  np.arange(0, 9).reshape(3,3)
print(x)

Above is the python code to create the NxNxN matrix in python. We have used the numpy library to create the NxNxN matrix. If you don’t have numpy library installed, use the below command.


pip install numpy

Paste the above command in the command prompt or your project terminal to install the numpy library, when you run this program you will see the below output.


[[0,1,2]
 [3,4,5]
 [6,7,8]]

You can run it on your computer or use an online python compiler to test, it should give you a list of 3 rows and 3 columns.

So this was a short tutorial on what a nxnxn matrix is and how to create it, I hope you found this tutorial helpful and useful.

Here are more python guides that may interest you:

I hope you found what you were looking for from this tutorial and if you want more python tutorials like this in the future then do join our Telegram channel.

Thanks for reading, have a nice day 🙂