Multiply a character matrix with int matrix | Sololearn: Learn to code for FREE!


Multiply a character matrix with int matrix

Which is correct syntax for it?

8/8/2022 8:55:28 AM

Oma Falk

12 Answers

New Answer


""" Oma Falk you need to specify dtype="object" to your string array """ import numpy as np a = np.array([list("word")],dtype='object').T # or dtype='O' print(a) b = np.array([[5]]) print(b) print( [print(*w) for w in] print(*list(np.concatenate(


Oma Falk No, it is not defined, don't let Python make you believe that! 😂 numpy is not Python string repetition. numpy *matrix operations* are math.


import numpy as np n = 5 arr0 = np.array(list('word')) # 1. repeat # 2. reshape arr = np.repeat(arr0, n).reshape(len(arr0), n) print(arr)



Bob_Li I love ❤ you thanks


What is the expected output? A matrix with "word" as columns? As matrix operations are only the defined for numbers, I wouldn't expect it to work with characters. I probably would either repeat and concatenate the matrix or try to use integers instead of characters.


I expected wwwww ooooo rrrrr ddddd Multiplication between integers and chars is defined. So why not matrix multiplication 😤


When I specified the out argument (as an array of string) inside dot method, it raised an error that says "ValueError: dot not available for this type". So I looked for other numpy methods that could work with strings. np.repeat() method will repeat elements inside numpy array, based on the second argument. I tried four methods with different output (as I don't know your exact desired output yet). The last two require some list comprehension though, and is somewhat manually multiplied.


Maninder singh your reply is off the topic. Please start a new Q&A post to ask your own questions. I do have a quick answer for you, nonetheless: You misspelled "length".


How ? I don't think


No ,I double check I spelled them correctly


Function add() If (arguments.lenght==0){ console.log("no argument found"); }; Else{ console.log(arguments.lenght); }add(5,6) Hi guys in this code above there is an error in the line 2 but I did not found I am trying to prove that if arguments.lenght==0 Output no arguments found Else Output argument.length Please help me