Coder Social home page Coder Social logo

cookbook-code's People

Contributors

akarve avatar bcsharp avatar dspyrhsu avatar j9ac9k avatar keik avatar moble avatar rossant avatar shivangim avatar skwbc avatar

Stargazers

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

Watchers

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

cookbook-code's Issues

Vispy Code (6.6) Error

In the 6th python cell:

program['a_position'] = np.c_[
        np.linspace(-1.0, +1.0, 1000),
        np.random.uniform(-0.5, +0.5, 1000)]

results in:

TypeError: data must be 32-bit not float64

I may mess with this later, but I know next to nothing about vispy so I'm not sure how well I can troubleshoot the issue.

Failed to start the Kernel

when i start notebook, there's a error in my console as follow
image

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/notebook/base/handlers.py", line 437, in wrapper
    result = yield gen.maybe_future(method(self, *args, **kwargs))
  File "/Library/Python/2.7/site-packages/notebook/services/sessions/handlers.py", line 56, in post
    model = sm.create_session(path=path, kernel_name=kernel_name)
  File "/Library/Python/2.7/site-packages/notebook/services/sessions/sessionmanager.py", line 66, in create_session
    kernel_name=kernel_name)
  File "/Library/Python/2.7/site-packages/notebook/services/kernels/kernelmanager.py", line 84, in start_kernel
    **kwargs)
  File "/Library/Python/2.7/site-packages/jupyter_client/multikernelmanager.py", line 109, in start_kernel
    km.start_kernel(**kwargs)
  File "/Library/Python/2.7/site-packages/jupyter_client/manager.py", line 244, in start_kernel
    **kw)
  File "/Library/Python/2.7/site-packages/jupyter_client/manager.py", line 190, in _launch_kernel
    return launch_kernel(kernel_cmd, **kw)
  File "/Library/Python/2.7/site-packages/jupyter_client/launcher.py", line 124, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

how can I fix it ?

my mac's info:

image

Update book release info

Every recipe ends with a footer:

You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).

Since the book has been already published, I suggest changing it to a link to the book description/publication info.

Issue with explanation of shared memory in 01_numpy_performance

Thanks for writing the cookbook and sharing it online. This is certain to become a great resource for our users.

In cookbook 01_numpy_performance, it is recommended to use x.__array_interface__['data'][0] to determine if an array is sharing data with another array. This is only useful if the offset of the arrays are the same, not if one array is a subarray/slice/view of another.

For example, here, two arrays are sharing the same data but they have different starting pointers.

In [1]: import numpy as np

In [2]: x = np.arange(10)

In [3]: y = x[1::2]

In [4]: x.__array_interface__['data'][0]
Out[4]: 46090608

In [5]: y.__array_interface__['data'][0]                                                                                                                                                                                            
Out[5]: 46090616

You could probably figure out that their data areas are overlapping, but that’s kind of expensive/complex.

The best way I’ve found to find out if two arrays share the same data:

def get_data_base(arr):
    base = arr.base
    while base is not None:
        base = base.base
    return base

>>> get_data_base(x) is get_data_base(y)
True

Errors in http://ipython-books.github.io/featured-03/

A few issues:
Step 2: make sure to actually use "g = nx.read_shp("data/tl_2013_06_prisecroads.shp", simplify =False)". Without setting simplify to False, grid-like road structures become completely broken graphs. This is extremely important when using open street map data for example.

Step 3: to get the maximally connected subgraph, use the command 'max(nx.connected_component_subgraphs(g.to_undirected()), key=len)'

Step 7: Since the "JSON" coordinates are in the form (lon,lat), you are actually passing the wrong set to the geocalc function. Change to 'return np.sum(geocalc(path[1:,1],path[1:,0],path[:-1,1],path[:-1,0]))'. Surprisingly, the path it finds is nearly the same, and the distance is only a bit different.

Chopped values in the energy-minimization example

One of the featured recipes is this nice energy-minimization problem. But I think the final plot is missing some really interesting features. In particular, the function that plots the spring bar contains the line

