+ 4

Multiply a character matrix with int matrix

Which is correct syntax for it? https://code.sololearn.com/cBQxu6JFyr1i

8th Aug 2022, 8:55 AM
Oma Falk
Oma Falk - avatar
12 Respostas
+ 3
""" 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(a.dot(b)) [print(*w) for w in a.dot(b)] print(*list(np.concatenate(a.dot(b)).flat))
10th Aug 2022, 3:07 AM
Bob_Li
Bob_Li - avatar
+ 3
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.
8th Aug 2022, 10:14 AM
Lisa
Lisa - avatar
+ 3
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)
8th Aug 2022, 10:25 AM
Lisa
Lisa - avatar
8th Aug 2022, 11:00 AM
Vitaly Sokol
Vitaly Sokol - avatar
+ 2
Bob_Li I love ❀ you thanks
10th Aug 2022, 9:59 AM
Oma Falk
Oma Falk - avatar
+ 1
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.
8th Aug 2022, 9:50 AM
Lisa
Lisa - avatar
+ 1
I expected wwwww ooooo rrrrr ddddd Multiplication between integers and chars is defined. So why not matrix multiplication đŸ˜€
8th Aug 2022, 10:08 AM
Oma Falk
Oma Falk - avatar
+ 1
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. https://code.sololearn.com/cAZ9vkJAyt87/?ref=app
8th Aug 2022, 10:10 AM
noteve
noteve - avatar
0
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".
8th Aug 2022, 11:53 PM
Brian
Brian - avatar
- 1
How ? I don't think
8th Aug 2022, 11:56 PM
Mani Singh
Mani Singh - avatar
- 1
No ,I double check I spelled them correctly
9th Aug 2022, 12:04 AM
Mani Singh
Mani Singh - avatar
- 2
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
8th Aug 2022, 7:48 PM
Mani Singh
Mani Singh - avatar