Home > Blockchain >  Cannot assignt to literal
Cannot assignt to literal

Time:10-07

In my code i want to create simply the tsne_results list which will contain [tsne_results_50,tsne_results_30,tsne_results_50,tsne_results_100]. But i cannot since it says"Cannot assignt to literal".How can i fix iy?

perplexity_values=[5,30,50,100]
tsne_results=[]

for value in perplexity_values: 
  tsne = TSNE(n_components=2, verbose=1, perplexity=value, n_iter=250)
  f'tsne_results_{(str(value))}' = tsne.fit_transform(X)
  f'tsne_results_{(str(value))}'.append(tsne_results)

CodePudding user response:

Variables cannot be created dynamically in Python. You see to want to assign a value to a string, and think that that will create a variable.

It looks you're trying to do something like:

tsne_results = {}
for value in perplexity_values:
     ....
     tsne_results[value] = tsne.fit_transform(X)
  • Related