Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

Vectors#

classpyspark.mllib.linalg.Vectors[source]#

Factory methods for working with vectors.

Notes

Dense vectors are simply represented as NumPy array objects,so there is no need to convert them for use in MLlib. For sparse vectors,the factory methods in this class create an MLlib-compatible type, or userscan pass in SciPy’sscipy.sparse column vectors.

Methods

dense(*elements)

Create a dense vector of 64-bit floats from a Python list or numbers.

fromML(vec)

Convert a vector from the new mllib-local representation.

norm(vector, p)

Find norm of the given vector.

parse(s)

Parse a string representation back into the Vector.

sparse(size, *args)

Create a sparse vector, using either a dictionary, a list of (index, value) pairs, or two separate arrays of indices and values (sorted by index).

squared_distance(v1, v2)

Squared distance between two vectors.

stringify(vector)

Converts a vector into a string, which can be recognized by Vectors.parse().

zeros(size)

Methods Documentation

staticdense(*elements)[source]#

Create a dense vector of 64-bit floats from a Python list or numbers.

Examples

>>>Vectors.dense([1,2,3])DenseVector([1.0, 2.0, 3.0])>>>Vectors.dense(1.0,2.0)DenseVector([1.0, 2.0])
staticfromML(vec)[source]#

Convert a vector from the new mllib-local representation.This does NOT copy the data; it copies references.

New in version 2.0.0.

Parameters
vecpyspark.ml.linalg.Vector
Returns
pyspark.mllib.linalg.Vector
staticnorm(vector,p)[source]#

Find norm of the given vector.

staticparse(s)[source]#

Parse a string representation back into the Vector.

Examples

>>>Vectors.parse('[2,1,2 ]')DenseVector([2.0, 1.0, 2.0])>>>Vectors.parse(' ( 100,  [0],  [2])')SparseVector(100, {0: 2.0})
staticsparse(size,*args)[source]#

Create a sparse vector, using either a dictionary, a list of(index, value) pairs, or two separate arrays of indices andvalues (sorted by index).

Parameters
sizeint

Size of the vector.

args

Non-zero entries, as a dictionary, list of tuples,or two sorted lists containing indices and values.

Examples

>>>Vectors.sparse(4,{1:1.0,3:5.5})SparseVector(4, {1: 1.0, 3: 5.5})>>>Vectors.sparse(4,[(1,1.0),(3,5.5)])SparseVector(4, {1: 1.0, 3: 5.5})>>>Vectors.sparse(4,[1,3],[1.0,5.5])SparseVector(4, {1: 1.0, 3: 5.5})
staticsquared_distance(v1,v2)[source]#

Squared distance between two vectors.a and b can be of type SparseVector, DenseVector, np.ndarrayor array.array.

Examples

>>>a=Vectors.sparse(4,[(0,1),(3,4)])>>>b=Vectors.dense([2,5,4,1])>>>a.squared_distance(b)51.0
staticstringify(vector)[source]#

Converts a vector into a string, which can be recognized byVectors.parse().

Examples

>>>Vectors.stringify(Vectors.sparse(2,[1],[1.0]))'(2,[1],[1.0])'>>>Vectors.stringify(Vectors.dense([0.0,1.0]))'[0.0,1.0]'
staticzeros(size)[source]#

[8]ページ先頭

©2009-2025 Movatter.jp