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?

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

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

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.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

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.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

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.