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

The Archive Base Latest Questions

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

If I have an 1D numpy.ndarray b and a Python function f that I

  • 0

If I have an 1D numpy.ndarray b and a Python function f that I want to vectorize, this is very easy using the numpy.vectorize function:

c = numpy.vectorize(f)(a).

But if f returns a 1D numpy.ndarray instead of a scalar, how can I build a 2D numpy.ndarray instead? (That is, I want every 1D numpy.ndarray returned from f to become a row in the new 2D numpy.ndarray.)

Example:

def f(x):
    return x * x

a = numpy.array([1,2,3])
c = numpy.vectorize(f)(a)

def f_1d(x):
    return numpy.array([x, x])

a = numpy.ndarray([1,2,3])
d = ???(f_1d)(a)

In the above example c would become array([1, 4, 9]). What should ??? be replaced with if d should become array([[1, 1], [2, 2], [3, 3]])?

  • 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-14T21:10:51+00:00Added an answer on June 14, 2026 at 9:10 pm

    Could do this instead:

    def f_1d(x):
        return (x,x)
    d = numpy.column_stack(numpy.vectorize(f_1d)(a))
    

    will output:

    array([[1, 1],
           [2, 2],
           [3, 3]])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function using a quantum simulation class QuTIP that returns a
I have a numpy array like this a = np.array(1) Now if I want
I have two numpy arrays that are OpenCV convex hulls and I want to
I'm fairly new to Python, and very new to Numpy. So far I have
I have some python code which generates a 256^3 numpy array of data that
In python I have numpy.ndarray called a and a list of indices called b
I've written a very simple python numpy code. It have a strange behavior... from
I have an object of type 'numpy.ndarray', called myarray, that when printed to the
I have seen some python functions that work generally receiving a (n,2) shaped numpy
I have a one-dimensional array of the type numpy.ndarray and I want to know

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.