SICP – cap. 2 – cosa s’intende per dati? – esercizi – 9

mib2

Oggi qui, continuando da qui.

Exercise 2.6: In case representing pairs as procedures wasn’t mind-boggling enough, consider that, in a language that can manipulate procedures, we can get by without numbers (at least insofar as nonnegative integers are concerned) by implementing 0 and the operation of adding 1 as

(define zero (lambda (f) (lambda (x) x)))

(define (add-1 n)
  (lambda (f) (lambda (x) (f ((n f) x)))))

This representation is known as Church numerals, after its inventor, Alonzo Church, the logician who invented the λ-calculus.

Define one and two directly (not in terms of zero and add-1). (Hint: Use substitution to evaluate (add-1 zero)). Give a direct definition of the addition procedure + (not in terms of repeated application of add-1).

Devo confessare che non ci sono riuscito 👿
Ho provato per un po’ ma non sono andato oltre a questo:

s155

che è solo la verifica che zero e add-1 sono procedure correttamente definite. In questi casi attivo il liz-segnale e arriva Bill the Lizard 😄 che risolve spiegando tutto.

È tutto di là, riporto solo il risultato, semplicissimo (una volta fatto 😜), questo

(define one
  (lambda (f) (lambda (x) (f x))))

s156

A questo punto diventa semplice definire two, basta chiamare una volta in più la f dentro lambda:

(define two
  (lambda (f) (lambda (x) (f (f x)))))

s157

Di lì Bill generalizza per i numeri successivi, Bill davvero über-rockz 😄.

Una cosa simile anche da sicp-ex e Spaceman Aki ma manca la spiegazione.

SICP a volte è troppo impegnativo per me. O dovrei essere più motivato, sapere di dover passare l’esame, senza l’aiuto di Bill &co.

:mrgreen:

Arrotondamento con Octave e bc

nikon-small-world-scales-of-a-butterfly-wing

Post che interessa probabilmente solo me, perso(nale), ma mi devo anche autogiustificare per tempo perso per chissà quale errore (mio) 😡
Ieri mi sono perso a rifare con Octave una cosa elementare, c’è e funziona perfettamente con il foglio di calcolo (tipo Excel) di Libre Office.
Forse è uno skill che ho acquisito nel tempo: quando sono sotto pressione, con qualcuno che ti fa fretta, “è pronto?”, “quanto ci vuole?” non riesco a produrre niente di buono. E se, come ieri, non si lavora nello stesso ufficio la situazione peggiora, diventa più macchinoso confrontarsi, scambiarsi le opinioni.
OK, finito il pippone ecco la soluzione in due versioni. Una premessa: uso il terminale (sono l’unico) ma ovviamente è per l’ambiente integrato. Inoltre ho il solito (mio) alias:

a-1

Il problema –semplicissimo– è di arrotondare un numero, float, alla seconda cifra decimale. È poi immediata la generalizzazione a qualsiasi altra cifra.
La prima soluzione, quella usuale è di moltiplicare il numero per 100, convertirlo in intero (in realtà no per Octave ma diventa intero nel senso che perde la parte decimale) e infine dividerlo per 100. Così:

a0

La verifica visualizza che il nuovo numero, na, sia davvero senza coda. L’operazione potrebbe sembrare perversa ma ci sono dei casi in cui si devono fare somme e moltiplicazioni nelle quali il risultato dev’essere “esatto” 👽

Un approccio diverso è quello di trasformare il numero in stringa formattandola con una funzione della famiglia di printf e poi ricavare il numero dalla stringa ottenuta, così:

a1

OK 😄 Semplice vero? eppure ieri non veniva 😡

E con bc? questione che ha deviato la discussione e –mysteryousamente– fatto evaporare il bug 😜

Al solito ho un alias, lo rimuovo per essere standard

b0

Chi non è abituato a Linux trova cose strane: solo interi! Ma è subito pronta l’opzione, via scale, numero di cifre decimali:

b1

Solo che non fa quello che si vuole: invece dell’arrotondamento si ha il troncamento 😯
Ma, come si faceva anticamente in Fortran, basta aggiungere mezzo centesimo al numero da arrotondare e tutto torna (vero Giòrs? (chissà se mi legge)).

b2

Notare che la divisione per 1 in questo caso è richiesta. Uh poteva essere anche una moltiplicazione 😜

