Data Warehousing
Top 50 Teradata Interview Questions & Answers
Download PDF 1) How do you define Teradata? Give some of the primary characteristics of the same....
NumPy arrays are a bit like Python lists, but still very much different at the same time. For those of you who are new to the topic, let’s clarify what it exactly is and what it’s good for.
As the name kind of gives away, a NumPy array is a central data structure of the numpy library. The library’s name is actually short for "Numeric Python" or "Numerical Python".
Simplest way to create an array in Numpy is to use Python List
myPythonList = [1,9,8,3]
To convert python list to a numpy array by using the object np.array.
numpy_array_from_list = np.array(myPythonList)
To display the contents of the list
numpy_array_from_list
Output
array([1, 9, 8, 3])
In practice, there is no need to declare a Python List. The operation can be combined.
a = np.array([1,9,8,3])
NOTE: Numpy documentation states use of np.ndarray to create an array. However, this the recommended method
You can also create a numpy array from a Tuple
You could perform mathematical operations like additions, subtraction, division and multiplication on an array. The syntax is the array name followed by the operation (+.-,*,/) followed by the operand
Example:
numpy_array_from_list + 10
Output:
array([11, 19, 18, 13])
This operation adds 10 to each element of the numpy array.
You can check the shape of the array with the object shape preceded by the name of the array. In the same way, you can check the type with dtypes.
import numpy as np a = np.array([1,2,3]) print(a.shape) print(a.dtype) (3,) int64
An integer is a value without decimal. If you create an array with decimal, then the type will change to float.
#### Different type b = np.array([1.1,2.0,3.2]) print(b.dtype) float64
You can add a dimension with a ","coma
Note that it has to be within the bracket []
### 2 dimension
c = np.array([(1,2,3),
(4,5,6)])
print(c.shape)
(2, 3)
Higher dimension can be constructed as follow:
### 3 dimension
d = np.array([
[[1, 2,3],
[4, 5, 6]],
[[7, 8,9],
[10, 11, 12]]
])
print(d.shape)
(2, 2, 3)
Below, a summary of the essential functions used with NumPy.
| Objective | Code |
|---|---|
| Create array | array([1,2,3]) |
| print the shape | array([.]).shape |
Download PDF 1) How do you define Teradata? Give some of the primary characteristics of the same....
What is Data Mart? A Data Mart is focused on a single functional area of an organization and...
Tableau Desktop Workspace In the start screen, go to File > New to open a Tableau Workspace The...
Here are data modelling interview questions for fresher as well as experienced candidates. 1) What...
{loadposition top-ads-automation-testing-tools} ETL testing is performed before data is moved into...
What is Data? Data is a raw and unorganized fact that required to be processed to make it...