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

  • Home
  • SEARCH
  • 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 7923043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:10:27+00:00 2026-06-03T17:10:27+00:00

I was wondering if it was possible to create a nested matrix in python.

  • 0

I was wondering if it was possible to create a nested matrix in python. Here I define my matrix A

  A = array([[ 12.,   0.],[  0.,   4.]])

I would like to replace the zeros with a generic 2×2 matrix and then plot everything with imshow(). Is that possible?

I tried defining my nested matrix this way

  A = array([[ 12.,   array([[ 1.,   1.],[  1.,   1.]])],[  0.,   4.]])

but I got this error message

ValueError: setting an array element with a sequence.

  • 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-03T17:10:29+00:00Added an answer on June 3, 2026 at 5:10 pm
    >>> M = NP.empty((5, 5), dtype=NP.object)     # a 2D NumPy array
    >>> M
      array([[None, None, None, None, None],
             [None, None, None, None, None],
             [None, None, None, None, None],
             [None, None, None, None, None],
             [None, None, None, None, None]], dtype=object)
    

    Now you can insert sequences, without getting the ValueError

    >>> M[2,2] = NP.array([4, 3, 5])
    >>> M
      array([[None, None, None, None, None],
             [None, None, None, None, None],
             [None, None, [4 3 5], None, None],
             [None, None, None, None, None],
             [None, None, None, None, None]], dtype=object)
    
    >>> M[2,2]
       array([4, 3, 5])
    

    The other part of the OP–passing an Array like this to Matplotlib’s imshow, is a problem.

    imshow visually represents a 2D array as a cloud of points positioned on the canvas according to their x, y indices. The value at that index is indicated according to different colors and color intensities based on a colormap which maps color to array value. Therefore, valid arguments for imshow’s data parameter are:

    • NumPy 2D arrays

    NumPy arrays of higher dimension in two (and only these two AFAIK) which imshow can interpret as

    • NumPy 2D array of rgb tuples (x, y, r, b, g)

    • NumPy 6D arrays, which are interpreted as a 2D array of rgba
      tuples
      (x, y, r, g, b, a)

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

Sidebar

Related Questions

I am wondering if it is possible to create something like a predicate for
I was wondering if it's possible to create a generic push notification solution for
I was wondering if it would be possible to create a window using SWT
I was wondering if it was possible to create an array of objects when
I was wondering if it would be possible to create a C++ environment variable
I am wondering if it's possible to create a grid-like layout using div's that
I am wondering if is possible to create an XSLT stylesheet that would extract
I was wondering how it would be possible to create my own listener for
I was wondering if it is possible to create a flash movie that rotates
I was wondering if it was possible to create a SPARQL UpdateRequest in Jena

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.