Convert a NumPy array to a tuple in Python

0 votes

Hi Guys,

I am new in Python. I want to convert one Numpy array to a tuple. How can I do that?

Jun 29, 2020 in Python by akhtar
• 38,210 points
1,066 views

1 answer to this question.

0 votes

Hi@akhtar,

You can use the tuple keyword in Python. It allows you to convert Numpy to a tuple. I have attached one example for your reference.

arr = np.array(((1, 2),(3, 4)))
array_of_tuples = map(tuple, arr)
tuples = tuple(array_of_tuples)
print(tuples)
    answered Jun 29, 2020 by MD
    • 95,300 points

    Related Questions In Python

    0 votes
    1 answer
    0 votes
    1 answer

    How to convert a Pandas GroupBy object to DataFrame in Python

    g1 here is a DataFrame. It has a hierarchical index, ...READ MORE

    answered Nov 12, 2018 in Python by Nymeria
    • 3,520 points
    30,195 views
    0 votes
    1 answer

    How to save Numpy array as image in python?

    If you have matplotlib, you can do: import ...READ MORE

    answered Nov 16, 2018 in Python by Nymeria
    • 3,520 points
    7,492 views
    0 votes
    2 answers
    +1 vote
    2 answers

    how can i count the items in a list?

    Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

    answered Jul 7, 2019 in Python by Neha
    • 330 points

    edited Jul 8, 2019 by Kalgi 2,423 views
    0 votes
    0 answers
    +5 votes
    6 answers

    Lowercase in Python

    You can simply the built-in function in ...READ MORE

    answered Apr 11, 2018 in Python by hemant
    • 5,810 points
    1,823 views
    0 votes
    1 answer
    0 votes
    1 answer