Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Numpy Beginner's Guide (Update)
  • Toc
  • feedback
Numpy Beginner's Guide (Update)

Numpy Beginner's Guide (Update)

By : Ivan Idris
2 (1)
close
Numpy Beginner's Guide (Update)

Numpy Beginner's Guide (Update)

2 (1)
By: Ivan Idris

Overview of this book

This book is for the scientists, engineers, programmers, or analysts looking for a high-quality, open source mathematical library. Knowledge of Python is assumed. Also, some affinity, or at least interest, in mathematics and statistics is required. However, I have provided brief explanations and pointers to learning resources.
Table of Contents (16 chapters)
close
14
C. NumPy Functions' References
15
Index

Time for Action – clustering points

We will generate some random points and cluster them, which means that the points that are close to each other are put into the same cluster. This is just one of the many techniques that you can apply with scikit-learn. Clustering is a type of machine learning algorithm, which aims to group items based on similarities. Next, we will calculate a square affinity matrix. An affinity matrix is a matrix containing affinity values: for instance, the distances between points. Finally, we will cluster the points with the AffinityPropagation class from scikit-learn.

  1. Generate 30 random point positions within a square of 400 by 400 pixels:
    positions = np.random.randint(0, 400, size=(30, 2))
  2. Calculate the affinity matrix using the Euclidean distance to the origin as the affinity metric:
    positions_norms = np.sum(positions ** 2, axis=1)
    S = - positions_norms[:, np.newaxis] - positions_norms[np.newaxis, :] + 2 * np.dot(positions, positions.T)
  3. Give the AffinityPropagation...
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete