Do you know how to create the NXNXN Matrix Python 3 Program? In this article, I’m going to explain the full details about nxnxn matrix and how to create the NXNXN matrix in python 3.
A matrix is nothing more than a set of numbers arranged in rows and columns into a rectangular arrangement. These numbers are called the elements, or entries, of the matrix.
For example, We have a m x n matrix, that’s because the number of rows here is equal to m and the number of columns is equal to n.
What is NxNxN Matrix?
The term NxNxN (pronounced as N by N by N) is also called NxNxN cube or NxNxN puzzle. It represents the cube with the same dimensions which means the cube will have the same height, width, and length.
For example, N=4 then 4x4x4. Hope you got the point.
NXNXN Matrix Python 3 Program using Numpy
import numpy as np
x = np.arange(2, 11).reshape(3,3)
In this program, We can use the NumPy package to create NXNXN Matrix. We have to assign the variable as “x” that will store the data. After that, We have to arrange the range of values between greater than or equal to 2 and less than 11. The reshaping values are (3,3) which means the output of the matrix is 3 x 3.
Lastly, the print() function is used to print the results on the output screen, as shown below:
[[ 2 3 4]
[ 5 6 7]
[ 8 9 10]]
Create a Square Matrix in Python Program using For Loop
By using for Loop in Python 3 program, we can create a square matrix as follows:
R = int(input("Enter the number of rows:")) C = int(input("Enter the number of columns:")) # Initialize matrix matrix =  print("Enter the entries rowwise:") # For user input for i in range(R): # A for loop for row entries a = for j in range(C): # A for loop for column entries a.append(int(input())) matrix.append(a) # For printing the matrix for i in range(R): for j in range(C): print(matrix[i][j], end = " ") print()
Using the two input variables “R” and “C”, the for loop is used to analyze the range of the matrix and display the output.
I hope this article helps you to create NXNXN Matrix using the Python Program. I would appreciate your feedback via the comment section. Please share this article with other Python programmers via social networks. Thanks!