Deep in the Crystal Cave, the enigmatic Pattern Weaver creates stunning sequences by uncovering the intricate relationships between crystals. Each crystal is marked by a unique numeric value, and the Weaver emphasizes that the true power of any crystal depends on how it interacts with all others. You have discovered N crystals, each with a specific value, and your task is to reveal their enhanced patterns by analyzing these relationships using self-attention. Given a sequence of crystals and their values, your task is to implement a simplified self-attention mechanism. For each crystal, calculate its relationship with every other crystal, compute the attention scores using the softmax function, and derive the final weighted pattern for each crystal. This Problem was made with the help of GroundZero AI
Examples
number of crystals: 5
values: 4 2 7 1 9
dimension: 1[8.9993, 8.9638, 9.0, 8.7259, 9.0]Starter Code
import numpy as np
def softmax(values):
# Implement the softmax function
pass
def pattern_weaver(n, crystal_values, dimension):
# Your code here
return np.round(x,3)