Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
How to create a vector in Python using NumPy
Next article icon

Divide each row by a vector element using NumPy

Last Updated : 03 Oct, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

The following article depicts how to Divide each row by a vector element using NumPy. The vector element can be a single element, multiple element, or array. The division operator ( / ) is employed to produce the required functionality.  We can divide rows of 1-D, 2-D, or even more types of arrays with vector elements and the following examples will help you understand better:

Divide row by a vector element in a 1-D Numpy array

In the example, we divide the rows of a 1-D Numpy array with a vector element i.e [15]

Python3
# Importing Numpy module  import numpy as np  # Creating 1-D Numpy array n_arr = np.array([20, 30, 40]) print("Given 1-D Array:") print(n_arr)  # Vector element  vec = np.array([12]) print("\nVector element:") print(vec)  # Dividing rows of 1-D array with vector element print("\nResultant Array") print(n_arr / vec[:,None]) 

Output:

 

Divide each by a vector element in a 2-D Numpy array

In the example, we divide each row by a vector element of a 2-D Numpy array with a vector element i.e [2.5]

Python3
# Importing Numpy module  import numpy as np  # Creating 2-D Numpy array n_arr = np.array([[20, 35, 40],                 [10, 51, 25]])  print("Given 2-D Array:") print(n_arr)  # Vector element  vec = np.array([2.5]) print("\nVector element:") print(vec)  # Dividing rows of 2-D array with vector element print("\nResultant Array") print(n_arr / vec[:,None]) 

Output:

 

Divide row by a vector element in a 3-D Numpy array

In the example, we divide the rows of a 3-D Numpy array with a vector element i.e [3, 3]

Python3
# Importing Numpy module  import numpy as np  # Creating 3-D Numpy array n_arr = np.array([[[10, 25], [30, 45]],                    [[50, 65], [70, 85]]])  print("Given 3-D Array:") print(n_arr)  # Vector element  vec = np.array([3, 3]) print("\nVector element:") print(vec)  # Dividing rows of 3-D array with vector element print("\nResultant Array") print(n_arr / vec[:,None]) 

Output:

 

Next Article
How to create a vector in Python using NumPy
author
vanshgaur14866
Improve
Article Tags :
  • Python
  • Python-numpy
  • Python numpy-arrayManipulation
Practice Tags :
  • python

Similar Reads

  • Find a matrix or vector norm using NumPy
    To find a matrix or vector norm we use function numpy.linalg.norm() of Python library Numpy. This function returns one of the seven matrix norms or one of the infinite vector norms depending upon the value of its parameters.  Syntax: numpy.linalg.norm(x, ord=None, axis=None)Parameters: x: input ord:
    2 min read
  • How to create a vector in Python using NumPy
    NumPy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python. Numpy is basically used for creating array of n dimensions. Vector are built
    5 min read
  • How to get element-wise true division of an array using Numpy?
    True Division in Python3 returns a floating result containing the remainder of the division. To get the true division of an array, NumPy library has a function numpy.true_divide(x1, x2). This function gives us the value of true division done on the arrays passed in the function. To get the element-w
    2 min read
  • How to inverse a matrix using NumPy
    In this article, we will see NumPy Inverse Matrix in Python before that we will try to understand the concept of it. The inverse of a matrix is just a reciprocal of the matrix as we do in normal arithmetic for a single number which is used to solve the equations to find the value of unknown variable
    3 min read
  • Divide one Hermite series by another in Python using NumPy
    In this article, we are going to see how to divide one Hermite series by another in Python using NumPy. The numpy hermdiv() method helps us divide one Hermite series by another. The quotient and remainder of two Hermite series, c1 / c2, are returned. The arguments are a series of coefficients from l
    3 min read
  • Averaging over every N elements of a Numpy Array
    In this article, we will learn how to find the average over every n element of a NumPy array. For doing our task, we will some inbuilt methods provided by NumPy module which are as follows: numpy.average() to calculate the average i.e the sum of all the numbers divided by the number of elementsnumpy
    3 min read
  • Products of Vectors and Matrices in NumPy
    Working with vector and matrix operations is a fundamental part of scientific computing and data analysis. NumPy is a Python library that computes various types of vector and matrix products. Let's discuss how to find the inner, outer and cross products of matrices and vectors using NumPy in Python.
    3 min read
  • Divide all Elements of a List by a Number in Python
    The task of dividing all elements of a list by a number in Python involves iterating over the list and applying the division operation to each element. For example, given a list a = [14, 8, 0, 12, 981, 21, -99] and a divisor d = 7, the result after dividing each element by 7 will be [2, 1, 0, 1, 140
    3 min read
  • How to skip every Nth index of NumPy array ?
    NumPy arrays offer efficient numerical operations and data storage. When working with large arrays, sometimes it's necessary to skip specific indices for optimization or data processing purposes. This article will show how to skip every Nth index of the NumPy array. There are various ways to access
    4 min read
  • Find unique rows in a NumPy array
    In this article, we will discuss how to find unique rows in a NumPy array. To find unique rows in a NumPy array we are using numpy.unique() function of NumPy library. Syntax of np.unique() in Python Syntax: numpy.unique() Parameter: ar: arrayreturn_index: Bool, if True return the indices of the inpu
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences