How to select elements from Numpy array in Python?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

# How to select elements from Numpy array in Python?

This recipe helps you select elements from Numpy array in Python

0

## Recipe Objective

In a numpy array array how do you select an element? Selecting an element is very easy if you know the index of the element. In this we will be selecting element from vector matrix and tensor.

So this is the recipe on how we can Select Elements from Numpy Array.

## Step 1 - Import the library

``` import numpy as np ```

We have only imported numpy which is needed.

## Step 2 - Selecting element from vector

We have created a vector and we will select a element from it by passing the index in the object. ``` vector = np.array([1, 2, 3, 4, 5, 6]) print(vector[1]) ``` We have created a matrix and we will select a element from it by passing the index in the object. For matrix we have to pass two values in the form (row , column) to select the element. ``` matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) print(matrix[1,1]) ``` We have created a tensor and we will select a element from it by passing the index in the object. For tensor we have to pass three value to select the element. ``` tensor = np.array([ [[[1, 1], [1, 1]], [[2, 2], [2, 2]]], [[[3, 3], [3, 3]], [[4, 4], [4, 4]]] ]) print(tensor[1,1,1]) ``` So the output comes as

```2

5

[4 4]
```

#### Relevant Projects

##### Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

##### PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

##### Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.

##### Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

##### Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

##### Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

##### German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

##### Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

##### Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

##### Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.