initialization

TensorFlow: generating a random constant

ぃ、小莉子 提交于 2020-01-21 04:42:04
问题 In ipython I imported tensorflow as tf and numpy as np and created an TensorFlow InteractiveSession . When I am running or initializing some normal distribution with numpy input, everything runs fine: some_test = tf.constant(np.random.normal(loc=0.0, scale=1.0, size=(2, 2))) session.run(some_test) Returns: array([[-0.04152317, 0.19786302], [-0.68232622, -0.23439092]]) Just as expected. ...but when I use the Tensorflow normal distribution function: some_test = tf.constant(tf.random_normal([2,

Initializing static array of strings (C++)?

我只是一个虾纸丫 提交于 2020-01-21 01:15:47
问题 I can't for the life of me figure out how to do this properly. I have a class that needs to store some constants (text that corresponds to values in an enum type) - I have it declared like this (publicly) in my class: const static char* enumText[]; And I'm trying to initialize it like this: const char* MyClass::enumText[] = { "A", "B", "C", "D", "E" }; However gcc gives me the following error: 'const char* MyClass::enumText[]' is not a static member of 'class MyClass' What am I doing wrong?

Is there a difference between initializing a variable and assigning it a value immediately after declaration?

流过昼夜 提交于 2020-01-20 07:08:18
问题 Assuming a purely non-optimizing compiler, is there any difference in machine code between initializing a variable and assigning it a value after declaration? Initialization method : int x = 2; Assignment method : int x; x = 2; I used GCC to output the assembly generated for these two different methods and both resulted in a single machine instruction: movl $2, 12(%esp) This instruction just sets the memory held by the x variable to the value of 2 . GCC may be optimizing this because it can

Is there a difference between initializing a variable and assigning it a value immediately after declaration?

空扰寡人 提交于 2020-01-20 07:07:29
问题 Assuming a purely non-optimizing compiler, is there any difference in machine code between initializing a variable and assigning it a value after declaration? Initialization method : int x = 2; Assignment method : int x; x = 2; I used GCC to output the assembly generated for these two different methods and both resulted in a single machine instruction: movl $2, 12(%esp) This instruction just sets the memory held by the x variable to the value of 2 . GCC may be optimizing this because it can

Does the equal sign make a difference in brace initialization? eg. 'T a = {}' vs 'T a{}'

时光怂恿深爱的人放手 提交于 2020-01-19 07:34:46
问题 Here are two ways to initialize a variable in C++11: T a {something}; T a = {something}; I tested these two in all scenarios I could think of and I failed to notice a difference. This answer suggests that there is a subtle difference between the two: For variables I don't pay much attention between the T t = { init }; or T t { init }; styles, I find the difference to be minor and will at worst only result in a helpful compiler message about misusing an explicit constructor. So, is there any

Does the equal sign make a difference in brace initialization? eg. 'T a = {}' vs 'T a{}'

旧时模样 提交于 2020-01-19 07:31:18
问题 Here are two ways to initialize a variable in C++11: T a {something}; T a = {something}; I tested these two in all scenarios I could think of and I failed to notice a difference. This answer suggests that there is a subtle difference between the two: For variables I don't pay much attention between the T t = { init }; or T t { init }; styles, I find the difference to be minor and will at worst only result in a helpful compiler message about misusing an explicit constructor. So, is there any

C# error: Use of unassigned local variable

半城伤御伤魂 提交于 2020-01-19 03:49:42
问题 I'm not sure why I'm getting this error, but shouldn't this code compile, since I'm already checking to see if queue is getting initialized? public static void Main(String[] args) { Byte maxSize; Queue queue; if(args.Length != 0) { if(Byte.TryParse(args[0], out maxSize)) queue = new Queue(){MaxSize = maxSize}; else Environment.Exit(0); } else { Environment.Exit(0); } for(Byte j = 0; j < queue.MaxSize; j++) queue.Insert(j); for(Byte j = 0; j < queue.MaxSize; j++) Console.WriteLine(queue.Remove

C# error: Use of unassigned local variable

一笑奈何 提交于 2020-01-19 03:49:14
问题 I'm not sure why I'm getting this error, but shouldn't this code compile, since I'm already checking to see if queue is getting initialized? public static void Main(String[] args) { Byte maxSize; Queue queue; if(args.Length != 0) { if(Byte.TryParse(args[0], out maxSize)) queue = new Queue(){MaxSize = maxSize}; else Environment.Exit(0); } else { Environment.Exit(0); } for(Byte j = 0; j < queue.MaxSize; j++) queue.Insert(j); for(Byte j = 0; j < queue.MaxSize; j++) Console.WriteLine(queue.Remove

Is un-initialized integer always default to 0 in c?

孤街浪徒 提交于 2020-01-18 09:49:25
问题 I'm reading source code of nginx and find it's not initializing many of the numerical variables, including ngx_int_t ngx_last_process; ,here ngx_int_t defined as long int #if 0 ngx_last_process = 0; #endif So here @Igor Sysoev think it unnecessary to do the initialization? But in the programe it's assuming the default value is 0 : for (s = 0; s < ngx_last_process; s++) { if (ngx_processes[s].pid == -1) { break; } } Is it guranteed that un-initialized variable will have 0 value in c at all?

How non-static initializer block invoked? [closed]

自古美人都是妖i 提交于 2020-01-17 01:05:21
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . public class A{ { System.out.println("hi i am IIB"); } public A(){ System.out.println("hi i am constructor"); } public static void main(String... args){ A objA=new A(); } } 回答1: iib will get execute before the constructor is called No, this is not what happens. The code written in instance