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 7491893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:11:32+00:00 2026-05-29T16:11:32+00:00

I think that my issue should be really simple, yet I can not find

  • 0

I think that my issue should be really simple, yet I can not find any help
on the Internet whatsoever. I am very new to Python, so it is possible that
I am missing something very obvious.

I have an array, S, like this [x x x] (one-dimensional). I now create a
diagonal matrix, sigma, with np.diag(S) – so far, so good. Now, I want to
resize this new diagonal array so that I can multiply it by another array that
I have.

import numpy as np
...
shape = np.shape((6, 6)) #This will be some pre-determined size
sigma = np.diag(S) #diagonalise the matrix - this works
my_sigma = sigma.resize(shape) #Resize the matrix and fill with zeros - returns "None" - why?

However, when I print the contents of my_sigma, I get "None". Can someone please
point me in the right direction, because I can not imagine that this should be
so complicated.

Thanks in advance for any help!

Casper

Graphical:

I have this:

[x x x]

I want this:

[x 0 0]
[0 x 0]
[0 0 x]
[0 0 0]
[0 0 0]
[0 0 0] - or some similar size, but the diagonal elements are important.
  • 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-05-29T16:11:33+00:00Added an answer on May 29, 2026 at 4:11 pm

    sigma.resize() returns None because it operates in-place. np.resize(sigma, shape), on the other hand, returns the result but instead of padding with zeros, it pads with repeats of the array.

    Also, the shape() function returns the shape of the input. If you just want to predefine a shape, just use a tuple.

    import numpy as np
    ...
    shape = (6, 6) #This will be some pre-determined size
    sigma = np.diag(S) #diagonalise the matrix - this works
    sigma.resize(shape) #Resize the matrix and fill with zeros
    

    However, this will first flatten out your original array, and then reconstruct it into the given shape, destroying the original ordering. If you just want to “pad” with zeros, instead of using resize() you can just directly index into a generated zero-matrix.

    # This assumes that you have a 2-dimensional array
    zeros = np.zeros(shape, dtype=np.int32)
    zeros[:sigma.shape[0], :sigma.shape[1]] = sigma
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having an issue here that I have tried everything I can think of but
This should be quite simple really - not sure what the problem is. I
I came across an issue that makes me think there is bug in the
I think that business logic should exist in a model when using an MVC
I think that this problem can be sorted using reflection (a technology which I'm
I'm having problems getting a simple URL to tokenize properly so that you can
I have a simple script that should cause one of three divs to be
I have heard several people claiming that you can not scale the JVM heap
I'm having an issue mapping what I would think is a fairly simple association.
I'm looking for a way to create a simple HTML table that can be

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.