162k views
5 votes
Problem 3. Define a function list_relu (L) which takes as input a list L of numbers, and returns a list which is the same as L except that all negative values in L are replaced with 0. So, for example, list_relu ([1,-2,17,-3.2,-15]) should return the list [1,0,17,0,0]. Hint: Your code will probably need to use an if statement inside a for loop.

User Framp
by
7.6k points

1 Answer

1 vote

Final answer:

To solve this problem, you can define a function called list_relu that takes a list of numbers as input. Use a for loop and an if statement to replace negative values with 0. Finally, return the updated list.

Step-by-step explanation:

To solve this problem, we need to define a function called list_relu that takes a list of numbers as input. We can use a for loop to iterate through each element in the list. Within the loop, we can use an if statement to check if the number is negative. If it is, we replace it with 0. Finally, we return the updated list.

Here's an example of how the function would look like in Python:

def list_relu(L):
for i in range(len(L)):
if L[i] < 0:
L[i] = 0
return L

Learn more about list_relu

User Stephen Haberman
by
8.2k points

No related questions found