Change language

numpy.defchararray.multiply () in Python

|

numpy.core.defchararray.multiply (arr, n) : concatenates lines & # 39; n & # 39; times by elements.

Parameters:
arr: array-like or string.
n : [array-like] no. of times we want to concatenate.

Returns: Concatenated String ’n’ times element-wise.

Code # 1 :

# Python program illustrating
# numpy.char.multiply () method

import numpy as np 

 

arr1 = [ ’ eAAAa’ , ’ttttds’ ​​ , ’AAt’ ]

arr2 = [ ’11sf’ , ’sdsf 2’ , ’1111f2’ ]

 

print ( "arr1:" , arr1)

print ( "arr2:" , arr2)

 

print ( "arr1:" , np.char.multiply (arr1, 2 ))

 
# Separate multiplication

print ( "arr1:" , np.char.multiply (arr1, [ 2 , 4 , 3 ]))

print ( "arr2:" , np.char.multiply (arr2, 3 ))

Output:

 arr1: [’eAAAa’,’ ttttds’, ’AAt’] arr2: [’ 11sf’, ’sdsf2’,’ 1111f2’] arr1: [’eAAAaeAAAa ’’ ttttdsttttds’ ​​’AAtAAt’] arr1: [’ eAAAaeAAAa’ ’ttttdsttttdsttttdsttttds’’ AAtAAtAAt’] arr2: [’11sf11sf11sf’’ sdsf2sdsf2sdsf2’’f211f211> strong> 

# Python program illustrating
# numpy.char.multiply () method

import numpy as np 

 

arr1 = ’This is geeks’

arr2 = ’for geeks’

  

print ( "arr1:" , np.char.multiply (arr1, 2 ))

print ( "arr2:" , np.char.multiply (arr2, 4 ))

Exit :

 arr1 : This is geeks arr2: for geeks arr1: This is geeks This is geeks arr2: for geeks for geeks for geeks for geeks 



                   

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method