Numpy Program - Pynat
Numpy Program - Pynat
Numpy Program - Pynat
Note: The element must be a type of unsigned int16. And print the following Attributes: –
Printing Array
[[64392 31655]
[32579 0]
[49248 462]
[ 0 0]]
import numpy
Exercise 2: Create a 5X2 integer array from a range between 100 to 200
such that the difference between each element is 10
Expected Output:
[[100 110]
[120 130]
[140 150]
[160 170]
[180 190]]
import numpy
sampleArray = numpy.array([[11 ,22, 33], [44, 55, 66], [77, 88, 99]])
Expected Output:
[[11 22 33]
[44 55 66]
[77 88 99]]
[33 66 99]
Show Solution
import numpy
sampleArray = numpy.array([[11 ,22, 33], [44, 55, 66], [77, 88, 99]])
print("Printing Input Array")
print(sampleArray)
print("\n Printing array of items in the third column from all rows")
newArray = sampleArray[...,2]
print(newArray)
Exercise 4: Return array of odd rows and even columns from below
numpy array
Expected Output:
[[ 3 6 9 12]
[15 18 21 24]
[27 30 33 36]
[39 42 45 48]
[51 54 57 60]]
[[ 6 12]
[30 36]
[54 60]]
Show Solution
import numpy
Expected Output:
[[20 39 33]
[25 25 28]]
Show Solution
import numpy
Note: Create an 8X3 integer array from a range between 10 to 34 such that the difference between
each element is 1 and then Split the array into four equal-sized sub-arrays.
Expected Output:
Creating 8X3 array using numpy.arange
[[10 11 12]
[13 14 15]
[16 17 18]
[19 20 21]
[22 23 24]
[25 26 27]
[28 29 30]
[31 32 33]]
Show Solution
import numpy
sampleArray = numpy.array([[34,43,73],[82,22,12],[53,94,66]])
Expected Output:
[[34 43 73]
[82 22 12]
[53 94 66]]
[[73 43 34]
[12 22 82]
[66 94 53]]
[[82 22 12]
[34 43 73]
[53 94 66]]
Show Solution
import numpy
sortArrayByRow = sampleArray[:,sampleArray[1,:].argsort()]
print("Sorting Original array by secoond row")
print(sortArrayByRow)
Exercise 8: Print max from axis 0 and min from axis 1 from the following
2-D array.
sampleArray = numpy.array([[34,43,73],[82,22,12],[53,94,66]])
Expected Output:
Printing Original array
[[34 43 73]
[82 22 12]
[53 94 66]]
[34 12 53]
[82 94 73]
Show Solution
import numpy
minOfAxisOne = numpy.amin(sampleArray, 1)
print("Printing amin Of Axis 1")
print(minOfAxisOne)
maxOfAxisOne = numpy.amax(sampleArray, 0)
print("Printing amax Of Axis 0")
print(maxOfAxisOne)
Exercise 9: Delete the second column from a given array and insert the
following new column in its place.
sampleArray = numpy.array([[34,43,73],[82,22,12],[53,94,66]])
newColumn = numpy.array([[10,10,10]])
Expected Output:
[[34 43 73]
[82 22 12]
[53 94 66]]
[[34 73]
[82 12]
[53 66]]
[[34 10 73]
[82 10 12]
[53 10 66]]
Show Solution
import numpy
arr = numpy.array([[10,10,10]])
Exercise 10: Create two 2-D arrays and Plot them using matplotlib
import numpy
arr = numpy.array([[10,10,10]])
print("Array after inserting column 2 on axis 1")
sampleArray = numpy.insert(sampleArray , 1, arr, axis = 1)
print (sampleArray)