Una particolarità di bc che sorprende i nuovi: il risultato è corretto per quante cifre si vuole ma non per tutte quelle visualizzate. Ecco l’esempio con π, calcolato come si faceva –OOPS! 😯  già detto– a() è l’arcotangente.

b3

Per quel che ne so basta non fidarsi delle ultime 2.

Lo so che è un post perso, ma mi sono sfogato. Voi non leggetelo.

:mrgreen:

cit. & loll – 31

Giovedì e allora… ecco 😊

ogeexrwt-ktzd-u110012925576919cg-1024x576lastampa-it

Ils sont où les tests ?
::: CommitStrip

This is my new favorite comic
::: ml_barnett

Tu sei bravo con i software. Sei portato naturalmente. Come fai?
::: grostein

I like this story
::: ThePracticalDev

Software reuse is more like an organ transplant than snapping together Lego blocks
::: CompSciFact

clwn-cauoaawvnn

New Donald Trump programming language seeks to make programming great again
::: Functionalworks

Your software architecture when you started the project…
::: ico_TC

If you watch a video of a tree falling in a forest and it doesn’t make a sound
misteryousassay, anzi di più 👽
::: SwiftOnSecurity

Dopo gli ultimi attacchi #hacker sembra sia stata bandita la password 123456 dagli enti pubblici
::: Genjuro75

Farsi deridere in tutto il mondo
::: fabiochiusi

icon_window_unhappy

Engineers On Google’s Self-Driving Car Project Were Paid So Much That They Quit
da noi una cosa simile non si usa, mai 😀
::: Slashdot

Old Gold
vechia ma sempre bella 😜
::: 9GAGTweets

Human projection on the future of artificial intelligence uptake
::: EricTopol

Cards Against Developers
::: ThePracticalDev

Size matters
::: mpietropoli

c4o2fnkueaa0rgs

Modern Software Development
::: manisha72617183

Chissà, magari un fax
::: Didonezombie

It’s so hard to use
::: CompSciFact

Declared my income tax for 2016 today
::: TaaviRoivas

juggler

NumPy – 12 – Le basi degli arrays di NumPy – 1

larry

Copio qui, continuando da qui.

Data manipulation in Python is nearly synonymous with NumPy array manipulation: even newer tools like Pandas (Chapter 3 [prossimamente]) are built around the NumPy array. This section will present several examples of using NumPy array manipulation to access data and subarrays, and to split, reshape, and join the arrays. While the types of operations shown here may seem a bit dry and pedantic, they comprise the building blocks of many other examples used throughout the book. Get to know them well!

We’ll cover a few categories of basic array manipulations here:

  • Attributes of arrays: Determining the size, shape, memory consumption, and data types of arrays
  • Indexing of arrays: Getting and setting the value of individual array elements
  • Slicing of arrays: Getting and setting smaller subarrays within a larger array
  • Reshaping of arrays: Changing the shape of a given array
    Joining and splitting of arrays: Combining multiple arrays into one, and splitting one array into many

Attributi degli arrays di NumPy
First let’s discuss some useful array attributes. We’ll start by defining three random arrays, a one-dimensional, two-dimensional, and three-dimensional array. We’ll use NumPy’s random number generator, which we will seed with a set value in order to ensure that the same random arrays are generated each time this code is run:

np68

Each array has attributes ndim (the number of dimensions), shape (the size of each dimension), and size (the total size of the array):

np69

Another useful attribute is the dtype, the data type of the array (which we discussed previously [post precedente]):

np70

Other attributes include itemsize, which lists the size (in bytes) of each array element, and nbytes, which lists the total size (in bytes) of the array:

np71

Indicizzazione degli arrays, accedere singoli elementi
If you are familiar with Python’s standard list indexing, indexing in NumPy will feel quite familiar. In a one-dimensional array, the ith value (counting from zero) can be accessed by specifying the desired index in square brackets, just as with Python lists:

np72

To index from the end of the array, you can use negative indices:

np73

In a multi-dimensional array, items can be accessed using a comma-separated tuple of indices:

np74

Values can also be modified using any of the above index notation:

np75

Keep in mind that, unlike Python lists, NumPy arrays have a fixed type. This means, for example, that if you attempt to insert a floating-point value to an integer array, the value will be silently truncated. Don’t be caught unaware by this behavior!

np76

La storia è ancora lunga, pausa 😉

:mrgreen:

SICP – cap. 2 – cosa s’intende per dati? – esercizi – 8

