Numpy: Numerical Computation in Python Flashcards
This is prompt.
What stands for Numpy
This is Footnote
Numerical Python
This is Footnote in Answer
Numpy developed by ?
Travis Oliphant
What is an array in Python ?
Array is the data structure that stores values of Same data types.
How Array is created in Python ?
To create a array in Python we have to use Numpy library.
How to import numpy Library ?
import numpy as np
How to Define array in python ?
#We have to use numpy library import numpy as np a1 = np.array([1,2,3,4,5]) print(a1)
How to print last element of numpy array ?
print(a1[-1])
How to print the second last and third last element of numpy array ?
a1[-2] a1[-3]
How to get the size of numpy array ?
We have to use the array property- array1.size
~~~
a.numpy.array([1,2,3,4])
print(a.size())
~~~
How to get the total bytes of array in python without using byte property ?
import numpy as np a1=np.array([1,2,3,4]) print(f"Total Array Size is {a1.size} Items") print(f"Each Element Size is {a1.itemsize} bytes") print(f"Total size of Array in bytes is : {a1.itemsize* a1.size} bytes")
How to Print the total bytes of Array ?
We Have to use an array property - nbytes
~~~
a1=np.array([1,2,3,4])
print(fâTotal Bytes of Array {a1.nbytes}â)
~~~
How to get the size of array element ?
We have to use the property items size.
~~~
print(a1.itemsize)
~~~
How to get the data type of an array elements ?
We have to use dtype property of array ?
~~~
print(a1.dtype)
~~~
How to update value at given index in an array ?
array[3]=10
How to create three dimension array ?
threeDArray=np.array([[1,2,3,4,5], [1,2,3,4,5], [1,2,3,4,5]]) print(threeDArray)
How to iterate three dimensional array ?
We have to use shape property to get row and colum value.
~~~
import numpy as np
threeDArray=np.array([[1,2,3,4,5],
[2,6,7,8,9],
[3,4,5,6,5]])
for i in range(twoDArray.shape[0]):
for j in range(twoDArray.shape[1]):
print(fâ{twoDArray[i][j]} â,end=â â)
print(â\nâ)
~~~
How to know the array is One dimensional or two dimensional ?
We have to use the property ndim
~~~
a1.ndim
~~~
How to get the row and colum count of array ?
We have to use the shape property
~~~
threeDArray=np.array([[1,2,3,4,5],
[2,6,7,8,9],
[3,4,5,6,5]])
print(threeDArray.shape)
~~~
What are the different properties of numpy array?
Some property are: size,itemsize,nbytes, ndim,shape,dtype
~~~
print(threeDArray.size)
print(threeDArray.itemsize)
print(threeDArray.nbytes)
print(threeDArray.shape)
print(threeDArray.ndim)
print(threeDArray.dtype)
~~~
How to Print array values by adding one ?
print(array1 + 1)
How to print array values by myltiplying by two ?
print(array1 * 2)
How to access array elements by using slice notation ?
It Prints the elements 0,1,2
~~~
array1=np.array([1,2,3,4,5,6])
print(array1[0:3])
~~~
What is the output of this ?
~~~
a=np.array([2,8,6,76,56,87])
print(a[2:])
~~~
[ 6 76 56 87]
What is the output of ?
~~~
a=np.array([2,8,6,78,55,94])
print(a[:5])
~~~
[ 2 8 6 78 55]
What is the output of ?
~~~
a=np.array([2,8,6,78,55,94,45,4,8,23])
print(a[3:8:2])
~~~
[78 94 4]
What is the output of ?
~~~
a=np.array([2,8,6,78,55,94,45,4,8,23])
print(a[0::2])
~~~
[ 2 6 55 45 8]