Questions tagged [scalar]

In computing and programming, a scalar variable or value refers to a single value, as opposed to data structures such as arrays or lists.

In computing and programming, a scalar variable refers to a single value, as opposed to data structures such as or s. A scalar can be of any type, including a complex type such as an object or string. Being scalar only means that it is manipulated as a single value.

As an example, the string type in C++ is considered to be a scalar as it is a primitive type containing a single value, although in the C language there is no such primitive type. Thus, the char array implementation of strings typically used would not be considered as a scalar.

See also:

532 questions
766
votes
23 answers

Constructing pandas DataFrame from values in variables gives "ValueError: If using all scalar values, you must pass an index"

This may be a simple question, but I can not figure out how to do this. Lets say that I have two variables as follows. a = 2 b = 3 I want to construct a DataFrame from this: df2 = pd.DataFrame({'A':a,'B':b}) This generates an error: ValueError:…
Nilani Algiriyage
  • 32,876
  • 32
  • 87
  • 121
450
votes
17 answers

PHP Constants Containing Arrays?

This failed: define('DEFAULT_ROLES', array('guy', 'development team')); Apparently, constants can't hold arrays. What is the best way to get around this? define('DEFAULT_ROLES', 'guy|development team'); //... $default = explode('|',…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
400
votes
15 answers

python: how to identify if a variable is an array or a scalar

I have a function that takes the argument NBins. I want to make a call to this function with a scalar 50 or an array [0, 10, 20, 30]. How can I identify within the function, what the length of NBins is? or said differently, if it is a scalar or a…
otmezger
  • 10,410
  • 21
  • 64
  • 90
185
votes
8 answers

Scalar vs. primitive data type - are they the same thing?

In various articles I have read, there are sometimes references to primitive data types and sometimes there are references to scalars. My understanding of each is that they are data types of something simple like an int, boolean, char, etc. Is there…
90
votes
2 answers

Python RuntimeWarning: overflow encountered in long scalars

I am new to programming. In my latest Python 2.7 project I encountered the following: RuntimeWarning: overflow encountered in long_scalars Could someone please elaborate what this means and what I could do to fix that? The code runs through, but…
timkado
  • 1,922
  • 2
  • 17
  • 27
77
votes
2 answers

TypeError: only length-1 arrays can be converted to Python scalars while trying to exponentially fit data

f=np.loadtxt('Single Small Angle 1.txt',unpack=True,skiprows=2) g=np.loadtxt('Single Small Angle 5.txt',unpack=True,skiprows=2) x = f-g[:,:11944] t=range(len(x)) m=math.log10(abs(x)) np.polyfit(t,m) plt.plot(t,abs(x)) plt.show() I'm just not…
user3291404
  • 781
  • 1
  • 5
  • 5
70
votes
6 answers

How to multiply all integers inside list

Hello so I want to multiply the integers inside a list. For example; l = [1, 2, 3] l = [1*2, 2*2, 3*2] output: l = [2, 4, 6] So I was searching online and most of the answers were regarding multiply all the integers with each other such…
Andre
  • 1,601
  • 6
  • 19
  • 19
66
votes
3 answers

Excel: Scalar product of two ranges

I am trying to find a proper way to calculate the scalar product of two ranges. For instance, the product of A1:A3 and B1:B3 would be A1*B1 + A2*B2 + A3*B3. Is there a good way to do this? Hardcoding this calculation is quite a tedious thing to do…
Lee White
  • 3,649
  • 8
  • 37
  • 62
64
votes
4 answers

Fatal error: Uncaught Error: Cannot use a scalar as an array warning

I have the following code: $final = [1 => 2]; $id = 1; $final[$id][0] = 3; The code seems to work fine, but I get this warning: Warning: Cannot use a scalar value as an array in line X (the line with: $final[$id][0] = 3). Can anyone tell me…
zozo
  • 8,230
  • 19
  • 79
  • 134
47
votes
3 answers

how to create and call scalar function in sql server 2008

I have created a Scalar Functions, it was created successfully, but when I call the function using select statement, it says invalid object, I altered the function, I got the message command completed successfully, but when I call the function, I…
Abbas
  • 4,948
  • 31
  • 95
  • 161
35
votes
4 answers

What does addScalar do?

The JavaDoc says: SQLQuery org.hibernate.SQLQuery.addScalar(String columnAlias, Type type) Declare a scalar query result I know what executeScalar is in C#, but this scalar and C# scalar seem to be absolutely different.
superM
  • 8,605
  • 8
  • 42
  • 51
33
votes
5 answers

When to return a pointer, scalar and reference in C++?

I'm moving from Java to C++ and am a bit confused of the language's flexibility. One point is that there are three ways to store objects: A pointer, a reference and a scalar (storing the object itself if I understand it correctly). I tend to use…
theone
  • 411
  • 1
  • 5
  • 4
28
votes
6 answers

Can you force either a scalar or array ref to be an array in Perl?

I have a perl variable $results that gets returned from a service. The value is supposed to be an array, and $results should be an array reference. However, when the array has only one item in it, $results will be set to that value, and not a…
Rudd Zwolinski
  • 26,712
  • 17
  • 57
  • 60
20
votes
8 answers

c# LINQ: how to retrieve a single result

Kind of new to linq, whats the simplest way to retrieve a single result using linq? example, my query var query = from c in db.productInfo where c.flavor == "Classic Coke" && c.container == "Can" select c.co2Target; it should only…
Sinaesthetic
  • 11,426
  • 28
  • 107
  • 176
19
votes
4 answers

How to multiply a tensor row-wise by a vector in PyTorch?

When I have a tensor m of shape [12, 10] and a vector s of scalars with shape [12], how can I multiply each row of m with the corresponding scalar in s?
Chris
  • 1,266
  • 4
  • 16
  • 34
1
2 3
35 36