nikon-small-world-mouse-retinal-ganglion-cells

Continuo a copiare, oggi qui.

Exercise 2.5: Show that we can represent pairs of nonnegative integers using only numbers and arithmetic operations if we represent the pair a and b as the integer that is the product 2a3b. Give the corresponding definitions of the procedures cons, car, and cdr.

Panico! 👽  Mica sicuro di aver capito cosa si vuole che faccia 😯

La prima parte è semplice:

s152

Meno facile dal numero ottenuto ricavare i componenti a e b. Serve l’equivalente del comando di sistema factor:

s153

Devo determinare quante volte il numero è divisibile per 2 e 3, ahemmm, l’ha fatto uno dei miei nerds

(define (num-divs n d)
  (define (iter x result)
    (if (= 0 (remainder x d))
        (iter (/ x d) (+ 1 result))
        result))
  (iter n 0))

Applicando num-divs per 2 e 3 si ottiene la coppia –pair– di (a . b):

(define (pair num)
  (cons (num-divs num 2)
        (num-divs num 3)))

ho raccolto le due procedure nel file get-pair.rkt, ottengo:

s154

😄 Per avere a e b basta usare car e cdr della pair ottenuta, banale, non la riporto.

Da Bill the Lizard ho preso num-divs, più pulita della mia.
sicp-ex costruisce la funzione exp invece di usare expt built-in; poi diventa quasi normale.
La soluzione migliore è quella di Spaceman Aki, usa anche lui la funzione built-in remainder (ah! saperlo ricordarlo 💥).
Una soluzione simile anche da Drewiki.

:mrgreen:

Ecco un nuovo blog da seguire

banner
Alle volte —sapete il tempo, la politica, la configurazione strologica, whatever— potrebbe anche venirmi il cattivo umore.
Poi scopro ‘na roba nuova fatta anche pensando a me e allora mi dico OK 🎶 , Leibniz aveva kwasy ragione, viviamo in un mondo non necessariamente il migliore possibile ma comunque uno che tutto sommato può andare 🍓

Oggi per esempio un nuovo blog di —‘spetta che il nick è <come dire>CS PRIO30.

tit
Il blog è qui: Yet another wannabe programming blog, completo di About (cosa che tanti si dimenticano), CS PRIO30 no, l’ha messo subito, rockz! 🚀  E c’è anche il Git, con il codice dentro 🚀

Insomma auguri al nuovo blogger 💥 e non devo certo dirvelo io di seguirlo, vero? 😜

:mrgreen:

NumPy – 11 – Comprendere i tipi di dati in Python

c4q

Continuando da qui copio qui.

Un post teorico, mi sa che per capirci qualcosa quando lo rivedrò devo copiare tutto –o almeno parecchio 😙

Effective data-driven science and computation requires understanding how data is stored and manipulated. This section outlines and contrasts how arrays of data are handled in the Python language itself, and how NumPy improves on this. Understanding this difference is fundamental to understanding much of the material throughout the rest of the book.

Users of Python are often drawn-in by its ease of use, one piece of which is dynamic typing. While a statically-typed language like C or Java requires each variable to be explicitly declared, a dynamically-typed language like Python skips this specification. For example, in C you might specify a particular operation as follows:

/* C code */
int result = 0;
for(int i=0; i<100; i++){
    result += i;
}

While in Python the equivalent operation could be written this way:

# Python code
result = 0
for i in range(100):
    result += i

Notice the main difference: in C, the data types of each variable are explicitly declared, while in Python the types are dynamically inferred. This means, for example, that we can assign any kind of data to any variable:

# Python code
x = 4
x = "four"

Here we’ve switched the contents of x from an integer to a string. The same thing in C would lead (depending on compiler settings) to a compilation error or other unintented consequences:

/* C code */
int x = 4;
x = "four";  // FAILS

This sort of flexibility is one piece that makes Python and other dynamically-typed languages convenient and easy to use. Understanding how this works is an important piece of learning to analyze data efficiently and effectively with Python. But what this type-flexibility also points to is the fact that Python variables are more than just their value; they also contain extra information about the type of the value. We’ll explore this more in the sections that follow.

L’integer di Python è più di un integer
The standard Python implementation is written in C. This means that every Python object is simply a cleverly-disguised C structure, which contains not only its value, but other information as well. For example, when we define an integer in Python, such as x = 10000, x is not just a “raw” integer. It’s actually a pointer to a compound C structure, which contains several values. Looking through the Python 3.4 source code, we find that the integer (long) type definition effectively looks like this (once the C macros are expanded):

