What is a vector?

Tajrin
Analytics Vidhya
Published in
5 min readApr 21, 2020

[Note: This was my first attempt and I don’t update this article]

Vectors are a foundational element of linear algebra. A vector is a tuple of one or more values called scalars.

In this article, we will discover linear algebra vectors for machine learning.

After reading this article, you will know:

  • What a vector is.
  • Why vector is important.
  • Major differences between an array and a vector.

Vectors are used throughout the field of machine learning in the description of algorithms and processes such as the target variable (y) when training an algorithm. Vectors are commonly used in machine learning as they lend a convenient way to organize data. Often one of the very first steps in making a machine learning model is vectorizing the data.

Vector in terms of machine learning

In machine learning and programming it is often convenient to use vectors. Vectors could be in the form of data itself, or model parameters, and so on.

For instance, the input (3.14159, 2.71828, 1.618) is a vector of 3 elements, and could be represented as a point in 3-dimensional space. Your program would declare a 1x3 array (one-dimensional data structure) to hold the three items.

The feature vector is simply one row of input. For instance, in the popular machine learning example of housing price prediction, we might have features (table columns) including a house’s year of construction, number of bedrooms, area (m²), and size of garage (auto capacity). This would give input vectors such as

[1988, 4, 200, 2]
[2001, 3, 220, 1]

In Simple words,
Dimensions : The attributes/features taken for analysis

n-Dimensional Vector : <e1, e2, e3, …., en> where ei is the value of dimension i and elements are ordered.

Example:
<180, 74, M, 60, 120> is a 6-Dimensional Vector where 180, 74, M, 60, 120 are the values of attributes/dimensions height, weight, gender, pulse_rate, cholesterol_level respectively.

<180, 74, M, 60, 120> and <180, M, 74, 60, 120> are not same as the order of dimensions weight and gender are changed.

Think of it as a list of values or a row in a table. The data structure is a 1-dimensional array; a vector of N elements is an N-dimensional vector, one dimension for each element.

A vector may refer to any of the following:

1. In computer programming, a vector is either a pointer or an array with only one dimension.

2. In mathematics, a vector is a quantity with both a magnitude and direction.

3. In computer graphics, the term vector describes a line with a starting and ending point.

4. In computer security, the term attack vector refers to a particular method for exploiting a system vulnerability.

Example:

If we do a survey of the heights of people in a population, we may get a distribution like this:

This histogram indicates how likely it is for anyone in the survey to be in a particular height range. (6 ft is around 180 cm)

This histogram can also be represented by a vector, i.e. a list of numbers.

In this case, we record the frequency of people with heights in little groups at 2.5 cm intervals, i.e. between 150 cm and 152.5 cm, between 152.5 cm and 155 cm, and so on. We can define this as the vector f with components:

vector f

These vector components are then the sizes of each bar in the histogram.

Some points to be noted

  • A vector, in programming, is a type of array that is one dimensional.
  • A vector is often represented as a 1-dimensional array of numbers, referred to as components and is displayed either in column form or row form.
  • Vectors are a logical element in programming languages that are used for storing data.
  • Vectors are similar to arrays but their actual implementation and operation differs.
  • Vector containers are implemented as dynamic arrays; Just as regular arrays, vector containers have their elements stored in contiguous storage locations, which means that their elements can be accessed not only using iterators but also using offsets on regular pointers to elements.
  • But unlike regular arrays, storage in vectors is handled automatically, allowing it to be expanded and contracted as needed.
  • Furthermore, vectors can typically hold any object — so you can make a class to hold information about vehicles, and then store the fleet in a vector.
  • Nice things about vectors, aside from resizing, is that they still allow access in constant time to individual elements via index, just like an array.
  • Each item in the vector has to be the same length and type. If we choose to put different types in there, either through casting or pointer manipulation, we risk making a mistake with later casting and pointer manipulation.
  • Represented geometrically, vectors typically represent coordinates within a n-dimensional space, where n is the number of dimensions. A simplistic representation of a vector might be a arrow in a vector space, with an origin, direction, and magnitude (length)

The major differences between an array and a vector

  • Unlike typical arrays, the container size of a vector can be easily increased and decreased to complement different data storage types.
  • Vectors have a dynamic structure and provide the ability to assign container size up front and enable allocation of memory space quickly.
  • Vectors can be thought of as dynamic arrays.

In the next article we will discuss about vector operations.

Conclusion

Vectors are primarily used within the programming context of most programming languages and serve as data structure containers. Being a data structure, vectors are used for storing objects and collections of objects in an organized structure.

--

--