In [33]:
# Repeat a Python list
[1, 3]*5
Out[33]:
In [34]:
# repeat at Numpy array
np.array([1, 3]*5)
Out[34]:
In [46]:
tile([1, 3], 5) # also transforms a Python list into Numpy array
Out[46]:
In [54]:
repeat([1, 3], 5) # repeat the elements ! also transforms a Python list into Numpy array
Out[54]:
In [37]:
# Pay attention that r_ or c_ not repeat but instead perform element multiplication
r_[1, 3]*5
Out[37]:
Let $a$ and $b$ two vectors of different length, for example: $$ a = \left( 1 , 2 , 3 \right) $$ and $$ b = \left(4, 5\right) $$ We would like new vectors $a_2$ and $b_2$ with the same length and such that: $$ \begin{array}{l} a_2 = \left(1, 2, 3, 1, 2, 3\right)\\ b_2 = \left(4, 4, 4, 5, 5, 5\right) \end{array} $$
In [53]:
# method 1
a = np.array([1,2,3])
b = np.array([4, 5])
a2 = tile(a, len(b))
b2 = repeat(b, len(a))
print(a2)
print(b2)
In [52]:
# method 2
a = np.array([1,2,3])
b = np.array([4, 5])
aa, bb = meshgrid(a,b)
a2 = reshape(aa, len(a)*len(b))
b2 = reshape(bb, len(a)*len(b))
print(a2)
print(b2)
In [1]:
from IPython.core.display import HTML
def css_styling():
styles = open("../styles/custom.css", "r").read()
return HTML(styles)
css_styling()
In [ ]: