Difference between revisions of "Python-3.4.3/C2/Getting-started-with-arrays/English"
Line 102: | Line 102: | ||
− | Also notice that the object we passed to create an '''array '''is a '''list''' | + | Also notice that the object we passed to create an '''array '''is a '''list,''' i.e '''a1.''' |
Line 130: | Line 130: | ||
This is our 2-dimensional array. | This is our 2-dimensional array. | ||
+ | |||
'''<nowiki><<</nowiki>'''PAUSE>> | '''<nowiki><<</nowiki>'''PAUSE>> | ||
Line 144: | Line 145: | ||
− | The syntax is shown here | + | The syntax is shown here. |
− | + | ||
− | + | ||
|- | |- | ||
Line 167: | Line 166: | ||
It will give the elements one less than the stop value. | It will give the elements one less than the stop value. | ||
+ | |||
'''<nowiki><<</nowiki>'''PAUSE>> | '''<nowiki><<</nowiki>'''PAUSE>> | ||
Line 331: | Line 331: | ||
− | The syntax is '''identity | + | The syntax is '''identity '''''inside parentheses''' ''n.''' |
|- | |- | ||
Line 356: | Line 356: | ||
− | The Syntax is: '''zeros | + | The Syntax is: '''zeros '''''inside parentheses inside parentheses''' ''m, n''' |
|- | |- | ||
Line 490: | Line 490: | ||
# Perform some basic operations on '''arrays''' like addition and multiplication. | # Perform some basic operations on '''arrays''' like addition and multiplication. | ||
# Use methods like - | # Use methods like - | ||
− | + | ||
− | + | '''shapearange''' | |
− | + | ||
− | + | '''reshapeidentity '''and'''zeros''' | |
− | + | ||
|- | |- | ||
Line 505: | Line 504: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Here is a self assessment question for you to solve | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Here is a self assessment question for you to solve | ||
− | ''' | + | '''x '''''is equal to''''' np.array '''''inside parentheses inside square brackets''' ''1, 2, 3, '''''inside square brackets''' ''5, 6, 7''' is a valid statement ? |
− | + | *True | |
− | * True | + | *False |
− | * False | + | |
Line 526: | Line 524: | ||
− | That is ''' | + | That is '''x '''''is equal to''''' np.array '''''inside parentheses inside square brackets again inside square brackets '''''1, 2, 3, '''''inside square brackets '''''5, 6, 7''' |
|- | |- | ||
Line 534: | Line 532: | ||
|- | |- | ||
| style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Show Slide Fossee Forum | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Show Slide Fossee Forum | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Please post your general queries on Python in this forum. | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Please post your general queries on '''Python''' in this forum. |
|- | |- | ||
Line 545: | Line 543: | ||
Acknowledgment | Acknowledgment | ||
− | + | ||
+ | |||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India. | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India. | ||
Line 553: | Line 552: | ||
|- | |- | ||
| style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Previous slide | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Previous slide | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| This is Priya from IIT Bombay signing off. Thanks for | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| This is Priya from IIT Bombay signing off. Thanks for watching. |
|} | |} |
Revision as of 16:24, 4 May 2018
|
|
Show Slide | Welcome to the spoken tutorial on Getting started with arrays. |
Show Slide
Learning objectives
|
In this tutorial, you will learn to,
|
Show Slide
System Requirements |
To record this tutorial, I am using
|
Show Slide
Pre-requisite slide |
To practice this tutorial, you should know how to use Lists.
|
Show Slide
Overview of array |
Arrays are homogeneous data structures.
|
open the Terminal by pressing Ctrl+Alt+T keys simultaneously | In this tutorial, we will be using numpy library which we used in earlier tutorial.
|
type python3
Highlight ipython prompt |
Let us start ipython by typing ipython3 and press Enter.
|
Type, import numpy as np | Now we will import numpy.
|
Type, a1 = np.array([1,2,3,4])
|
Now let us see how to create arrays.
|
Type a1
|
Type, a1
|
Type
a2 = np.array([[1,2,3,4],[5,6,7,8]])
|
Next we will see how to create two dimensional array.
Type, a2 is equal to np dot array inside parentheses inside square brackets again inside square brackets 1 comma 2 comma 3 comma 4 comma inside square brackets 5 comma 6 comma 7 comma 8 |
Type a2
|
Type a2
|
slide : arange method
|
Next we will see about arange method.
|
Type, ar = np.arange(1,9) | Type, ar is equal to np dot arange inside parentheses 1 comma 9. |
type print (ar)
|
Type, print inside parentheses ar
|
Can we make a two dimensional array of order 2 by 4?
| |
slide reshape method
|
We will use reshape method to change the shape of an array.
object.reshape inside parentheses rows comma columns |
Switch to terminal | Switch back to the terminal. |
Type, br = ar.reshape(2,4) | Type, ar dot reshape inside parentheses 2 comma 4. |
type ar | type ar
|
Type, ar.shape = (2,4) | If you want to change the shape of the original array, type
ar dot shape is equal to inside parentheses 2 comma 4. |
Type ar | Type ar
|
Show Slide
shape of an array
|
To find the shape of an array we can use the method shape.
|
Type
a2.shape
|
Let us check the shape of the arrays we have created so far.
|
Show Slide
Assignment 1
|
Pause the video here, try out the following exercise and resume the video.
|
Type a1.shape | Let us see the solution.
|
Type, ar.shape | Type, ar dot shape
|
Type, a3 = np.array([1,2,3,'a string']) | Now let us try to create a new array with elements of different datatypes.
|
Type a3
|
Arrays handle elements with the same datatype.
|
Highlight dtype='<U21')
|
This is how array works.
|
Show Slide
identity(n) method
|
Next we will see about identity matrix.
|
type np.identity(2) | Let us see how to create a 2 by 2 identity matrix.
|
Show Slide
zeros(shape) method
|
Next is Zeros method.
|
type
np.zeros((4,5)) |
Let us create an array of the shape (4, 5) with all the elements zero.
|
But box on the arrays iden: | The default output of identity and zeros method are in float datatype. |
Show Slide
Learning exercise
|
Explore the below functions on your own:
|
type, a1 | Try the following.
|
type
a1 * 2 |
Let us now try a1 multiplied by 2
|
Type a1 | Now let us again check the contents of a1.
|
Type a1 + 2 | Similarly we will try with addition.
|
Type a1 | Type a1
|
Type a1 += 2 | Let us try with a1 plus equal to 2 |
Type a1 | Type, a1
|
Type a1 = np.array([1, 2, 3, 4]) | We can use all the mathematical operations with arrays.
|
Type, a2 = np.array([5, 6, 7, 8]) | Type, a2 is equal to np dot array inside parentheses inside square brackets 5, 6, 7, 8 |
Type, a1 + a2 | Type, a1 plus a2
|
Type, a1 * a2
|
Type, a1 multiplied by a2
|
Show Slide
Summary slide
|
This brings us to the end of the end of this tutorial.
shapearange reshapeidentity andzeros |
Show Slide
Self assessment questions slide
|
Here is a self assessment question for you to solve
x is equal to np.array inside parentheses inside square brackets 1, 2, 3, inside square brackets 5, 6, 7 is a valid statement ?
|
Show Slide
Solution of self assessment questions on slide
|
And the answer is False.
|
Show Slide Forum | Please post your timed queries in this forum. |
Show Slide Fossee Forum | Please post your general queries on Python in this forum. |
Slide Textbook Companion | FOSSEE team coordinates the TBC project. |
Show Slide
Acknowledgment
|
Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India.
|
Previous slide | This is Priya from IIT Bombay signing off. Thanks for watching. |