struct _longobject {
    long ob_refcnt;
    PyTypeObject *ob_type;
    size_t ob_size;
    long ob_digit[1];
};

A single integer in Python 3.4 actually contains four pieces:

  • ob_refcnt, a reference count that helps Python silently handle memory allocation and deallocation
  • ob_type, which encodes the type of the variable
  • ob_size, which specifies the size of the following data members
  • ob_digit, which contains the actual integer value that we expect the Python variable to represent.

This means that there is some overhead in storing an integer in Python as compared to an integer in a compiled language like C, as illustrated in the following figure:

np54

Here PyObject_HEAD is the part of the structure containing the reference count, type code, and other pieces mentioned before.

Notice the difference here: a C integer is essentially a label for a position in memory whose bytes encode an integer value. A Python integer is a pointer to a position in memory containing all the Python object information, including the bytes that contain the integer value. This extra information in the Python integer structure is what allows Python to be coded so freely and dynamically. All this additional information in Python types comes at a cost, however, which becomes especially apparent in structures that combine many of these objects.

La list di Python è più di una list
Let’s consider now what happens when we use a Python data structure that holds many Python objects. The standard mutable multi-element container in Python is the list. We can create a list of integers as follows:

np55

Because of Python’s dynamic typing, we can even create heterogeneous lists:

np56

But this flexibility comes at a cost: to allow these flexible types, each item in the list must contain its own type info, reference count, and other information –that is, each item is a complete Python object. In the special case that all variables are of the same type, much of this information is redundant: it can be much more efficient to store data in a fixed-type array. The difference between a dynamic-type list and a fixed-type (NumPy-style) array is illustrated in the following figure:

np57

At the implementation level, the array essentially contains a single pointer to one contiguous block of data. The Python list, on the other hand, contains a pointer to a block of pointers, each of which in turn points to a full Python object like the Python integer we saw earlier. Again, the advantage of the list is flexibility: because each list element is a full structure containing both data and type information, the list can be filled with data of any desired type. Fixed-type NumPy-style arrays lack this flexibility, but are much more efficient for storing and manipulating data.

Fixed-type arrays in Python
Python offers several different options for storing data in efficient, fixed-type data buffers. The built-in array module (available since Python 3.3) can be used to create dense arrays of a uniform type:

np58

Here 'i' is a type code indicating the contents are integers.
Much more useful, however, is the ndarray object of the NumPy package. While Python’s array object provides efficient storage of array-based data, NumPy adds to this efficient operations on that data. We will explore these operations in later sections; here we’ll demonstrate several ways of creating a NumPy array.
We’ll start with the standard NumPy import, under the alias np:

np59

Creare arrays da liste Python
First, we can use np.array to create arrays from Python lists:

np60

Remember that unlike Python lists, NumPy is constrained to arrays that all contain the same type. If types do not match, NumPy will upcast if possible (here, integers are up-cast to floating point):

np61

If we want to explicitly set the data type of the resulting array, we can use the dtype keyword:

np62

Finally, unlike Python lists, NumPy arrays can explicitly be multi-dimensional; here’s one way of initializing a multidimensional array using a list of lists:

np63

The inner lists are treated as rows of the resulting two-dimensional array.

Creare nuovi arrays
Especially for larger arrays, it is more efficient to create arrays from scratch using routines built into NumPy. Here are several examples:

np64

e –mica finito 😉

np65

e ancora

np66

e infine

np67

Tipi standard di NumPy
NumPy arrays contain values of a single type, so it is important to have detailed knowledge of those types and their limitations. Because NumPy is built in C, the types will be familiar to users of C, Fortran, and other related languages.

The standard NumPy data types are listed in the following table. Note that when constructing an array, they can be specified using a string:

np.zeros(10, dtype='int16')

Or using the associated NumPy object:

np.zeros(10, dtype=np.int16)

