Professional Documents
Culture Documents
Lec 7 8
Lec 7 8
Department of Mathematics
Institute of Business Administration.
Yousuf Tufail ¯ Yousuf Tufail
ytufail@iba.edu.pk
Lecture 7 & 8
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 1/8
Importance of numpy
Example
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 2/8
Importance of numpy
Example
weight
BMI = height 2
Calculate the BMI for the following information
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 2/8
Importance of numpy
Example
weight
BMI = height 2
Calculate the BMI for the following information
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
Solution
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 2/8
Importance of numpy
Example
weight
BMI = height 2
Calculate the BMI for the following information
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
Solution
BMI=weight/(height**2)
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 2/8
Importance of numpy
Example
weight
BMI = height 2
Calculate the BMI for the following information
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
Solution
BMI=weight/(height**2)
TypeError: unsupported operand type(s) for ∗∗ or pow(): ‘list’ and ‘int’
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 2/8
Importance of numpy
Example
weight
BMI = height 2
Calculate the BMI for the following information
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
Solution
BMI=weight/(height**2)
TypeError: unsupported operand type(s) for ∗∗ or pow(): ‘list’ and ‘int’
import numpy as np
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 2/8
Importance of numpy
Example
weight
BMI = height 2
Calculate the BMI for the following information
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
Solution
BMI=weight/(height**2)
TypeError: unsupported operand type(s) for ∗∗ or pow(): ‘list’ and ‘int’
import numpy as np
new weight=np.array(weight)
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 2/8
Importance of numpy
Example
weight
BMI = height 2
Calculate the BMI for the following information
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
Solution
BMI=weight/(height**2)
TypeError: unsupported operand type(s) for ∗∗ or pow(): ‘list’ and ‘int’
import numpy as np
new weight=np.array(weight)
new height=np.array(height)
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 2/8
Importance of numpy
Example
weight
BMI = height 2
Calculate the BMI for the following information
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
Solution
BMI=weight/(height**2)
TypeError: unsupported operand type(s) for ∗∗ or pow(): ‘list’ and ‘int’
import numpy as np
new weight=np.array(weight)
new height=np.array(height)
BMI=new weight/(new height**2)
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 2/8
Importance of numpy
Example
weight
BMI = height 2
Calculate the BMI for the following information
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
Solution
BMI=weight/(height**2)
TypeError: unsupported operand type(s) for ∗∗ or pow(): ‘list’ and ‘int’
import numpy as np
new weight=np.array(weight)
new height=np.array(height)
BMI=new weight/(new height**2)
print(BMI)
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 2/8
Importance of numpy
Example
weight
BMI = height 2
Calculate the BMI for the following information
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
Solution
BMI=weight/(height**2)
TypeError: unsupported operand type(s) for ∗∗ or pow(): ‘list’ and ‘int’
import numpy as np
new weight=np.array(weight)
new height=np.array(height)
BMI=new weight/(new height**2)
print(BMI)
[19.596 27.681 35.856 47.466 34.911]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 2/8
Another difference between arrays and lists
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 3/8
Another difference between arrays and lists
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 3/8
Another difference between arrays and lists
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 3/8
Another difference between arrays and lists
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 3/8
Another difference between arrays and lists
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 3/8
Another difference between arrays and lists
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 3/8
Another difference between arrays and lists
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 3/8
Another difference between arrays and lists
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 3/8
Another difference between arrays and lists
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 3/8
Another difference between arrays and lists
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 3/8
Another difference between arrays and lists
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 3/8
Use of Boolean
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 4/8
Use of Boolean
Suppose A=[2,4,6,7,10,2.1,3,4]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 4/8
Use of Boolean
Suppose A=[2,4,6,7,10,2.1,3,4]
B=np.array(A)
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 4/8
Use of Boolean
Suppose A=[2,4,6,7,10,2.1,3,4]
B=np.array(A)
C=A>3
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 4/8
Use of Boolean
Suppose A=[2,4,6,7,10,2.1,3,4]
B=np.array(A)
C=A>3
TypeError: ‘>’ not supported between instances of ‘list’ and ‘int’
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 4/8
Use of Boolean
Suppose A=[2,4,6,7,10,2.1,3,4]
B=np.array(A)
C=A>3
TypeError: ‘>’ not supported between instances of ‘list’ and ‘int’
D=B>3
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 4/8
Use of Boolean
Suppose A=[2,4,6,7,10,2.1,3,4]
B=np.array(A)
C=A>3
TypeError: ‘>’ not supported between instances of ‘list’ and ‘int’
D=B>3
print(D)
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 4/8
Use of Boolean
Suppose A=[2,4,6,7,10,2.1,3,4]
B=np.array(A)
C=A>3
TypeError: ‘>’ not supported between instances of ‘list’ and ‘int’
D=B>3
print(D)
[False True True True True False False True]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 4/8
Use of Boolean
Suppose A=[2,4,6,7,10,2.1,3,4]
B=np.array(A)
C=A>3
TypeError: ‘>’ not supported between instances of ‘list’ and ‘int’
D=B>3
print(D)
[False True True True True False False True]
Now if you want to know what are those values that satisfies the above
condition, then
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 4/8
Use of Boolean
Suppose A=[2,4,6,7,10,2.1,3,4]
B=np.array(A)
C=A>3
TypeError: ‘>’ not supported between instances of ‘list’ and ‘int’
D=B>3
print(D)
[False True True True True False False True]
Now if you want to know what are those values that satisfies the above
condition, then
print(B[D])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 4/8
Use of Boolean
Suppose A=[2,4,6,7,10,2.1,3,4]
B=np.array(A)
C=A>3
TypeError: ‘>’ not supported between instances of ‘list’ and ‘int’
D=B>3
print(D)
[False True True True True False False True]
Now if you want to know what are those values that satisfies the above
condition, then
print(B[D])
[ 4. 6. 7. 10. 4.]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 4/8
2D array
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
weight=[70,80,100,120,59]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
new 2d matrix=np.array([weight,height])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
new 2d matrix=np.array([weight,height])
print(new 2d matrix)
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
new 2d matrix=np.array([weight,height])
print(new 2d matrix)
[[ 70. 80. 100. 120. 59.],
[1.89 1.7 1.67 1.59 1.3 ]]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
new 2d matrix=np.array([weight,height])
print(new 2d matrix)
[[ 70. 80. 100. 120. 59.],
[1.89 1.7 1.67 1.59 1.3 ]]
print(new 2d matrix.shape)
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
new 2d matrix=np.array([weight,height])
print(new 2d matrix)
[[ 70. 80. 100. 120. 59.],
[1.89 1.7 1.67 1.59 1.3 ]]
print(new 2d matrix.shape)
(2, 5)
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
new 2d matrix=np.array([weight,height])
print(new 2d matrix)
[[ 70. 80. 100. 120. 59.],
[1.89 1.7 1.67 1.59 1.3 ]]
print(new 2d matrix.shape)
(2, 5)
Calling entries from the array
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
new 2d matrix=np.array([weight,height])
print(new 2d matrix)
[[ 70. 80. 100. 120. 59.],
[1.89 1.7 1.67 1.59 1.3 ]]
print(new 2d matrix.shape)
(2, 5)
Calling entries from the array
If you want to call ‘100’ from the above 2D array then the following
options can be used.
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
new 2d matrix=np.array([weight,height])
print(new 2d matrix)
[[ 70. 80. 100. 120. 59.],
[1.89 1.7 1.67 1.59 1.3 ]]
print(new 2d matrix.shape)
(2, 5)
Calling entries from the array
If you want to call ‘100’ from the above 2D array then the following
options can be used.
(i) print(new 2d matrix[0][2])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array
Suppose
weight=[70,80,100,120,59]
height=[1.89,1.70,1.67,1.59,1.3]
new 2d matrix=np.array([weight,height])
print(new 2d matrix)
[[ 70. 80. 100. 120. 59.],
[1.89 1.7 1.67 1.59 1.3 ]]
print(new 2d matrix.shape)
(2, 5)
Calling entries from the array
If you want to call ‘100’ from the above 2D array then the following
options can be used.
(i) print(new 2d matrix[0][2])
(ii)print(new 2d matrix[0,2])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 5/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Solution
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Solution
print(new 2d matrix[0])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Solution
print(new 2d matrix[0])
[ 70. 80. 100. 120. 59.]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Solution
print(new 2d matrix[0])
[ 70. 80. 100. 120. 59.]
OR
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Solution
print(new 2d matrix[0])
[ 70. 80. 100. 120. 59.]
OR
print(new 2d matrix[0,:])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Solution
print(new 2d matrix[0])
[ 70. 80. 100. 120. 59.]
OR
print(new 2d matrix[0,:])
OR
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Solution
print(new 2d matrix[0])
[ 70. 80. 100. 120. 59.]
OR
print(new 2d matrix[0,:])
OR
print(new 2d matrix[0,0:])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Solution
print(new 2d matrix[0])
[ 70. 80. 100. 120. 59.]
OR
print(new 2d matrix[0,:])
OR
print(new 2d matrix[0,0:])
OR
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Solution
print(new 2d matrix[0])
[ 70. 80. 100. 120. 59.]
OR
print(new 2d matrix[0,:])
OR
print(new 2d matrix[0,0:])
OR
print(new 2d matrix[0][0:])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Solution
print(new 2d matrix[0])
[ 70. 80. 100. 120. 59.]
OR
print(new 2d matrix[0,:])
OR
print(new 2d matrix[0,0:])
OR
print(new 2d matrix[0][0:])
OR
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call whole first row from new 2d matrix.
Solution
print(new 2d matrix[0])
[ 70. 80. 100. 120. 59.]
OR
print(new 2d matrix[0,:])
OR
print(new 2d matrix[0,0:])
OR
print(new 2d matrix[0][0:])
OR
print(new 2d matrix[0][:])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 6/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 7/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 7/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call first three entries of the second row.
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 7/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call first three entries of the second row.
Solution
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 7/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call first three entries of the second row.
Solution
print(new 2d matrix[1][0:3])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 7/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call first three entries of the second row.
Solution
print(new 2d matrix[1][0:3])
[1.89 1.7 1.67]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 7/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call first three entries of the second row.
Solution
print(new 2d matrix[1][0:3])
[1.89 1.7 1.67]
OR
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 7/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call first three entries of the second row.
Solution
print(new 2d matrix[1][0:3])
[1.89 1.7 1.67]
OR
print(new 2d matrix[1,0:3])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 7/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call first three entries of the second row.
Solution
print(new 2d matrix[1][0:3])
[1.89 1.7 1.67]
OR
print(new 2d matrix[1,0:3])
[1.89 1.7 1.67]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 7/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 8/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 8/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call all the entries in the first three columns
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 8/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call all the entries in the first three columns
Solution
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 8/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call all the entries in the first three columns
Solution
print(new 2d matrix[:,0:3])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 8/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call all the entries in the first three columns
Solution
print(new 2d matrix[:,0:3])
[[ 70. 80. 100. ]
[ 1.89 1.7 1.67]]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 8/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call all the entries in the first three columns
Solution
print(new 2d matrix[:,0:3])
[[ 70. 80. 100. ]
[ 1.89 1.7 1.67]]
OR
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 8/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call all the entries in the first three columns
Solution
print(new 2d matrix[:,0:3])
[[ 70. 80. 100. ]
[ 1.89 1.7 1.67]]
OR
print(new 2d matrix[0:,0:3])
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 8/8
2D array: new 2d matrix=[[ 70. 80. 100. 120. 59. ] [
1.89 1.7 1.67 1.59 1.3 ]]
Example
Call all the entries in the first three columns
Solution
print(new 2d matrix[:,0:3])
[[ 70. 80. 100. ]
[ 1.89 1.7 1.67]]
OR
print(new 2d matrix[0:,0:3])
[[ 70. 80. 100. ]
[ 1.89 1.7 1.67]]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 7 & 8 8/8