Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-dimensional vectors (tensors) #15

Open
2 tasks
serengil opened this issue Dec 20, 2023 · 0 comments
Open
2 tasks

Support multi-dimensional vectors (tensors) #15

serengil opened this issue Dec 20, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@serengil
Copy link
Owner

Currently, tensor operations support just 1D vectors. We need to change the following methods.

Instead of a one depth for loop, element wise operations can be calculated as:

def element_wise_multiply(tensor1, tensor2):
    # Make sure both tensors have the same dimensions
    if len(tensor1) == len(tensor2) and all(len(row1) == len(row2) for row1, row2 in zip(tensor1, tensor2)):
        rows = len(tensor1)
        cols = len(tensor1[0])

        result = [[0 for _ in range(cols)] for _ in range(rows)]

        # Perform element-wise multiplication using nested for loop
        for i in range(rows):
            for j in range(cols):
                result[i][j] = tensor1[i][j] * tensor2[i][j]

        return result
    else:
        raise ValueError("Tensors must have the same dimensions for element-wise multiplication.")

# Example usage
tensor1 = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]

tensor2 = [
    [9, 8, 7],
    [6, 5, 4],
    [3, 2, 1]
]

result = element_wise_multiply(tensor1, tensor2)
@serengil serengil added the enhancement New feature or request label Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant