How to compute Z to the power of n using numpy if Z is a large vector?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

# How to compute Z to the power of n using numpy if Z is a large vector?

This recipe helps you compute Z to the power of n using numpy if Z is a large vector

## Recipe Objective

Many a times while handling arrays, we might need to find powers. We do have a function in numpy to handle such a situation. Null array comes quite handy while operating with numpy library in python.

So this recipe is a short example on how to compute power of a large array. Let's get started.

## Step 1 - Import the library

``` import numpy as np ```

Let's pause and look at these imports. Numpy is generally helpful in data manipulation while working with arrays. It also helps in performing mathematical operation.

## Step 2 - Defining power function

``` def power(Z,n): return np.power(Z,n) ```

We have a created a function which will return an array passed to it raised to power n.

## Step 3 - Printing array

``` print(power(np.random.random(1000),3)) ```

We call power function to find out the array of size 1000 raised to the power n.

## Step 4 - Lets look at our dataset now

Once we run the above code snippet, we will see:

```Scroll down to the ipython file for visualizing the output.
```

#### Relevant Projects

##### 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.

##### Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

##### 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.

##### Build a Face Recognition System in Python using FaceNet
In this deep learning project, you will build your own face recognition system in Python using OpenCV and FaceNet by extracting features from an image of a person's face.

##### Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

##### Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

##### Time Series Analysis Project in R on Stock Market forecasting
In this time series project, you will build a model to predict the stock prices and identify the best time series forecasting model that gives reliable and authentic results for decision making.

##### Build a Similar Images Finder with Python, Keras, and Tensorflow
Build your own image similarity application using Python to search and find images of products that are similar to any given product. You will implement the K-Nearest Neighbor algorithm to find products with maximum similarity.

##### Churn Prediction in Telecom using Machine Learning in R
Estimating churners before they discontinue using a product or service is extremely important. In this ML project, you will develop a churn prediction model in telecom to predict customers who are most likely subject to churn.

##### Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.