

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
- Related Questions & Answers
- What does “javascript:void(0)” mean?
- What does a “set+0” in a MySQL statement do?
- What does the “yield” keyword do in Python?
- How do I index “or” in MongoDB for indexing multiple fields?
- How does “do something OR DIE()” work in Perl?
- What does axes.flat in Matplotlib do?
- Which one is better to use for a JavaScript link, “#” or “javascript:void(0)”?
- What does “use strict” do in JavaScript, and what is the reasoning behind it?
- How do I programmatically “restart” an Android app?
- How do I programmatically “restart” an iOS app?
- What does “?:” mean in a Python regular expression?
- How do I replace “+”(plus sign) with SPACE in MySQL?
- What does “dereferencing” a pointer mean in C/C++?
- How do I use the ternary operator ( ? : ) in PHP as a shorthand for “if / else”?
- How do I kill all the processes in MySQL “show processlist”?
Advertisements