[GO] python> Display 3 decimals in ".3f, .3f, .3f" format / Get 3 coordinate values in the range [-1: 1]

I got three random numbers and tried to display them in a format like "% .3f,% .3f,% .3f" in C language.

http://ideone.com/WGaHJR

import numpy as np
from numpy.random import *

pos = tuple( rand(3) )

frm = '%.3f, %.3f, %.3f'
print pos

print frm % tuple(pos)

result


(0.076222111784701618, 0.76602747950227201, 0.13864621611927097)
0.076, 0.766, 0.139

Reference http://stackoverflow.com/questions/7568627/using-python-string-formatting-with-lists

v0.2

Change the coordinate value to the range [-1,1].

http://ideone.com/PZPfxe

import numpy as np
from numpy.random import *
 
 
for loop in range(15):
	pos = tuple( rand(3) * 2 - 1 )
 
	frm = '[ %.3f, %.3f, %.3f ],'
	# print pos
 
	print frm % tuple(pos)

(Addition) @ Shiracamus's comment is better than the above.

Recommended Posts

python> Display 3 decimals in ".3f, .3f, .3f" format / Get 3 coordinate values in the range [-1: 1]
Get the result in dict format with Python psycopg2
Get the MIME type in Python and determine the file format
Get the desktop path in Python
Get the script path in Python
Get the desktop path in Python
Get the host name in Python
[python] Get the rank of the values in List in ascending / descending order
Get the top nth values in Pandas
Display Python 3 in the browser with MAMP
Get the EDINET code list in Python
format in python
[Python] Get the files in a folder with Python
Get the weather in Osaka via WebAPI (python)
[Python] How to change the date format (display format)
Get the caller of a function in Python
Get the X Window System window title in Python
[Python] Display the Altair legend in the plot area
How to get the files in the [Python] folder
I want to display the progress in Python!
Get coordinate values and keyboard input values by clicking on the python / matplotlib diagram
Display n digits after the decimal point in python
How to get the variable name itself in python
How to get the number of digits in Python
[Python] Get the numbers in the graph image with OCR
[python] Get the list of classes defined in the module
Get environment variables in Python, otherwise set default values
Image format in Python
Get the size (number of elements) of UnionFind in Python
Get the value selected in Selenium Python VBA pull-down
Swapping values in Python
Get date in Python
Display a histogram of image brightness values in python
Get the URL of the HTTP redirect destination in Python
[Python] How to output the list values in order
Python OpenCV tried to display the image in text.
Get your heart rate from the fitbit API in Python!
Get the number of specific elements in a python list
Get the value while specifying the default value from dict in Python
How to get the last (last) value in a list in Python
Automatically get the port where Arduino is stuck in Python
[Python] Display the elapsed time in hours, minutes, and seconds (00:00:00)
How to get all the keys and values in the dictionary
Get the current date and time in Python, considering the time difference
Get the index of each element of the confusion matrix in Python
Get YouTube Comments in Python
Easily format JSON in Python
Get last month in python
Download the file in Python
Find the difference in Python
Display UTM-30LX data in Python
Get Terminal size in Python
[Python] Get the previous month
Explicitly get EOF in python
[Python 2/3] Parse the format string
Get Evernote notes in Python
Transfer parameter values in Python
About "for _ in range ():" in python
Get Japanese synonyms in Python
Get the Ticker Symbol for US exchange listed stocks in Python
Determine the date and time format in Python and convert to Unixtime