Clustering com numpy e cython
Upcoming SlideShare
Loading in...5
×
 

Clustering com numpy e cython

on

  • 1,717 views

 

Statistics

Views

Total Views
1,717
Views on SlideShare
1,203
Embed Views
514

Actions

Likes
0
Downloads
12
Comments
0

4 Embeds 514

http://pugpe.wordpress.com 503
https://pugpe.wordpress.com 5
http://translate.googleusercontent.com 4
url_unknown 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Clustering com numpy e cython Clustering com numpy e cython Presentation Transcript

  • Clustering com numpy e Cython Anderson Berg XIII Encontro do PUG-PE
  • Agrupamento de dados
  • K-Means
  • Matrizes
  • Exemplo simples>>> from numpy import *>>>a = arange(10).reshape(2,5)>>>aarray([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
  • Criação de arrays>>> a = array( [2,3,4] )>>> b = array( [ (1.5,2,3), (4,5,6) ] )>>> barray([[ 1.5, 2. , 3. ], [ 4. , 5. , 6. ]])>>> zeros( (3,4) )array([[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]])>>> ones( (2,3,4), dtype=int16 )array([[[ 1, 1, 1, 1], [ 1, 1, 1, 1], [ 1, 1, 1, 1]], [[ 1, 1,1, 1], [ 1, 1, 1, 1], [ 1, 1, 1, 1]]], dtype=int16)
  • Outras Operações>>> b = arange( 4 )>>> b**2array([0, 1, 4, 9])>>> a = random.random((2,3))>>> aarray([[ 0.6903007 , 0.39168346, 0.16524769], [ 0.48819875, 0.77188505, 0.94792155]])
  • Ainda outras operações>>> a.sum()3.4552372100521485>>> a.min()0.16524768654743593>>> a.max()0.9479215542670073>>> a[:,1]array([0.39168346, 0.77188505])>>> sum(a[:,1])1.1635685099999999
  • Primeiros Passoshelloworld.pyx:print "Hello World"setup.py:from distutils.core import setupfrom distutils.extension import Extensionfrom Cython.Distutils import build_extsetup( cmdclass = {build_ext: build_ext}, ext_modules = [Extension("helloworld",["helloworld.pyx"])] )$ python setup.py build_ext --inplace>>> import helloworldHello World
  • Advanced Modedef primes(int kmax): cdef int n, k, i cdef int p[1000] result = [] if kmax > 1000: kmax = 1000 k = 0 n = 2 while k < kmax: i = 0 while i < k and n % p[i] != 0: i = i + 1 if i == k: p[k] = n k = k + 1 result.append(n) n = n + 1 return result
  • Sem Cython Com Cython
  • Clustering com numpy e Cython Anderson Berg - @berg_pe XIII Encontro do PUG-PE