output

Why is snprintf consistently 2x faster than ostringstream for printing a single number?

自古美人都是妖i 提交于 2019-12-24 00:44:40
问题 I was testing various approaches at formatting double s in C++, and here's some code I came up with: #include <chrono> #include <cstdio> #include <random> #include <vector> #include <sstream> #include <iostream> inline long double currentTime() { const auto now = std::chrono::steady_clock::now().time_since_epoch(); return std::chrono::duration<long double>(now).count(); } int main() { std::mt19937 mt(std::random_device{}()); std::normal_distribution<long double> dist(0, 1e280); static const

Reading out specific points off the Matlab / Octave fft2() function output

不问归期 提交于 2019-12-24 00:38:44
问题 I am getting familiarized with Octave and the function fft2() . In this toy example, I am aiming at producing the 2D DFT of the following 256 x 256 png image: To be able to understand the output easily, I try to convert this image into a 256 x 256 image, eliminating color information: Im = imread('circ.png'); pkg load image Im = rgb2gray(Im); figure, imshow(Im) After this bookkeeping preliminaries I run: A = fft2(double(Im)); OK. Now I take the same image, and analyze it with ImageJ, checking

How to write to a file using open() and printf()?

安稳与你 提交于 2019-12-24 00:36:27
问题 I am opening a file with open(), and need to print to that file using printf with no output to the console. How do I do this? I can successfully create the file, and printf to the console, but that is not correct. int main(int argc, char *argv[]) { int fd; char *name = "helloworld"; fd = open(name, O_CREAT); char *hi = "Hello World"; printf("%s\n", hi); close(fd); exit(0); } I need the program to have no output to the console, but if I look at the file helloworld , it should have "Hello World

for loop taking too long to produce/export output in Python

依然范特西╮ 提交于 2019-12-23 23:19:19
问题 This question is a continuation of a previous question for loop taking too long to produce output that I asked earlier today. As advised to me in one comment, I used pandas for reading excel files in place of xlrd . Here is the program that I wrote - import pandas as pd import numpy as np no_of_columns = 10000 Book1 = pd.read_excel("D:\Python\Book1.xlsx",header=None,name=range(no_of_columns)) Book2 = pd.read_excel("D:\Python\Book2.xlsx",header=None,name=range(no_of_columns)) Book3 = pd.read

Keeping the user's input intact when outputing to terminal at the same time

喜欢而已 提交于 2019-12-23 23:06:31
问题 To simplify, let's say I'm trying to write a command line two-way chat in Python. I would like the user to input his message with input() at the command prompt, but a listening thread could print a message at any moment. By default, this would "break" the user's input. Visually something like this: userB>Stop interuserA wrote:Hey check this out! rupting me! The closest I was able to find was this answer here which is almost, but not exactly, what I'm looking for, but it did point me towards

cURL live output CLI

徘徊边缘 提交于 2019-12-23 21:29:02
问题 I try to have a "live output" of a web page in a shell script ; to explain, a little example : With this "localhost/index.php" like this: <?php header('Content-type: text/html; charset=utf-8'); echo 'Start<br />'.PHP_EOL; for( $i = 0 ; $i < 10 ; $i++ ) { echo '.'; flush();ob_flush(); sleep(1); } echo PHP_EOL.'<br />End'; ?> I want to write a shell script which permit to have the "dots" on the screen that appears each second. If I try this : #!/bin/bash curl 'localhost/index.php' It shows the

Fortran: add column to file (i.e. skip a varying amount of horizontal spaces)

丶灬走出姿态 提交于 2019-12-23 18:14:40
问题 I'm a bloody beginner to Fortran (f90) and some apparently easy problems turn out to cause severe headaches...Thanks for helping me with this one: My code runs through a loop, processes data and writes them into a file. I'd like to have those data written in columns of the same file until the looping is finished. OPEN (unit=11,file=filename // '.csv') WRITE(11,'(i4,A1,f10.6)') NUM4 , tab, NUMfloat10_6 CLOSE(11) This code works fine for the saving of a single dataset. "tab" is defined as char

Access or parse elements in summary() in R

ε祈祈猫儿з 提交于 2019-12-23 16:44:50
问题 I run the following R commands to make a Dunnett's test and get the summary. How can I access each row of the Linear Hypotheses below, which is part of summary output? Basically I do not know the structure of the summary. I attempted using names() but it seems not working as I do not see any named attribute to give that. library("multcomp") Group <- factor(c("A","A","B","B","B","C","C","C","D","D","D","E","E","F","F","F")) Value <- c(5,5.09901951359278,4.69041575982343,4.58257569495584,4

Write dynamical arrays in Fortran 90 [duplicate]

寵の児 提交于 2019-12-23 12:56:21
问题 This question already has answers here : Format string for output dependent on a variable (4 answers) Dynamic output format setting (2 answers) Closed 2 years ago . I have arrays with dynamical dimension ( dimx , dim ) and I need a way to write such arrays in a file through the Write instruction, the problem is that until now I haven't been able to produce such files in a automatic way, I mean until now I have to change the dimension of the array in the Write instruction by hand and I need a

System.out.println to text file

匆匆过客 提交于 2019-12-23 12:44:41
问题 I was searching a way to get System.out.println texts and save them on a .txt file, for example: System.out.println("Java vendor: " + System.getProperty("java.vendor")); System.out.println("Operating System architecture: " + System.getProperty("os.arch")); System.out.println("Java version: " + System.getProperty("java.version")); System.out.println("Operating System: " + System.getProperty("os.name")); System.out.println("Operating System Version: " + System.getProperty("os.version")); System