forked from arrayfire/arrayfire-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayandmatrixmanipulation.py
More file actions
142 lines (83 loc) · 2.35 KB
/
arrayandmatrixmanipulation.py
File metadata and controls
142 lines (83 loc) · 2.35 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# [manipulation1-snippet]
import arrayfire as af
# Creates a 3x3 array filled with random numbers between [0, 1)
a = af.randu((3, 3))
# Flattens the array 'a' into a 1-dimensional column vector
flat_a = af.flat(a)
# Display the original array 'a'
print(a)
# [manipulation1-endsnippet]
# [manipulation2-snippet]
import arrayfire as af
# Generate a 5x2 array of uniformly distributed random numbers between [0, 1)
a = af.randu((5, 2))
# Print the original array 'a'
print("Original array 'a' [5 2 1 1]")
print(a)
# Flip the array 'a' along both axes (rows and columns)
flip_a = af.flip(a)
# Print the flipped array 'flip_a'
print("\nFlipped array 'flip_a' [5 2 1 1]")
print(flip_a)
# [manipulation2-endsnippet]
# [manipulation3-snippet]
import arrayfire as af
# Generate a 1-dimensional array 'a' of size 5 filled with uniformly distributed random numbers between [0, 1)
a = af.randu((5,))
# Print the original array 'a'
print("Original array 'a' [5 1 1 1]")
print(a)
# Join the array 'a' with itself along axis 0
a_join = af.join(0, a, a)
# Print the joined array 'a_join'
print("\nJoined array 'a_join' [10 1 1 1]")
print(a_join)
# [manipulation3-endsnippet]
# [manipulation4-snippet]
import arrayfire as af
a = af.randu((8,))
print(a)
moddims_a = af.moddims(a,(2,4))
print(moddims_a)
moddims_b = af.moddims(a,(len(a),))
print(moddims_b)
# [manipulation4-endsnippet]
# [manipulation5-snippet]
import arrayfire as af
a = af.randu((2,2,3,1))
print(a)
a_reorder = af.reorder(a,())
# [manipulation5-endsnippet]
# [manipulation6-snippet]
import arrayfire as af
a = af.randu((3,5))
print(a)
a_shift = af.shift(a,(0,2))
print(a_shift)
a_shift1 = af.shift(a,(-1,2))
print(a_shift1)
# [manipulation6-endsnippet]
# [manipulation7-snippet]
import arrayfire as af
a = af.randu((3,)) #[3,1,1,1]
print (a)
a_tile = af.tile(a,(2,))
print(a_tile)
a_tile1 = af.tile(a,(2,2))
print(a_tile1)
a_tile2 = af.tile(a,(1,2,3))
print(a_tile2)
# [manipulation7-endsnippet]
# [manipulation8-snippet]
import arrayfire as af
a = af.randu((3,3))
print(a) #[3 3 1 1]
''' 0.3949 0.8465 0.3709
0.3561 0.9399 0.2751
0.6097 0.6802 0.2720'''
a_transpose = af.transpose(a)
print(a_transpose) #[3 3 1 1]
''' 0.3949 0.3561 0.6097
0.8465 0.9399 0.6802
0.3709 0.2751 0.2720'''
# [manipulation8-endsnippet]