-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction.py
More file actions
48 lines (43 loc) · 1.27 KB
/
Function.py
File metadata and controls
48 lines (43 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import numpy as np
#program to reverse the order of the items in the array.
lis=(input("enter the values into the array"))
data_list=lis.split()
array=np.array(data_list,dtype=int)
for i in range(len(array)//2):
s=array[i]
array[i],array[-(i+1)]=array[-(i+1)],s
print(array)
print(type(array))
# Python program to get the number of occurrences of a specified element in an array.
lis=(input("enter the values into the array"))
data_list=lis.split()
array=np.array(data_list,dtype=int)
dec={}
for i in range(len(array)):
if array[i] in dec:
dec[array[i]]+=1
else:
dec[array[i]]=1
print(dec)
#Python program to find out if a given array of integers contains any duplicate elements.
lis=(input("enter the values into the array"))
data_list=lis.split()
array=np.array(data_list,dtype=int)
s=set(array)
print(s)
#Python program to find the missing number in a given array of 5 continuous numbers.
array=np.array([1,2,3,4,None,6])
i=0
while i < len(array):
if array[i]==None:
array[i]=array[i-1]+1
i+=1
print(array)
#Replace all odd numbers in the given array with -1
lis=(input("enter the values into the array"))
data_list=lis.split()
array=np.array(data_list,dtype=int)
for i in range(len(array)):
if array[i]%2!=0:
array[i]=(-1)
print(array)