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,260 points
2,499 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,460 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,560 points
    34,471 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,560 points
    8,984 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 4,467 views
    0 votes
    1 answer
    +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,790 points
    4,127 views
    0 votes
    1 answer
    0 votes
    1 answer
    webinar REGISTER FOR FREE WEBINAR X
    REGISTER NOW
    webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP