Write a NumPy program to convert a list and tuple into arrays. Return the converted arrays.
Example 1:
Input: [1, 2, 3, 4, 5], (6, 7, 8, 9, 10) Output: array([1, 2, 3, 4, 5]), array([ 6, 7, 8, 9, 10])
Example 2:
Input: [10, 20, 30, 40, 50], (60, 70, 80, 90, 100) Output: array([10, 20, 30, 40, 50]), array([ 60, 70, 80, 90, 100])
You can use np.array() function to convert a list or a tuple into an array.
import numpy as np def convert_to_arrays(list_values, tuple_values): array_from_list = np.array(list_values) array_from_tuple = np.array(tuple_values) return array_from_list, array_from_tuple print(convert_to_arrays([1, 2, 3, 4, 5], (6, 7, 8, 9, 10))) print(convert_to_arrays([10, 20, 30, 40, 50], (60, 70, 80, 90, 100)))
Unlock AI & Data Science treasures. Log in!