importnumpyasnpimportmatplotlib.pyplotaspltimportmatplotlibimportosfrommathimportgcd# Ensure output directory existsos.makedirs("/mnt/data",exist_ok=True)# Define the list SS=[1,2,3,4,5,6,7,8,9,10]n=len(S)# Create the GCD matrixgcd_matrix=np.zeros((n,n),dtype=int)foriinrange(n):forjinrange(n):gcd_matrix[i,j]=gcd(S[i],S[j])# Plot the heatmapplt.style.use('seaborn-v0_8')fig,ax=plt.subplots(figsize=(8,6))cax=ax.matshow(gcd_matrix,cmap='viridis')# Add colorbarfig.colorbar(cax)# Set axis labelsax.set_xticks(np.arange(n))ax.set_yticks(np.arange(n))ax.set_xticklabels(S)ax.set_yticklabels(S)plt.xlabel("S values")plt.ylabel("S values")plt.title("Heatmap of GCD Matrix")# Rotate x-axis labels for better readabilityplt.xticks(rotation=45)# Save the figureoutput_path="/mnt/data/gcd_matrix_heatmap.png"plt.tight_layout()plt.savefig(output_path)plt.close()
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse