def find_d_min(kv): X = list(kv[1]) minimum = Vectors.norm(X[0] - X[1], 2) # lets start from somewhere count = len(X) for i in xrange(count): for j in xrange(i + 1, count): d = Vectors.norm(X[i] - X[j], 2) if d < minimum: minimum = d return minimum
# COMMAND ---------- # MAGIC %md # MAGIC ** Norm ** # MAGIC # MAGIC We can calculate the norm of a vector using `Vectors.norm`. The norm calculation is: # MAGIC # MAGIC \\[ ||x|| _p = \bigg( \sum_i^n |x_i|^p \bigg)^{1/p} \\] # MAGIC # MAGIC # MAGIC # MAGIC Sometimes we'll want to normalize our features before training a model. Later on we'll use the `ml` library to perform this normalization using a transformer. # COMMAND ---------- Vectors.norm(denseVector, 2) # COMMAND ---------- # MAGIC %md # MAGIC In Python, `DenseVector` operations are delegated to an underlying NumPy array so we can perform multiplication, addition, division, etc. # COMMAND ---------- denseVector * denseVector # COMMAND ---------- 5 + denseVector # COMMAND ----------
# COMMAND ---------- # MAGIC %md # MAGIC ** Norm ** # MAGIC # MAGIC We can calculate the norm of a vector using `Vectors.norm`. The norm calculation is: # MAGIC # MAGIC \\[ ||x|| _p = \bigg( \sum_i^n |x_i|^p \bigg)^{1/p} \\] # MAGIC # MAGIC # MAGIC # MAGIC Sometimes we'll want to normalize our features before training a model. Later on we'll use the `ml` library to perform this normalization using a transformer. # COMMAND ---------- Vectors.norm(denseVector, 2) # COMMAND ---------- # MAGIC %md # MAGIC In Python, `DenseVector` operations are delegated to an underlying NumPy array so we can perform multiplication, addition, division, etc. # COMMAND ---------- denseVector * denseVector # COMMAND ---------- 5 + denseVector # COMMAND ----------