-4

I am getting numpy array in Python, which I am converting to list and it looks like this

[0.0003323988609746907,inf , 0.6412162477054423, 9.545269768297, -1323.6125512135593, -1512.0718516647562, -2073.6020535721273, -2578.302701605687, 0.27304053703708875, 0.5580326301604825, 0.34912544310755905, 0.550917816717867, 49.7455110651867, 1821.15723334093, -61.3700045037962, -49.400686298507, 13.11111111111111, 26.0, 12.222222222222221, 18.0, 0.3111111111111111, 0.325, 0.4148148148148148, 0.43333333333333335, 0.5930328763108722, 0.7343377194812131, 0.23685155593995189, 0.6754530381265557, 0.16582557525922734, 0.009828988419922594, 0.00017475124235758377, 0.0003779194334627987, 0.0008100853061379151, 2.9387129701088046, 0.41880424639672703, 2.639057329615259, 0.0, 2.75, 2.807354922057604, 0.07124096827009982, 0.003, 0.1435385870250432, 0.5547574989867142, 0.1445909953802227]

Here 2nd array value is NaN.

I want to assign this array to C++ double array. I have declareted it this way

double feature_values[] {0.0003323988609746907, "NaN", 0.6412162477054423, 9.545269768297, -1323.6125512135593, -1512.0718516647562, -2073.6020535721273, -2578.302701605687, 0.27304053703708875, 0.5580326301604825, 0.34912544310755905, 0.550917816717867, 49.7455110651867, 1821.15723334093, -61.3700045037962, -49.400686298507, 13.11111111111111, 26.0, 12.222222222222221, 18.0, 0.3111111111111111, 0.325, 0.4148148148148148, 0.43333333333333335, 0.5930328763108722, 0.7343377194812131, 0.23685155593995189, 0.6754530381265557, 0.16582557525922734, 0.009828988419922594, 0.00017475124235758377, 0.0003779194334627987, 0.0008100853061379151, 2.9387129701088046, 0.41880424639672703, 2.639057329615259, 0.0, 2.75, 2.807354922057604, 0.07124096827009982, 0.003, 0.1435385870250432, 0.5547574989867142, 0.1445909953802227};

I have tried to add Nan with and without " but still it gives this error

 error: expected ';' at end of declaration

Can you please guide me how can I declarete double array in C++ with NaN value in it

user3449212
  • 685
  • 1
  • 10
  • 20
  • 5
    [`std::numeric_limits::quiet_NaN()`](https://en.cppreference.com/w/cpp/types/numeric_limits/quiet_NaN) – François Andrieux May 09 '22 at 13:19
  • I check all of the links but still I am not clear on how do I make one of the array element `NaN` @FrançoisAndrieux I really appreciate if you answer in the context of my variable declaration – user3449212 May 09 '22 at 13:26
  • Also note that `inf` technically is NOT `NaN`. They are quite different in the standard – Lala5th May 09 '22 at 13:27
  • I added `#include ` and then put one of the array value `nan` but still same error – user3449212 May 09 '22 at 13:28
  • 1
    You forgot `=` between `[]` and the opening `{`. – François Andrieux May 09 '22 at 13:28
  • @user3449212 The link describes a function. You call it to get a `NaN` value. Replace `"NaN" with calling the function. Consider using a constant if you need to call the function more than once. – François Andrieux May 09 '22 at 13:29
  • I added `=` now it says `func.cpp:92669:750: error: cannot initialize an array element of type 'double' with an lvalue of type 'double (const char *)'` – user3449212 May 09 '22 at 13:31
  • I checked above link, it explains diff ways to generate `NaN`, but could not see way to assign `NaN` in it – user3449212 May 09 '22 at 13:33
  • 1
    The very first answer on the linked page, as well as the first comment on this question, both say _exactly_ what to write. – ChrisMM May 09 '22 at 13:37
  • 1
    [`std::nan("")`](https://en.cppreference.com/w/cpp/numeric/math/nan) – Eljay May 09 '22 at 13:42

0 Answers0