Professional Documents
Culture Documents
Abstract
In human motion analysis there is a frequently need for processing large amounts of data.
Storing data in lists and traversing lists with built-in Python’s loops leads to slow code.
Problem 1
Given the list rnd seq. The problem states that you should find the indexes of all occurrences of the
item ‘blue’.
"""
@autor: Eng. Alexander Sierra, Assistant Professor
"""
from future import p r i n t f u n c t i o n
import random
import d a t e t i m e
# seeding the random number generator
random . s e e d ( d a t e t i m e . d a t e t i m e . now ( ) . y e a r )
item idxs = []
In the script 1, the seed method is seeding the underlying random number generator used by Python’s
random module.
1
Problem 2
Consider a 1-dimensional list of True and False objects. The problem states that you should count
the number of False-to-True transitions in the sequence.
"""
@autor: Eng. Alexander Sierra, Assistant Professor
"""
from future import p r i n t f u n c t i o n
import random
import d a t e t i m e
r n d s e q =[ random . c h o i c e ( [ F a l s e , True ] )
for in range (100000)]
2
Problem 3
For an array of points X where each row represents a point in R3 compute kxk for x in X.
x1 y1 z1
x2 y2 z2
X= . (1)
.. ..
.. . .
xn yn zn
"""
@autor: Eng. Alexander Sierra, Assistant Professor
"""
from future import p r i n t f u n c t i o n
from p p r i n t import p p r i n t
import random
import d a t e t i m e
x array = [ ]
f o r row i n r a n g e (N ) :
point = [ ]
for i in range ( 3 ) :
p o i n t . append ( random . random ( ) )
x a r r a y . append ( p o i n t )
3
Problem 4
Consider a two-dimensional array containing a 3D-point cloud. Where N is the number of points in
the cloud.
x1 y1 z1
x2 y2 z2
ptCloud = . (2)
.. ..
.. . .
xn yn zn
The problem states that you should compute the radius of the sphere that best fit to all points. Hint:
find the centroid of point cloud.
The script 4 generates the point cloud.
4
"""
@autor: Eng. Alexander Sierra, Assistant Professor
"""
from future import p r i n t f u n c t i o n
from p p r i n t import p p r i n t
import random
d e f p o i n t c l o u d g e n e r a t o r ( n =10):
"""
Helper function to make an array having shape (n, 3)
"""
array = []
f o r rows i n range ( n ) :
point = [ ]
for in range ( 3 ) :
p o i n t . append ( random . g a u s s ( 0 , 1 ) )
a r r a y . append ( p o i n t )
return array
ptCloud = p o i n t c l o u d g e n e r a t o r (100000)
p r i n t ( ” p o i n t c l o u d l e n g t h : {} ” . f o r m a t ( l e n ( p t C l o u d ) ) )
5
Problem 5
The coordinates.csv file specify the position of two points in the three-dimensional space at different
times. A fragment of this file is shown in the table below.
The first line of file is a header that contains column labels followed by the rows of data. Each row of
data contains the (x, y, z) coordinates of each point.
The problem states that you should compute the mean distance between two points.
"""
@autor: Eng. Alexander Sierra, Assistant Professor
"""
from future import p r i n t f u n c t i o n
# print(datetime.datetime.now().year)
f = open ( ’ c o o r d i n a t e s . c s v ’ , ’ r ’ )
f . close ()
6
Marking criteria
The assignment is marked out of 50. Your work will be marked using the following criteria:
- Problem 1, 5 marks.
- Problem 2, 5 marks.
- Problem 3, 10 marks.
- Problem 4, 10 marks.
- Problem 5, 20 marks.