In this tutorial we'll take a look at the slice operator of the Numpy array. This feature of Numpy is virtually indespensible when working with multi-dimensional arrays.
Shortly after launching this site in 2015, I became very busy with work and life and didn't make enough time for maintaining it. In the meantime, I worked on many interesting projects and learned a lot. I'm looking forward to getting back into the rhythm of writing about my experiments and work in programming and various tech. In an attempt to bolster some momentum and reacquaint myself with the code for this site, I've spent the past few days making some long intended updates which have included the following:
In the last article we took a look at a simple k-means implementation using Python. In this article we will sophisticate our previous work by doing away with hard coded data, replacing the Vec class with Numpy arrays and visualizing results using matplotlib. The source code for this iteration can be found here. We will not go through it line by line, but we will look at the most significant improvements.
In this article we will build a k-means clustering algorithm. We will use plain old Python and no other third party code. The goal of this article is to convey the basic structure of the k-means algorithm by developing a minimal working example capable of clustering a 2D dataset. It is expected that you understand basic programming, simple vector math and that you have at least some idea about how k-means works. Let's get started.
In my last article I wrote about how to create an Icosahedron using Swift and SceneKit. The example used hard-coded values for the vertices and indices that define the shape. In this article, I'll show how we can create a sphere using that same data for initial values combined with an iterative algorithm. The algorithm takes each face of the Icosahedron and sub-divides it into four new triangles. The vertices of which are turned into new faces to be once again sub-divided in the next iteration.
In this article I'll demonstrate an of example of creating custom 3D geometry for SceneKit using the Swift programming language. We'll look at how to create the simple yet very interesting polyhedron known as the Icosahedron.
SCNVector3 class for SceneKit is a bit under-featured. Here is an extension that adds many useful operators and a few nice to have methods to it. A feature in Swift that is particularly helpful here is the ability to declare a function parameter as an
inout variable. This allows you to reassign a value to the variable itself. This is especially useful for defining
*= and the like.