color=plt.cm.copper(c*150))

This means that negative values (corresponding to compression of the spring, rather than extension) don't get any special coloring -- they get chopped. If you allow for negative values, you can see those compressed springs:

image

You can see that the lower springs near the wall are very compressed, and the diagonal ones get some compression as well. I think that's too interesting to ignore! :)

The simplest way to deal with this would just be

color=plt.cm.copper(abs(c*150)))

But that wouldn't show you which springs are compressed and which are extended. To get the plot above, I defined a new color function

def spring_color_map(c):
    min_c, max_c = -0.00635369422326, 0.00836362559722
    ratio = (max_c-c) / (max_c-min_c)
    color = plt.cm.coolwarm(ratio)
    shading = np.sqrt(abs(ratio-0.5)*2)
    return (shading*color[0], shading*color[1], shading*color[2], color[3])

and then in the plotting function, I did

color=spring_color_map(c)

AttributeError: 'VispyWidget' object has no attribute 'on_msg'


AttributeError Traceback (most recent call last)
in ()
----> 1 c.show()
2 app.run();

f:\anaconda3\vispy-master\vispy\app\canvas.py in show(self, visible, run)
427 Run the backend event loop.
428 """
--> 429 self._backend._vispy_set_visible(visible)
430 if run:
431 self.app.run()

f:\anaconda3\vispy-master\vispy\app\backends_ipynb_webgl.py in _vispy_set_visible(self, visible)
206 return
207 if self._widget is None:
--> 208 self._widget = VispyWidget()
209 self._widget.set_canvas(self._vispy_canvas)
210 display(self._widget)

f:\anaconda3\vispy-master\vispy\app\backends\ipython_widget.py in init(self, **kwargs)
60 def init(self, **kwargs):
61 super(VispyWidget, self).init(**kwargs)
---> 62 self.on_msg(self.events_received)
63 self.canvas = None
64 self.canvas_backend = None

AttributeError: 'VispyWidget' object has no attribute 'on_msg'

re notebook: 07_webcam_py3 ShimWarning

error on running the first cell:
ShimWarning: The IPython.html package has been deprecated. You should import from notebook instead. IPython.html.widgets has moved to ipywidgets.
"IPython.html.widgets has moved to ipywidgets.", ShimWarning)
/home/dgd/.local/lib/python3.5/site-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
warn("IPython.utils.traitlets has moved to a top-level traitlets package.")

Depreciated warning in Section 1 > Recipe 2

Run pd.rolling_mean(df['Berri1'], n).dropna().plot(); and you get


/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py:6: FutureWarning: pd.rolling_mean is deprecated for Series and will be removed in a future version, replace with 
    Series.rolling(window=15,center=False).mean()

How can you do the replacement with Series.rolling(...).mean()?

bokeh API changed

I've just installed bokeh 0.8.2 (the version pip finds). The 'line' and 'scatter' functions are now methods of a figure object, so in notebook chapter06/03_bokeh I had to change the first example to:

p = bkh.figure(title="random data", x_axis_label='x', y_axis_label='y')
p.line(x, y, line_width=5)
bkh.show(p)

and the second to:

p = bkh.figure(title="flower petal shapes by color", x_axis_label='petal_length', y_axis_label='petal_width')
p.scatter(flowers["petal_length"],
flowers["petal_width"],
color=flowers["color"],
fill_alpha=0.25, size=10,)
bkh.show(p)

Change in widgets in IPython 3.0

As reported by one user:

Page: 19 & 20

In the example that begins:

"10. Now, we illustrate the latest interactive features in IPython 2.0+,
namely JavaScript widgets."

I had to change the world 'values' to 'options' in

dw = DropdownWidget(values=OrderedDict([

and

dw.value = dw.values['SciPy 2013'].

Using IPython 3.1.0, Python 2.7.9.

IPython 3.0 updates

  • Update widget instructions
  • Check other potential IPython changes
  • Test with the latest versions of the other dependencies

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.