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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:22:17+00:00 2026-05-20T08:22:17+00:00

import numpy as np def L2Norm(f, x, y, d=0.00001): dudx = (f(x+d,y) – f(x-d,y))

  • 0
import numpy as np
def L2Norm(f, x, y, d=0.00001):
    dudx = (f(x+d,y) - f(x-d,y)) / (2*d) 
    dudy = (f(x,y+d) - f(x,y-d)) / (2*d)
    L2Norm = np.float128(np.sqrt(dudx**2 + dudy**2))
return L2Norm

def f(x,y):
    return np.float128((1.0 + np.sin(np.pi*x))*((3.0 + np.cos(2.011*y))**2)*np.e**((-x**2)-((y**2)/4)))

# 20 points in X direction
x = np.linspace(-1.0,1.0,20)
# 40 points in Y direction
y = np.linspace(-2.0,2.0,40)
[X,Y] = np.meshgrid(x,y)
L2_Norm = L2Norm(f, X, Y)
print L2_Norm[37,13]

My function is above. Basically, I would expect to call the function L2Norm and get an array going from 0 to 19 in the X direction, or first index and 0 to 39 in the second.

Instead, it seems like the first index now corresponds to where I would expect y to be.

I can call
L2_Norm[39,19]
but not
L2_Norm[19,39]
Why is this?

  • 1 1 Answer
  • 2 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-20T08:22:17+00:00Added an answer on May 20, 2026 at 8:22 am

    If you call L2_Norm.shape, you’ll see that the dimensions of the array is (40,20) so as the error states, L2_Norm[19,39] is out of range because 39 > the max index in that dimension of 19. Take a look at the shape of X and Y as well to see why L2_Norm has the shape that it does — the reason is clear if you look in the meshgrid documentation:

    For vectors x, y with lengths
    Nx=len(x) and Ny=len(y), return X, Y
    where X and Y are (Ny, Nx) shaped
    arrays
    with the elements of x and y
    repeated to fill the matrix along the
    first dimension for x, the second for
    y.

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

Sidebar

Related Questions

I have the following code: import numpy def numpysum(n): a = numpy.arange(n) ** 2
import numpy a = numpy.array([20090913, 20101020, 20110125]) Can you explain why numpy.datetime64(a.astype(S8).tolist()) converts correctly
In the following example In [8]: import numpy as np In [9]: strings =
I have installed Numpy using ActivePython and when I try to import numpy module,
The textbook examples of multiple unpacking assignment are something like: import numpy as NP
In short: I have two matrices (or arrays): import numpy block_1 = numpy.matrix([[ 0,
Suppose I have a recarray such as the following: import numpy as np #
When I run this simple code: from pylab import * import numpy as np
What's wrong with this snippet of code? import numpy as np from scipy import
why do the following lines not work as I expect? import numpy as np

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.