-
Notifications
You must be signed in to change notification settings - Fork 14
/
twoDimensionalArrays1.py
44 lines (30 loc) · 1.08 KB
/
twoDimensionalArrays1.py
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
import numpy as np
twoDArray = np.array([[11, 15, 10, 6], [10, 14, 11, 5], [12, 17, 12, 8], [15, 18, 14, 9] ])
print(twoDArray)
# newTwoDArray = np.insert(twoDArray, 1, [[1,2,3,4]], axis=0)
# print(newTwoDArray)
print(len(twoDArray))
newTwoDArray = np.append(twoDArray, [[1,2,3,4]], axis=0)
print(newTwoDArray)
print(len(newTwoDArray))
print(len(newTwoDArray[0]))
def accessElements(array, rowIndex, colIndex):
if rowIndex >= len(array) and colIndex >= len(array[0]):
print('Incorrect Index')
else:
print(array[rowIndex][colIndex])
accessElements(newTwoDArray, 1, 2)
def traverseTDArray(array):
for i in range(len(array)):
for j in range(len(array[0])):
print(array[i][j])
traverseTDArray(twoDArray)
def searchTDArray(array, value):
for i in range(len(array)):
for j in range(len(array[0])):
if array[i][j] == value:
return 'The value is located index '+str(i)+" "+str(j)
return 'The element no found'
print(searchTDArray(twoDArray, 444))
newTDArray = np.delete(twoDArray, 1, axis=1)
print(newTDArray)