Data type  Description
bool_      Boolean (True or False) stored as a byte
int_       Default integer type (same as C long; normally either int64 or int32)
intc       Identical to C int (normally int32 or int64)
intp       Integer used for indexing (same as C ssize_t; normally either int32 or int64)
int8       Byte (-128 to 127)
int16      Integer (-32768 to 32767)
int32      Integer (-2147483648 to 2147483647)
int64      Integer (-9223372036854775808 to 9223372036854775807)
uint8      Unsigned integer (0 to 255)
uint16     Unsigned integer (0 to 65535)
uint32     Unsigned integer (0 to 4294967295)
uint64     Unsigned integer (0 to 18446744073709551615)
float_     Shorthand for float64.
float16    Half precision float: sign bit, 5 bits exponent, 10 bits mantissa
float32    Single precision float: sign bit, 8 bits exponent, 23 bits mantissa
float64    Double precision float: sign bit, 11 bits exponent, 52 bits mantissa
complex_   Shorthand for complex128.
complex64  Complex number, represented by two 32-bit floats
complex128 Complex number, represented by two 64-bit floats

More advanced type specification is possible, such as specifying big or little endian numbers; for more information, refer to the NumPy documentation. NumPy also supports compound data types, which will be covered [prossimamente].

:mrgreen:

Visto nel Web – 274

Ecco che arriva la rassegna di cosa ho wisto nel Web 🍎

cqjjdtiwiaerndg

Mozilla Binds Firefox’s Fate To The Rust Language
#:linguaggi di programmazione #:ditte
::: Slashdot

Introduction to Computing – Explorations in Language, Logic, and Machines
#:programming, codice, snippet
::: b3h3m0th

Univac 1050-II console
#:storia
::: doctorow

View 360 Panorama Photos on Ubuntu with this Image Viewer Plugin
#:tools, componenti software
::: Genjuro75

Restore
#:Panic! 👿
::: Siamo Geek

c3_dg3vxaaa9py1

The new Tiny #Lisp Computer. Make your own!
#:lisp(s) #:hardware
::: RainerJoswig

getopt — Command Line Option Parsing
#:linguaggi di programmazione
::: doughellmann

Zen of Assembly Language – Free Knowledge, CS book n.2
#:linguaggi di programmazione
::: b3h3m0th

Milano, l’assessora arrivata da Microsoft rifiuta di fornire i redditi del 2015: l’Anac apre istruttoria
#:free open source software
::: Il Fatto Quotidiano

Try Raspberry Pi’s PIXEL OS on your PC
#:sistemi operativi
::: mrbyte72

c4fzjqcuyaaqhpp

The tiny ulisp not only runs on its own Tiny Lisp PCB
#:lisp(s)
::: RainerJoswig

Writing safer C with Clang address sanitizer
#:linguaggi di programmazione
::: ThePracticalDev

Build a self-contained computer you can program in Lisp on a single PCB
#:lisp(s) #:hardware
::: technoblogy

Predictability in pseudo-random number generators means hackable slot machines!
#:sicurezza, spionaggio, virus
::: MrHonner

#LogicielLibre : à la conquête du grand public
#:free open source software
::: zacchiro

111504363-765a19d0-a0f4-4f9e-b4ad-39e3a3cdd33a

Rocket has shipped a 0.2!
#:linguaggi di programmazione
::: rustlang

The 2017 roadmap for #rustlang
#:linguaggi di programmazione
::: rustlang

‘We Need Robots To Take Our Jobs,’ Veteran Tech Reporter John Markoff Explains Why
#:innovazioni, futuro
::: Slashdot

DC Inauguration Protestors Are Being Hit With Facebook Data Searches
#:social media #:sicurezza, spionaggio, virus
::: Slashdot

French Politician Uses Hologram To Hold Meetings In Two Cities At the Same Time
#:innovazioni, futuro
::: Slashdot

c4gbgpvwcaa_aqn

Basics of Compiler Design
#:manuali, how to
::: Datalogisk

NeXT: Steve Jobs’ dot.com IPO that Never Happened
#:storia
::: Computer History Museum

Yes, there is an #AI threat. But as Alan Bundy argues in @CACMmag, it’s stupid machines, not smart ones
#:artificial intelligence
::: TheOfficialACM

Top-mentioned books on Stack Overflow
#:manuali, how to
::: lizardbill

72% of ‘Anonymous’ Browsing History Can Be Attached To the Real User
#:sicurezza, spionaggio, virus
::: Slashdot

c4nlmbrwcaalojz

Goldman Sachs Automated Trading Replaces 600 Traders With 200 Engineers
#:innovazioni, futuro
::: Slashdot

happy to see that @creativecommons finally has an image search that is even more useful than @google image search
#:free open source software
::: paul_keller

The Data That Turned the World Upside Down
psychometrics, sometimes also called psychographics
#:dati, raccolta #:Web, Internet
::: nesistweets

