Giter Club home page Giter Club logo

introprog-exercises's People

Contributors

askernc avatar christianlangholzcarstensen avatar jeppedruedahl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

introprog-exercises's Issues

Persistent error in PS3

In the jupyter notebook

{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def assets_row_by_row(x,R,Y):\n",
" return 0 # wrong line\n",
" \n",
"def assets_all_at_once(income,consumption,R,Y):\n",
" return 0 # wrong line\n",
"\n",
"def assets_adj(assets,R,Y):\n",
" # missing lines\n",
" pass\n",
"\n",
"R = 1.2 # return rate\n",
"Y = 1 # income\n",
"try:\n",
" dt['assets_1'] = R*(dt['inc']-dt['con'])+Y\n",
" dt['assets_2'] = dt.apply(assets_row_by_row,axis=1,args=(R,Y))\n",
" dt['assets_3'] = assets_all_at_once(dt['inc'].values(),dt['con'].values(),R,Y)\n",
" dt['assets_4'] = dt['inc']-dt['con']\n",
" assets_adj(dt['assets_4'],R,Y)\n",
"except:\n",
" print('failed')\n",
"dt.head() "
]
},

In the solution

def assets_row_by_row(x,R,Y):
return R*(x['inc']-x['con'])+Y
def assets_all_at_once(income,consumption,R,Y):
return R*(income-consumption)+Y
def assets_adj(assets,R,Y):
assets *= R
assets += Y
R = 1.2 # return rate
Y = 1 # income
dt_true['assets_1'] = R*(dt_true['inc']-dt_true['con'])+Y
dt_true['assets_2'] = dt_true.apply(assets_row_by_row,axis=1,args=(R,Y))
dt_true['assets_3'] = assets_all_at_once(dt_true['inc'].values,dt_true['con'].values,R,Y)
dt_true['assets_4'] = dt_true['inc']-dt_true['con']
assets_adj(dt_true['assets_4'],R,Y)
dt_true.head()


Even if you copy the defined functions in the A10.py-program, the notebook will throw an error - if you run the code as follows,

Code

def assets_row_by_row(x,R,Y):
    return R*(x['inc']-x['con'])+Y
    
def assets_all_at_once(income,consumption,R,Y):
    return R*(income-consumption)+Y

def assets_adj(assets,R,Y):
    assets *= R
    assets += Y


R = 1.2 # return rate
Y = 1 # income
try:
    dt['assets_1'] = R*(dt['inc']-dt['con'])+Y
    dt['assets_2'] = dt.apply(assets_row_by_row,axis=1,args=(R,Y))
    dt['assets_3'] = assets_all_at_once(dt['inc'].values(),dt['con'].values(),R,Y)
    dt['assets_4'] = dt['inc']-dt['con']
    assets_adj(dt['assets_4'],R,Y)
except Exception as e:
    print(f'An error occurred: {e}')

dt.head()   

Error

An error occurred: 'numpy.ndarray' object is not callable

Why?

The subtle difference lies, I believe, in the use of df.values and df.values(), the latter uses numpy the former is pandas-syntax. Is this intended, so we are aware of this difference or is it a bug?

It took a while to debug, and now I am curious.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.