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 split the element of a given NumPy array with spaces?
Next article icon

How to insert a space between characters of all the elements of a given NumPy array?

Last Updated : 29 Aug, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will discuss how to insert a space between the characters of all elements of a given array of string. 
Example:

Suppose we have an array of string as follows:  A = ["geeks", "for", "geeks"]    then when we insert a space between the characters  of all elements of the above array we get the   following output.  A = ["g e e k s", "f o r", "g e e k s"]  

To do this we will use np.char.join(). This method basically returns a string in which the individual characters are joined by separator character that is specified in the method. Here the separator character used is space. 

Syntax: np.char.join(sep, string) 

Parameters:
sep: is any specified separator 
string: is any specified string. 

Example:

Python3

# importing numpy as np
import numpy as np
  
  
# creating array of string
x = np.array(["geeks", "for", "geeks"],
             dtype=np.str)
print("Printing the Original Array:")
print(x)
  
# inserting space using np.char.join()
r = np.char.join(" ", x)
print("Printing the array after inserting space\
between the elements")
print(r)
                      
                       

Output:

Printing the Original Array:  ['geeks' 'for' 'geeks']  Printing the array after inserting spacebetween the elements  ['g e e k s' 'f o r' 'g e e k s']


Next Article
How to split the element of a given NumPy array with spaces?

H

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

Similar Reads

  • How to split the element of a given NumPy array with spaces?
    To split the elements of a given array with spaces we will use numpy.char.split(). It is a function for doing string operations in NumPy. It returns a list of the words in the string, using sep as the delimiter string for each element in arr. Parameters:arr : array_like of str or unicode.Input array
    2 min read
  • NumPy ndarray.byteswap() Method | Swap bytes of the Array Elements
    The ndarray.byteswap() method swaps the bytes of the array elements. It toggles between low-endian and big-endian data representation by returning a byteswapped array, optionally swapped in-place. Note: byteswap() method does not work on arrays of strings. Example[GFGTABS] Python3 # Python program e
    2 min read
  • How to swap columns of a given NumPy array?
    In this article, let's discuss how to swap columns of a given NumPy array. Approach : Import NumPy moduleCreate a NumPy arraySwap the column with IndexPrint the Final array Example 1: Swapping the column of an array.  [GFGTABS] Python3 # importing Module import numpy as np # creating array with shap
    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
  • How to convert an array of indices to one-hot encoded NumPy array
    A very popular technique used in machine learning to transform categorical data into binary values of 0 and 1 is called the one-hot encoding technique. There are various circumstances when you need to use a one-hot encoded NumPy array rather than an array of indices, thus we can convert it using the
    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 rearrange columns of a 2D NumPy array using given index positions?
    In this article, we will learn how to rearrange columns of a given numpy array using given index positions. Here the columns are rearranged with the given indexes. For this, we can simply store the columns values in lists and arrange these according to the given index list but this approach is very
    2 min read
  • How to append a NumPy array to an empty array in Python
    In this article, we will cover how to append a NumPy array to an empty array in Python.  Here, we will discuss 2 different methods to append into an empty NumPy array. Both of these methods differ slightly, as shown below: Append a NumPy array to an empty array using the appendExample 1 Here we are
    2 min read
  • How to get values of an NumPy array at certain index positions?
    Sometimes we need to remove values from the source Numpy array and add them at specific indices in the target array. In NumPy, we have this flexibility, we can remove values from one array and add them to another array. We can perform this operation using numpy.put() function and it can be applied t
    4 min read
  • Select an element or sub array by index from a Numpy Array
    The elements of a NumPy array are indexed just like normal arrays. The index of the first element will be 0 and the last element will be indexed n-1, where n is the total number of elements. Selecting a single element from a NumPy array Each element of these ndarrays can be accessed using its index
    2 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