Tuesday 20 February 2024

shape of a NumPy array

The shape of a NumPy array refers to the number of elements along each of its dimensions. In simpler terms, it specifies how many rows and columns a two-dimensional array has, or how many rows, columns, and depth a three-dimensional array has, and so on.

For example, consider a 2D array representing a table of values:

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

This array has 3 rows (each containing 3 elements) and 3 columns, and its shape is therefore (3, 3).

Understanding array shapes is crucial in NumPy operations, as many functions and operations work on arrays of specific shapes.

How to find shape of the array in Python?


 To find the shape of the array, we use "shape" along with array name. In the above example, the array shape is 2x4, that means 2 rows and 4 columns.

We can also create an array with required dimensions as follows using "ndmin" as follows


As you can see, in the above output, the 5 dimension are displayed in [ ] brackets and also the shapes are displayed.

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top