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:
Repeat all the elements of a NumPy array of strings
Next article icon

Element-wise concatenation of two NumPy arrays of string

Last Updated : 04 Jan, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will discuss how to concatenate element-wise two arrays of string 

Example :

Input : A = ['Akash', 'Ayush', 'Diksha', 'Radhika'] B = ['Kumar', 'Sharma', 'Tewari', 'Pegowal']  Output : A + B = [AkashKumar, AyushSharma, 'DikshTewari', 'RadhikaPegowal']

We will be using the numpy.char.add() method.

Syntax : numpy.char.add(x1, x2)
Parameters :

  • x1 : first array to be concatenated (concatenated at the beginning)
  • x2 : second array to be concatenated (concatenated at the end)

Returns : Array of strings or unicode

Example 1: String array with a single element.

Python3

# importing library numpy as np
import numpy as np
 
# creating array as first_name
first_name = np.array(['Geeks'],
                      dtype = np.str)
print("Printing first name array:")
print(first_name)
 
# creating array as last name
last_name = np.array(['forGeeks'],
                     dtype = np.str)
print("Printing last name array:")
print(last_name)
 
# concat first_name and last_name
# into new array named as full_name
full_name = np.char.add(first_name, last_name)
print("\nPrinting concatenate array as full name:")
print(full_name)
                      
                       

 
 Output : 

Printing first name array: ['Geeks'] Printing last name array: ['forGeeks']  Printing concatenate array as full name: ['GeeksforGeeks']

Example 2: String array with multiple elements.

Python3

# importing library numpy as np
import numpy as np
 
# creating array as first_name
first_name = np.array(['Akash', 'Ayush', 'Diksha',
                       'Radhika'], dtype = np.str)
print("Printing first name array:")
print(first_name)
 
# creating array as last name
last_name = np.array(['Kumar', 'Sharma', 'Tewari',
                      'Pegowal'], dtype = np.str)
print("Printing last name array:")
print(last_name)
 
# concat first_name and last_name
# into new array named as full_name
full_name = np.char.add(first_name, last_name)
print("\nPrinting concatenate array as full name:")
print(full_name)
                      
                       

 
 Output : 

Printing first name array: ['Akash' 'Ayush' 'Diksha' 'Radhika'] Printing last name array: ['Kumar' 'Sharma' 'Tewari' 'Pegowal']  Printing concatenate array as full name: ['AkashKumar' 'AyushSharma' 'DikshaTewari' 'RadhikaPegowal']


Next Article
Repeat all the elements of a NumPy array of strings

H

hupphurr
Improve
Article Tags :
  • Python
  • Python numpy-String Operation
  • Python-numpy
Practice Tags :
  • python

Similar Reads

  • NumPy - Arithmetic operations with array containing string elements
    Numpy is a library of Python for array processing written in C and Python. Computations in numpy are much faster than that of traditional data structures in Python like lists, tuples, dictionaries etc. due to vectorized universal functions. Sometimes while dealing with data, we need to perform arith
    2 min read
  • Find the length of each string element in the Numpy array
    NumPy builds on (and is a successor to) the successful Numeric array object. Its goal is to create the corner-stone for a useful environment for scientific computing. NumPy provides two fundamental objects: an N-dimensional array object (ndarray) and a universal function object (ufunc). In this post
    3 min read
  • Repeat all the elements of a NumPy array of strings
    Let us see how to repeat all elements of the given array of string 3 times. Example : Input : ['Akash', 'Rohit', 'Ayush', 'Dhruv', 'Radhika'] Output : ['AkashAkashAkash', 'RohitRohitRohit', 'AyushAyushAyush', 'DhruvDhruvDhruv', 'RadhikaRadhikaRadhika'] We will be using the numpy.char.multiply(a, i)
    2 min read
  • How to Concatenate two 2-dimensional NumPy Arrays?
    Sometimes it might be useful or required to concatenate or merge two or more of these NumPy arrays. In this article, we will discuss various methods of concatenating two 2D arrays. But first, we have to import the NumPy package to use it: # import numpy package import numpy as np Then two 2D arrays
    5 min read
  • Evaluate Einstein's summation convention of two multidimensional NumPy arrays
    In Python, we can use the einsum() function of the NumPy package to compute Einstein's summation convention of two given multidimensional arrays. Syntax: numpy.einsum(subscripts, *operands, out=None)  Parameters:  subscripts : str Specifies the subscripts for summation as comma separated list of sub
    3 min read
  • NumPy | Get the Powers of Array Values Element-Wise
    To calculate the power of elements in an array we use the numpy.power() method of NumPy library. It raises the values of the first array to the powers in the second array. Example:[GFGTABS] Python3 import numpy as np # creating the array sample_array1 = np.arange(5) sample_array2 = np.arange(0, 10,
    3 min read
  • Python | dtype object length of Numpy array of strings
    In this post, we are going to see the datatype of the numpy object when the underlying data is of string type. In numpy, if the underlying data type of the given object is string then the dtype of object is the length of the longest string in the array. This is so because we cannot create variable l
    3 min read
  • Compute pearson product-moment correlation coefficients of two given NumPy arrays
    In NumPy, We can compute pearson product-moment correlation coefficients of two given arrays with the help of numpy.corrcoef() function. In this function, we will pass arrays as a parameter and it will return the pearson product-moment correlation coefficients of two given arrays. Syntax: numpy.corr
    1 min read
  • Different Ways to Create Numpy Arrays in Python
    Creating NumPy arrays is a fundamental aspect of working with numerical data in Python. NumPy provides various methods to create arrays efficiently, catering to different needs and scenarios. In this article, we will see how we can create NumPy arrays using different ways and methods. Ways to Create
    3 min read
  • How to Concatenate Two Lists Index Wise in Python
    Concatenating two lists index-wise means combining corresponding elements from both lists into a single element, typically a string, at each index . For example, given two lists like a = ["gf", "i", "be"] and b = ["g", "s", "st"], the task is to concatenate each element from a with the corresponding
    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