Sony’s Latest Smartphone Camera Sensor Can Shoot At 1,000fps
#:dispositivi mobili
::: Slashdot

Compiler Design: Theory, Tools, and Examples
#:manuali, how to
::: b3h3m0th

bagna

What Elm and Rust Teach us About the Future
#:linguaggi di programmazione
::: ThePracticalDev

Five Ubuntu Unity Features You May Not Have Known About
#:tools, componenti software
::: dcavedon

The draft opinion on EU #copyright reform of the @EPCulture is out!
#:copyright
::: communia_eu

Why Has Cameroon Blocked the Internet?
quindi è fattibile di bloccare Internet e diffondere solo la verità (spesso post-) del Trump locale 😡
#:censura
::: Slashdot

Programmer Develops Phone Bot To Target Windows Support Scammers
#:sicurezza, spionaggio, virus
::: Slashdot

c4t3y

Wikipedia Bans Daily Mail As ‘Unreliable’ Source
#:media #:bufale
::: Slashdot

Weird unix thing: ‘cd //’
Julia rockz! 🚀
#:tip, suggerimenti
::: Julia Evans

10 modi per ostacolare l’Open Data
#:free open source software
::: Tech Economy

Write your own compiler – Introduction
viebel – KLIPSE rockz! 🚀
::: A journey into functional programming

New #Copyright for publishers: false assumptions use to racket sums that have nothing to do with economic situation
#:copyright
::: communia_eu

16508080_1491183167583150_3806969040022118997_n

Seven #GnuPG hackers just founded the GnuPG Verein
#:sicurezza, spionaggio, virus
::: gnupg

New interactive features in Plotly
#:linguaggi di programmazione
::: SciPyTip

It’s almost enough to make a cyber-commando punch a kitten
da studiare e ricordare
#:programming, codice, snippet
::: wallingf

Why Functional Programming Matters
#:programmazione funzionale
::: b3h3m0th

Programming Languages: Application and Interpretation
#:manuali, how to
::: b3h3m0th

cr7ms_owcaa7hzt

a new range of shortcuts with the Hyper key
però Caps Lock mi serve per le E accentate e i tweets grilleschi
#:tip, suggerimenti
::: The Ubuntu Incident

let “Super + d” show the desktop
qualche problema, l’off non ripristina tutto
#:tools, componenti software
::: The Ubuntu Incident

Microsoft Teases Windows 10’s Upcoming ‘Project Neon’ Design Language
#:sistemi operativi
::: Slashdot

#GNU Octave is an important scientific tool. Its maintainer needs help after 25 years
#:free open source software
::: fsf

The code that took America to the moon was just published to GitHub, and it’s like a 1960s time capsule
#:storia
::: petenwood

16508629_795877360551522_6949791733130742270_n

Principles of Programming Languages
un’altra SICP reseo semplice, Mira è molto più brava di me 😜
#:manuali, how to
::: b3h3m0th

Short Introduction to Functional Programming and Lambda-calculus
#:programmazione funzionale
::: b3h3m0th

I learned a lot from that bug
ahemmm… mi sto perdendo con questo post 👽
#:programming, codice, snippet
::: wallingf

The CPython source code has officially moved to https://github
#:linguaggi di programmazione
::: gvanrossum

#Wearable #Translator Anywhere, Anytime!
funziona?
#:innovazioni, futuro
::: wearableO

how-many-phd

Finally: irrefutable evidence that I never cooperated with Russian intel
#:sicurezza, spionaggio, virus
::: Snowden ::: Slashdot

Spammer Faces Decades In Prison For Sending More Than 1 Million Spam Emails
#:spam
::: Slashdot

According to Pew, nearly half of American adults say they could not live without their smartphones
#:dispositivi mobili
::: EconBizFin

here are things that must be said no matter the consequence
#:sicurezza, spionaggio, virus
::: Snowden ::: Snowden

eagle

 

Aggiornamento –perpluto 😙
Alle ore 10:30 ho già accumulato 12 URLs da inserire nella prossima puntata della telenovela.
Per ragioni personali posto solo la mattina sul presto per cui mi domando –anzi domando ai lettori– devo spostare al lunedì (o meglio martedì) la rassegna?

NumPy – 10 – Introduzione di NumPy

guardian

Continuando da qui oggi finalmente qui.

