Commit 46527776 authored by Sanchit's avatar Sanchit

All parts of 1 except c and Readme

parent 70a324d1
https://en.wikipedia.org/wiki/Rotation_matrix
https://www.geeksforgeeks.org/numpy-cumsum-in-python/
https://www.javatpoint.com/numpy-pad
https://numpy.org/doc/stable/reference/generated/numpy.argsort.html
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html
https://scipython.com/book/chapter-6-numpy/examples/creating-a-rotation-matrix-in-numpy/
\ No newline at end of file
......@@ -6,7 +6,7 @@ import random # for testing
def avada_kedavra(my_list):
# Create an array 'a0' from this list 'my_list'
#my_integer=random.sample(range(1,101), 25) to test
a0=np.array(my_integer)
a0=np.array(my_list)
# print a0
print("a0 at beginning:\n{}".format(a0))
......@@ -107,13 +107,13 @@ def expelliarmus(arr, theta, axis):
[s, c, 0],
[0, 0, 1]])
if axis == 'X':
res = np.dot(mat, rot_array_x)
res = np.dot(arr, rot_array_x)
return (res.round(decimals=2))
if axis == 'Y':
res = np.dot(mat, rot_array_y)
res = np.dot(arr, rot_array_y)
return (res.round(decimals=2))
if axis == 'Z':
res = np.dot(mat, rot_array_z)
res = np.dot(arr, rot_array_z)
return (res.round(decimals=2))
......@@ -131,8 +131,11 @@ def crucio(arr):
# 'arr': int 1-D array; dim: (n,)
# k: integer
# return type: int 1-D array; dim: (n+k-1,)
def leviosa(arr, k):
pass
def leviosa(arr,k):
arr=np.pad(arr,(0,k-1))
cumm_ar=np.cumsum(arr)
cumm_ar[k:]=cumm_ar[k:]- cumm_ar[:-k]
return cumm_ar
# ---- Task (g) -------
......@@ -140,7 +143,6 @@ def leviosa(arr, k):
# k: integer
# return type: n-D integer array; dim: (m,k)
def accio(mat, k):
pass
return np.fliplr(np.argsort(mat))[:,:k]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment