- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return a string which is the concatenation of the strings in the sequence in Numpy
To return a string which is the concatenation of the strings in the sequence, use the numpy.char.join() method in Python Numpy. The 1st parameter is the separator array. The 2nd parameter is the sequence array. The function returns an output array of str or unicode, depending on input types
The numpy.char module provides a set of vectorized string operations for arrays of type numpy.str_ or numpy.bytes_.
Steps
At first, import the required library −
import numpy as np
Create a One-Dimensional array of string −
arr = np.array(['Bella\tCio', 'Tom\tHanks', 'Monry\tHeist\tSeries'])
Displaying our array −
print("Array...
",arr)
Get the datatype −
print("
Array datatype...
",arr.dtype)
Get the dimensions of the Array −
print("
Array Dimensions...
",arr.ndim)
Get the shape of the Array −
print("
Our Array Shape...
",arr.shape)
Get the number of elements of the Array −
print("
Elements in the Array...
",arr.size)
To replace tab characters by a fixed tabsize in a string array, use the numpy.char.expandtabs() method. The "tabsize" parameter is used to replace tabs with tabsize number of spaces. If not given defaults to 8 spaces. We have set the "tabsize" to 10 i.e. 10 spaces −
print("
Result (expand tabs)...
",np.char.expandtabs(arr, tabsize = 10))
Example
import numpy as np # Create two arrays sep = np.array([':', '-', '$']) seq = np.array(['abc', 'def', 'ghi']) # Displaying our sequence print("Sequence array...
",seq) # Get the datatype print("
Array datatype...
",seq.dtype) # Get the dimensions of the Array print("
Array Dimensions...
",seq.ndim) # Get the shape of the Array print("
Our Array Shape...
",seq.shape) # Get the number of elements of the Array print("
Elements in the Array...
",seq.size) # To return a string which is the concatenation of the strings in the sequence, use the numpy.char.join() method in Python Numpy # The 1st parameter is the separator array # The 2nd parameter is the sequence array print("
Result...
",np.char.join(sep,seq))
Output
Sequence array... ['abc' 'def' 'ghi'] Array datatype... <U3 Array Dimensions... 1 Our Array Shape... (3,) Elements in the Array... 3 Result... ['a:b:c' 'd-e-f' 'g$h$i']
- Related Articles
- Return element-wise string multiple concatenation in Numpy
- Return element-wise string concatenation for two arrays of string in Numpy
- Return the pickle of the masked array as a string in NumPy
- Return a list of the words in the string using separator as the delimiter string in Numpy
- Return the user-readable string representation of a masked array in Numpy
- Concatenation of Strings in Java
- Return the array data as a string containing the raw bytes in the array in Numpy
- Return the numeric string left-filled with zeros in Numpy
- Smart concatenation of strings in JavaScript
- Concatenation of strings in Lua programming
- Return the ceil of the inputs in Numpy
- Return the floor of the input in Numpy
- Return a view of the MaskedArray data in Numpy
- Return a copy of the masked array in NumPy
- Return the mask of a masked array in Numpy
