Skip to content
The Chat Archive
llama-2-13b-chat· Meta Arena Human Preference 55K

print with a fixed number of decimals, in one row of code, without iterations, using…

  1. User

    print with a fixed number of decimals, in one row of code, without iterations, using pytorch builtins print(f'{F.softmax(logits/0.1, dim = -1)}') # valori one hot --> meno valori tra cui scegliere

  2. Assistant

    You can use the torch.round function to round the values to a fixed number of decimals without iterations. Here's an example:

    print(f'{F.softmax(logits/0.1, dim = -1).round(2)}')
    

    This will round the values in the softmax output to 2 decimal places. The dim parameter specifies the dimension to apply the operation to, in this case -1 means all dimensions.

    Alternatively, you can use the torch.floor function to round down the values to the nearest integer, and then use the torch.ceil function to round up the values to the desired number of decimals. Here's an example:

    print(f'{F.floor(logits/0.1, dim = -1).ceil(2)}')
    

    This will round the values in the logits output to the nearest integer, and then round up the values to 2 decimal places.

    Both of these methods will print the output in one row of code, without any iterations.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.