Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8489587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:52:09+00:00 2026-06-10T21:52:09+00:00

I recently found out how to use tuples thanks to great contributions from SO

  • 0

I recently found out how to use tuples thanks to great contributions from SO users(see here). However I encounter the problem that I can’t add a tuple to another tuple stored inside an array of tuples. For instance if I define:

arrtup=empty((2,2),dtype=('int,int'))
arrtup[0,1]=(3,4)

Then if I try to add another tuple to the existing tupe to come up with a multidimensional index:

arrtup[0,1]+(4,4)

I obtain this error:

TypeError: unsupported operand type(s) for +: 'numpy.void' and 'tuple'

Instead of the expected (3,4,4,4) tuple, which I can obtain by:

(3,4)+(4,4)

Any ideas? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:52:11+00:00Added an answer on June 10, 2026 at 9:52 pm

    You are mixing different concepts, I’m afraid.

    Your arrtup array is not an array of tuples, it’s a structured ndarray, that is, an array of elements that look like tuples but in fact are records (numpy.void objects, to be exact). In your case, you defined these records to consist in 2 integers. Internally, NumPy creates your array as a 2×2 array of blocks, each block taking a given space defined by your dtype: here, a block consists of 2 consecutive blocks of size int (that is, each sub-block takes the space an int takes on your machine).

    When you retrieve an element with arrtup[0,1], you get the corresponding block. Because this block is structured as two-subblocks, NumPy returns a numpy.void (the generic object representing structured blocks), which has the same dtype as your array.

    Because you set the size of those blocks at the creation of the array, you’re no longer able to modify it. That means that you cannot transform your 2-int records into 4-int ones as you want.

    However, you can transform you structured array into an array of objects:

    new_arr = arrtup.astype(object)
    

    Lo and behold, your elements are no longer np.void but tuples, that you can modify as you want:

    new_arr[0,1] = (3,4) # That's a tuple
    new_arr[0,1] += (4,4) # Adding another tuple to the element
    

    Your new_arr is a different beast from your arrtup: it has the same size, true, but it’s no longer a structured array, it’s an array of objects, as illustrated by

    >>> new_arr.dtype
    dtype("object")
    

    In practice, the memory layout is quite different between arrtup and newarr. newarr doesn’t have the same constraints as arrtup, as the individual elements can have different sizes, but object arrays are not as efficient as structured arrays.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently found out about the WeakHashMap data structure in Java. However, I don't
The obvious answer is to use Charset.defaultCharset() but we recently found out that this
I recently found out about ActiveSupport::Notifications . I think it's a great tool to
I recently found out that I can use any dialect of Lisp for the
I recently found out that I need to use the cellspacing attribute in my
I recently found out about Cytoscape.js and would like to try out the force-directed
I recently found out about C# extension methods and wrote this one: /// <summary>
I recently found out about n-grams and the cool possibility to compare frequency of
I have recently found out that there exists a method called nth_element in the
I have recently found out that no argument constructor and multiple argument constructor cannnot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.