K
K
KazemirL2018-10-16 02:56:44
Python
KazemirL, 2018-10-16 02:56:44

How to work with add, multiply functions to merge numpy arrays?

Can you tell me why these code options do not work?
Option 1

dl = []
i = 0
while i < 5:
    dl.append('dict')   # + str(i) - можно было и так, но хочется понять, как работает numpy
    i+=1
print dl
x1 = np.arange(0,5)
x2 = np.asarray(x1,str)
x3 = np.add(dl1,x2)
print x3

Output:
['dict', 'dict', 'dict', 'dict', 'dict']
--------------------------- ------------------------------------------------
TypeError Traceback (most recent call last)
in ()
8 x1 = np.arange(0,5)
9 x2 = np.asarray(x1,str)
---> 10 x3 = np.add(dl1,x2)
11 print x3
TypeError : ufunc 'add' did not contain a loop with signature matching types dtype('S21') dtype('S21') dtype('S21')
Option 2
dl = []
i = 0
while i < 5:
    dl.append('dict')  # + str(i) 
    i+=1
print dl
x1 = np.arange(0,5)
x2 = np.asarray(x1,str)
x3 = np.multiply(dl1,x1)
print x3

Output
['dict', 'dict', 'dict', 'dict', 'dict']
---------------------- -----------------------------------------------------
TypeError Traceback( most recent call last)
in ()
8 x1 = np.arange(0,5)
9 x2 = np.asarray(x1,str)
---> 10 x3 = np.multiply(dl1,x1)
11 print x3
TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype('S21') dtype('S21') dtype('S21')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artgor, 2018-10-16
@KasemirL

Use the appropriate functions from ".core.defchararray." - it works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question