import numpy as np
def pagerank(M, num_iterations=100, d=0.85):
N = M.shape[1]
v = np.random.rand(N, 1)
v = v / np.linalg.norm(v, 1)
iteration = 0
while iteration < num_iterations:
iteration += 1
v = d * np.matmul(M, v) + (1 - d) / N
return v
This method gets vowels (‘a’, ‘e’, ‘i’, ‘o’, ‘u’) found in a string.
#make a function:
def get_vowels(string):
#return is the keyword which means function have to return value:
return [each for each in string if each in 'aeiou']
#assign the words and function will return vowels words.
get_vowels('foobar') # ['o', 'o', 'a']
get_vowels('gym') # []
Comments