Element by element tensor multiplication in python

泪湿孤枕 提交于 2020-01-24 13:17:27

问题


I am trying to solve a problem in computational algebra using python.

Basically given two sets, say A={a,b} and B={e}, I need to compute the element by element tensor products and get a final set say C={a\tensor{e},b\tensor{e}} containing these products of elements.

I can do an element by element multiplication using arrays with numbers but I can't do an element by element tensor multiplication of letters instead of numbers.


回答1:


Not sure if I understood correctly, this below code multiplies each letter of one set with each letter of the the other set

def getProduct(A,B):
    prod=[]
    for a in A:
        for b in B:
           prod.append(a+b)
    return prod

A=['a','b']
B=['e']
print(getProduct(A,B))

Output: ['ae', 'be']


来源:https://stackoverflow.com/questions/50328299/element-by-element-tensor-multiplication-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!