Answers for "save an array to txt file"

C
-2

save numpy array to text file

a_file = open("test.txt", "w")
for row in an_array:
    np.savetxt(a_file, row)

a_file.close()
Posted by: Guest on February-10-2021
0

Print array to a file

//Either var_export or set print_r to return the output instead of printing it.
$b = array (
    'm' => 'monkey', 
    'foo' => 'bar', 
    'x' => array ('x', 'y', 'z'));

$results = print_r($b, true); // $results now contains output from print_r
//You can then save $results with file_put_contents. Or return it directly when writing to file:

file_put_contents('filename.txt', print_r($b, true));
Posted by: Guest on October-07-2021

Code answers related to "C"

Browse Popular Code Answers by Language