You can use Python’s NumPy library to convert a list and tuple into arrays. Here’s a simple program to demonstrate this:
“`python
import numpy as np
def convert_to_array(input_data):
if isinstance(input_data, list):
return np.array(input_data)
elif isinstance(input_data, tuple):
return np.array(input_data)
else:
raise ValueError(“Input data must be either a list or a tuple”)
# Example usage:
input_list = [1, 2, 3, 4, 5]
input_tuple = (6, 7, 8, 9, 10)
array_from_list = convert_to_array(input_list)
array_from_tuple = convert_to_array(input_tuple)
print(“Array from list:”, array_from_list)
print(“Array from tuple:”, array_from_tuple)
“`
This program defines a function `convert_to_array` that takes either a list or a tuple as input and returns the corresponding NumPy array. It checks the type of the input data and converts it accordingly. Finally, it demonstrates how to use this function with example input data.
Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount