Professional Documents
Culture Documents
arr=np.array([])
Type-2:
arr=np.flip(arr)
print(arr)
Write a NumPy program to create a 8x8 matrix and fill it with a checkerboard
pattern. (0 1 0 1 0 1 0 1 )
x = np.zeros((8,8),dtype=int)
x[1::2,::2] = 1
x[::2,1::2] = 1
print(x)
Format a float
a = 2.154327
format_float = "{:.2f}".format(a)
print(format_float)
#Q.Write a Program to find the sum of all numbers stored in a list
//Type-1
num = [1, 2, 3, 4, 5]
sum = 0
for x in num:
sum += x
print(sum)
//Type-2
n=[2,3,4,5,6,7]
sum=0
i=0
while i < len(n):
sum+=n[i]
i+=1
print(sum)
mylist = [10,20,30];
changeme( mylist );
print ("Values outside the function: ", mylist)
appending name:
def my_function(fname):
print(fname + " Zaman")
my_function("Mina")
my_function("Farhim")
my_function("Tina")
String:
data = "I lovee data science"
type(data)
len(data)
import sys
sys.getsizeof(data)
data.count("data")
data.find("data")
data.find('v')
data.find("v",6,10)
data.index('v')
data.index("w")
data.upper()
data.lower()
data.capitalize()
data.swapcase()
data.title()
data.split()
data.split()[1]
data.replace('data','ai')
//list
n = [1,2,3,"ritu",True,(1,2,3)]
n[0:4]/// n[-1]/// n[-1][0]
list element update: list[2]=2000;
list element delete: del(list[2])
n = [1,2,3,"ritu","nil",True,(1,2,3)]
n[0:4] -_--> [1, 2, 3, 'ritu']
//tuple
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5, 6, 7 );
print ("tup1[0]: ", tup1[0])
print ("tup2[1:5]: ", tup2[1:5]) - (2, 3, 4, 5)
tup3 = tup1 + tup2;
print (tup3)
student_name = 'Sobuj'
marks = {'James': 90, 'Jules': 55, 'Arthur': 77}
for student in marks:
if student == student_name:
print(marks[student])
break
else:
print('No entry with that name found.')
#numpy array 1D
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr)
print(type(arr))
#2D
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)
#3D
import numpy as np
arr = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])
print(arr)
np.zeros((3,4))
np.ones((3,4))
Reverse the tuple
tuple1 = (10, 20, 30, 40, 50)
tuple1 = tuple1[::-1]
print(tuple1)
import numpy
Create a 5X2 integer array from a range between 100 to 200 such that
the difference between each element is 10
import numpy
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)
Return array of odd rows and even columns from below numpy array
import numpy