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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:21:33+00:00 2026-05-31T18:21:33+00:00

I am puzzled: class lin_reg: def __init__(self): ”’ Executes the program ”’ Indep_Array, Dep_Array

  • 0

I am puzzled:

class lin_reg:

     def __init__(self):
    ''' Executes the program '''

    Indep_Array, Dep_Array = self.Prob_Def()
    Total_Array = Indep_Array.append(Dep_Array)
    print Indep_Array, Dep_Array, Total_Array
    NumArray = len(Total_Array)

def Prob_Def(self):

    Analy_Type = raw_input('Type of Regression(linear-n,nonlinear-nl): ')
    Num_IndepVar = eval(raw_input('Number of Independent Variables: '))
    Indep_Array = []
    for IndepVar in range(Num_IndepVar):
        ArrayInput = eval(raw_input('Enter the array: '))
        Indep_Array.append(ArrayInput)
    Dep_Array = eval(raw_input('Enter the dependent array: '))
    return Indep_Array, Dep_Array

When I run this code, I get output as follows:

obs=lin_reg.lin_reg()
Type of Regression(linear-n,nonlinear-nl): nl
Number of Independent Variables: 3
Enter the array: [1,2,3]
Enter the array: [2,3,4]
Enter the array: [3,4,5]
Enter the dependent array: [5,6,7]
[[1, 2, 3], [2, 3, 4], [3, 4, 5], [5, 6, 7]] [5, 6, 7] None

Traceback (most recent call last):
  File "<pyshell#18>", line 1, in <module>
    obs=lin_reg.lin_reg()
  File "C:\Python27\DataAnalysis\lin_reg.py", line 13, in __init__
    NumArray=len(Total_Array)
TypeError: object of type 'NoneType' has no len()

How is the dependent array Dep_Array automatically appended to Indep_Array and why is Total_Array returning None?

I was expecting to see output like this for above input:
[[1,2,3],[2,3,4],[3,4,5]] [5,6,7] [[1,2,3],[2,3,4],[3,4,5],[5,6,7]]

  • 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-31T18:21:34+00:00Added an answer on May 31, 2026 at 6:21 pm

    .append modifies the original list and returns None. You want +.

    I’ve taken the liberty of rewriting your code to how Python should look.

    class lin_reg(object):
         def __init__(self):
             self.indep, self.dep = self.initialise_from_user()
             self.total = self.indep + self.dep
             print self.indep, self.dep, self.total
             self.n = len(self.total)
    
    def initialise_from_user(self):
        analysis_type = raw_input('Type of Regression(linear-n,nonlinear-nl): ')
        n = int(raw_input('Number of Independent Variables: '))
    
        indep = [np.matrix(raw_input('Enter the array: ')) for _ in range(self.n)]
        dep =  np.matrix(raw_input('Enter the dependent array: '))
    
        return indep, dep
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code got me really puzzled. class class AVLTree { private: struct AVLNode
I'm puzzled about iOS memory management. I have a class that has a member
I'm puzzled by what appears to be a quirk of the .NET CryptoStream class:
In a program I am using two external jar libraries. There is a class
I am really puzzled by this. I believe I am managing memory the correct
I'm a bit puzzled: From Cocoa Programming For Mac OS X (page 63, 3rd
I am puzzled. I looked at the trace of a pagecall that was slow
I'm a little puzzled with QueryStrings and ActionResult I have a URL coming in
okay...im really puzzled with this. I want to create a regular asp.net webforms website
I am a bit puzzled with my Regex results (and still trying to get

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.