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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:44:41+00:00 2026-06-09T11:44:41+00:00

I do not know the right way to import modules. I have a main

  • 0

I do not know the right way to import modules.

I have a main file which initializes the code, does some preliminary calculations etc.
I also have 5 functions f1, f2, … f5. The main code and all functions need Numpy.

If I define all functions in the main file, the code runs fine.
(Importing with : import numpy as np)

If I put the functions in a separate file, I get an error:
Error : Global name 'linalg' is not defined.

What is the right way to import modules such that the functions f1 – f5 can access the Numpy functionality?

  • 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-09T11:44:42+00:00Added an answer on June 9, 2026 at 11:44 am

    As other answers say, you need to import numpy into each file where you call a Numpy function. However you don’t need to import it into the main module if you’re not using it in the main module. Here’s a simple example. Imagine you have a file with your function in it called myFunc.py
    myFunc.py:

    import numpy as np
    
    def f1(a):  # a is a numpy multidimensional array
        z = np.array(a)
        flat = z.ravel()
        flat = flat.tolist()
    
        return flat     
    

    Then in your main file you can do something like this

    import myFunc as mf
    
    mf.f1([[4,67,8],[7,9,7]])
    

    Your output will be:

    [4, 67, 8, 7, 9, 7]
    

    So you pass a list to your function, convert it to a numpy array in your function, then return the answer as a list. If you return a numpy array you’ll get an error.

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

Sidebar

Related Questions

I have a situation, don't know if my approach is right or not please
I do not know javascript right now but I am planning on learning it.
I tried searching for information on this, but must not know the right terms
I know this is simple but I am not able to get it right
I don't know if I am on right track or not still asking this
I don't know if it's right to ask this question here or not. I'm
All right, do not get angry now, I know there are several questions about
EPD python does not know to look for the Ubuntu repository python so installing
I want to know how to profile my code. I have gone through the
Let's Say I Have This Class: package{ import flash.display.Sprite; public class Main extends Sprite{

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.