![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does .shape[] do in “for i in range(Y.shape[0])” using Matplotlib?
The shape property is usually used to get the current shape of an array, but it may also be used to reshape the array in-place by assigning a tuple of array dimensions to it.
Steps
Get an array Y using np.array method.
Y.shape would return a tuple (4, ).
Y.shape[0] method would return 4, i.e., the first element of the tuple.
Example
import numpy as np Y = np.array([1, 2, 3, 4]) print("Output of .show method would be: ", Y.shape, " for ", Y) print("Output of .show[0] method would be: ", Y.shape[0], " for ", Y) print("Output for i in range(Y.shape[0]): ", end=" ") for i in range(Y.shape[0]): print(Y[i], end=" ")
Output
Output of .show method would be: (4,) for [1 2 3 4] Output of .show[0] method would be: 4 for [1 2 3 4] Output for i in range(Y.shape[0]): 1 2 3 4
Advertisements