By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,757 Members | 1,990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,757 IT Pros & Developers. It's quick & easy.

NameError: name 'b' is not defined

P: 1
Expand|Select|Wrap|Line Numbers
  1. >>> import numpy
  2. >>> def backsub(X, y):
  3.     l = shape(X)  
  4.     n = l[1]
  5.     X = mat("1. 2. 3.; 0. 3. 2.; 0. 0. 1.")
  6.     y = mat(" 2.; 4.; 5.")
  7.     b = zeros((n,1))
  8.     b[n-1, 0] = y[n-1, 0]/X[n-1, n-1]
  9.     for j in range(n-1,0,-1):
  10.         b[j-1,0] = (y[j-1,0] - dot(X[j-1, range(j,n)], b[range(j,n),0]))/X[j-1, j-1]
  11.     return b
  12. print (b)
Sep 7 '15 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 619
You should be able to debug this yourself by adding a few simple print statements to see what is executing and what is not. No offense intended, but it is a waste of everyones time to post this, and you don't want people ignoring your questions because they were like this one in the past. Post back if you can't find the error, posting the complete error message and code that shows that you have attempted to find the problem yourself.
Sep 7 '15 #2

Expert 100+
P: 619
And if you keyed this into the python interpreter on the console, use a text editor, https://wiki.python.org/moin/PythonEditors or IDLE (comes with python) so you can save the file, change it, run it again, etc.
Sep 7 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.