Answers for "python map method"

1

mAPE python

def percentage_error(actual, predicted):
    res = np.empty(actual.shape)
    for j in range(actual.shape[0]):
        if actual[j] != 0:
            res[j] = (actual[j] - predicted[j]) / actual[j]
        else:
            res[j] = predicted[j] / np.mean(actual)
    return res

def mean_absolute_percentage_error(y_true, y_pred): 
    return np.mean(np.abs(percentage_error(np.asarray(y_true), np.asarray(y_pred)))) * 100
Posted by: Guest on June-07-2020
5

map in python

map(function_to_apply, list_of_inputs)
Posted by: Guest on October-20-2020
6

map in python 3

map(function, iterable, ...)
Posted by: Guest on May-26-2020
1

map function in python

# for the map function we give a function (action to act), a data action to act on that data.

# without map
def multiply_by2(li):
    new_list = []
    for number in li:
        new_list.append(number*2)
    return new_list


print(multiply_by2([1, 2, 3]))


# using map function
def multiply_by_2(item):
    return item*2


print(list(map(multiply_by_2, [1, 2, 3])))

# function that returns usernames in all uppercase letters.
usernames = ["RN_Tejas", "RN_Tejasprogrammer", "Rajendra Naik", "yooo", "Brainnnni", "Ouuuuut"]


def no_lower(item):
    return item.upper()


print(list(map(no_lower, usernames)))

# squares function
list_squares = list(range(1, 101))
print(list_squares)


def square(number):
    return number**2


square_list = list(map(square, list_squares))


def square_root(number):
    return number // number


print(list(map(square_root, square_list)))


def no_upper(string):
    return string.lower()


print(list(map(no_upper, 'TEJAS')))
Posted by: Guest on December-31-2020
0

função map python

lista =  [1, 2, -3, 4, 5, -9]
def quadrado(n):
    return n*n
 
map(quadrado, lista)
[1, 4, 9, 16, 25, 81]
Posted by: Guest on May-03-2020
0

about map function in python

# Add two lists using map and lambda
  
numbers1 = [1, 2, 3]
numbers2 = [4, 5, 6]
  
result = map(lambda x, y: x + y, numbers1, numbers2,axis=1)
print(list(result))
Posted by: Guest on May-30-2021

Python Answers by Framework

Browse Popular Code Answers by Language