This chapter […] outlines techniques for effectively loading, storing, and manipulating in-memory data in Python. The topic is very broad: datasets can come from a wide range of sources and a wide range of formats, including be collections of documents, collections of images, collections of sound clips, collections of numerical measurements, or nearly anything else. Despite this apparent heterogeneity, it will help us to think of all data fundamentally as arrays of numbers.

For example, images –particularly digital images– can be thought of as simply two-dimensional arrays of numbers representing pixel brightness across the area. Sound clips can be thought of as one-dimensional arrays of intensity versus time. Text can be converted in various ways into numerical representations, perhaps binary digits representing the frequency of certain words or pairs of words. No matter what the data are, the first step in making it analyzable will be to transform them into arrays of numbers.

For this reason, efficient storage and manipulation of numerical arrays is absolutely fundamental to the process of doing data science. We’ll now take a look at the specialized tools that Python has for handling such numerical arrays: the NumPy package, and the Pandas package [prossimamente].

This chapter will cover NumPy in detail. NumPy (short for Numerical Python) provides an efficient interface to store and operate on dense data buffers. In some ways, NumPy arrays are like Python’s built-in list type, but NumPy arrays provide much more efficient storage and data operations as the arrays grow larger in size. NumPy arrays form the core of nearly the entire ecosystem of data science tools in Python, so time spent learning to use NumPy effectively will be valuable no matter what aspect of data science interests you.

Install Anaconda, dice Jake, uhmmm… chissà forse, NumPy dovrei averlo…

np50

Uh! devo installare Anaconda 😊

…………………………………………………………………….
[considerate che qui ci sia una lunga pausa, sto installando]
…………………………………………………………………….

OK, fatto, seguendo le indicazioni trovate qui: Download Anaconda Now.

Tarocca un po l’environment ma per Numpy kwesto&altro 😉 e ora

np51

By convention, you’ll find that most people in the SciPy/PyData world will import NumPy using np as an alias:

np52

Throughout this chapter, and indeed the rest of the book, you’ll find that this is the way we will import and use NumPy.

Un promemoria sulla documentazione
[D]on’t forget that IPython gives you the ability to quickly explore the contents of a package (by using the tab-completion feature), as well as the documentation of various functions using the ? character.

For example, to display all the contents of the numpy namespace, you can type this:

np53

Nota: dopo il punto c’è Tab, nèh!
And to display NumPy’s built-in documentation, you can use np? e inoltre info più dettagliate qui.

:mrgreen:

biwas di BiwaScheme un interprete Scheme in JavaScript

biwascheme_logo
Sono sempre intrigato dagli interpreti, ne ho parlato qui.

Bello provarli online, ma non solo, prendi BiwaScheme. Mysteryouso e intrigousassay 😯

Intanto c’è un gruppo su G+, da perlustrare — messo tra le cose da fare.
bws
Ma prima di subito si può scaricare l’interprete e installarlo in locale. Serve Node.js, è scritto in JavaScript.
E volendo si può anche modificare, personalizzare. Io ho cominciato con togliere metà del banner:

bs0

è stato sufficiente commentare la riga 103 del file /usr/local/lib/node_modules/biwascheme/bin/biwas così:

  var prompt = prompts.base;
  rl.setPrompt(prompt);

  console.log('BiwaScheme version ' + BiwaScheme.VERSION);
  //console.log('try (+ 1 2), etc. (Ctrl-D to exit)');

  BiwaScheme.Port.current_input = new BiwaScheme.Port.CustomInput(

Facile vero? volendo si può cambiare anche il prompt, mettere qualcosa come bs > per esempio. Basta ricordarsi che occorre sudo, siamo in /usr.

E nella directory cosa non si trova! non sempre facile, ma ci sono i commenti. Ma sono in giapponese 😜

Yutaka Hara è presente qui e qui –e altri posti ancora ma meno accessibili, ho carenze linguistiche, parlo principalmente piemonteis (pron. piemuntèis) dei contadini della zona di Carmagnola 😙

Maggiori info si BiwaScheme si possono trovare in un post di Jakub Jankiewicz, qui: How to use and extend BiwaScheme.
In questo post ci sarebbero altre cose da approfondire, per esempio Dialog –manca solo il tempo.
Inoltre, da viebel | klipse (prossimamente…) un rapido approccio a Scheme, Interactive overview of Scheme’s semantics, complementare alle specifiche di Scheme, disponibili anche sulla home di Biwascheme, queste.
:mrgreen: