numpy.defchararray.multiply() in Python
numpy.core.defchararray.multiply(arr, n)
: Verkettet Zeichenfolgen 'n' mal elementweise.
Parameter:
arr: array-like oder string.
n: [Array-ähnlich] Nr. von Zeiten wollen wir verketten.Rückgabe: Verketteter String 'n' mal elementweise.
Code # 1:
import
numpy as np
arr1
=
[
'eAAAa'
,
'ttttds'
,
'AAt'
]
arr2
=
[
'11sf'
,
'sdsf2'
,
'1111f2'
]
(
"\narr1 : "
, arr1)
(
"\narr2 : "
, arr2)
(
"\narr1 : "
, np.char.multiply(arr1,
2
))
(
"\narr1 : "
, np.char.multiply(arr1, [
2
,
4
,
3
]))
(
"\narr2 : "
, np.char.multiply(arr2,
3
))
Ausgabe:
arr1: ['eAAAa', 'ttttds', 'AAt'] arr2: ['11sf', 'sdsf2', '1111f2'] arr1: ['eAAAaeAAAa' 'ttttdsttttds' 'AAtAAt'] arr1: ['eAAAaeAAAa' 'ttttdsttttdsttttdsttttds' 'AAtAAtAAt'] arr2: ['11sf11sf11sf' 'sdsf2sdsf2sdsf2' '1111f21111f21111f2']
Code # 2:
import
numpy as np
arr1
=
'This is geeks '
arr2
=
'for geeks '
(
"\narr1 : "
, np.char.multiply(arr1,
2
))
(
"\narr2 : "
, np.char.multiply(arr2,
4
))
Ausgabe:
arr1: Das sind Geeks arr2: für Geeks arr1: Das sind Geeks Das sind Geeks arr2: für Geeks für Geeks für Geeks für Geeks