Programming Articles - Page 1157 of 3363

What are some of the important Scientific Libraries used in Lua programming?

Mukul Latiyan
Updated on 19-Jul-2021 11:25:40

405 Views

While we know that Lua does a great job when we want to use it as an embedded language, it can also exceed its basic uses and can be used in extreme cases such as Machine Learning and statistical analysis.There are many scientific libraries that are present in the market for this particular case of making more out of Lua. Let’s explore what these libraries are and what they do.The first name that comes to my mind when talking about Lua and machine learning in the same sentence is of the Torch project. The torch project is a scientific computing ... Read More

What are Closures in Lua Programming?

Mukul Latiyan
Updated on 19-Jul-2021 11:23:46

1K+ Views

In Lua, any function is a closure. In a narrower sense, a closure is an anonymous function like the returned function in your example.Closures are first-class: they can be assigned to variables, passed to functions and returned from them. They can be both keys and values in Lua tables.Unlike C++ or PHP, closures in Lua have access to all variables in local scope— upvalues with no need to declare upvalues explicitly. Upvalues survive when code execution leaves the block where they were set.Now that we know what a closure is and why it is useful, let’s take an example and ... Read More

The __index metamethod in Lua Programming

Mukul Latiyan
Updated on 19-Jul-2021 11:20:29

2K+ Views

Whenever we try to access a field that hasn’t been declared in a table in Lua, the answer we get is nil. While this is true, but the reason for it is that when such access happens, the interpreter triggers a search for an __index metamethod and if it doesn’t find any method named __index, then we get nil as an answer; else we will get whatever the value of the field is set in the __index metamethod.We can explicitly put in the __index method in a table and provide it the named values that we want it to return ... Read More

table.unpack() function in Lua programming

Mukul Latiyan
Updated on 19-Jul-2021 11:17:40

17K+ Views

When we want to return multiple values from a table, we make use of the table.unpack() function. It takes a list and returns multiple values.Syntaxtable.unpack{x, y, z, ....}ExampleThe table.unpack() function provides us with all the values that are passed to it as an argument, but we can also specify which value we want by following the example shown below − Live Demoa, b = table.unpack{1, 2, 3} print(a, b)In the above example, even though the table.unpack() function contains different values, namely 1, 2 and 3, we only are storing the first two values, i.e., a and b and the value 3 ... Read More

table.pack() function in Lua programming

Mukul Latiyan
Updated on 19-Jul-2021 11:16:16

6K+ Views

When we want to return a table as a result from multiple values passed into a function, then we make use of the table.pack() function. The table.pack() function is a variadic function.Syntaxtable.pack(x, y, z, ....)ExampleThe table.pack() function provides a table formed with all the values that are passed to it as an argument, consider the example shown below − Live Demoa = table.pack(1, 2, 3) print(a) print(a.n)In the above example, we passed three numbers to the table.pack() function as an argument and then we are printing the returned value, i.e., which will hold the address of the table that contains the ... Read More

How to create violin plot for categories with grey color palette using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 13-Aug-2021 09:14:41

360 Views

To create violin plot for categories with grey color palette using ggplot2, we can follow the below steps −First of all, create a data frame.Then, create the violin plot for categories with default color of violins.Create the violin plot for categories with color of violins in grey palette.Creating the data frameLet's create a data frame as shown below − Live Demo> Group Score df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −     Group  Score 1   Second   405 2    Third   947 3    First    78 ... Read More

How to divide the data frame rows in R by row standard deviation?

Nizamuddin Siddiqui
Updated on 13-Aug-2021 09:12:04

512 Views

To divide the data frame row values by row standard deviation in R, we can follow the below steps −First of all, create a data frame.Then, use apply function to divide the data frame row values by row standard deviation.Creating the data frameLet's create a data frame as shown below − Live Demo> x y df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −      x     y 1   1.48  0.86 2  -0.14 -0.58 3  -0.25  1.22 4   0.18  0.25 5   0.50  0.68 6  -1.34 ... Read More

How to subtract column values from column means in R data frame?

Nizamuddin Siddiqui
Updated on 13-Aug-2021 09:09:25

3K+ Views

To subtract column values from column means in R data frame, we can follow the below steps −First of all, create a data frame.Then, find the column means using colMeans function.After that, subtract column values from column means.Creating the data frameLet's create a data frame as shown below − Live Demo> x1 x2 x3 df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −   x1  x2  x3 1  54  73  57 2  79  52  92 3  87  51  47 4  13  12   1 5  70  90  19 6  15  99 ... Read More

How to color a Seaborn boxplot based on DataFrame column name in Matplotlib?

Rishikesh Kumar Rishi
Updated on 08-Jul-2021 11:21:06

617 Views

To color a Seaborn boxplot based on dataframe column name, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a Pandas dataframe with two columns, col1 and col2.Make a boxplot with horizontal orientation.Get the boxes artists.Iterate the boxes and set the facecolor of the box.To display the figure, use show() method.Exampleimport seaborn as sns import matplotlib.pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(       [[2, 4],       [7, 2]       ], columns=['col1', 'col2']) ... Read More

How to draw rounded line ends using Matplotlib?

Rishikesh Kumar Rishi
Updated on 08-Jul-2021 11:18:41

2K+ Views

To draw rounded line ends using matplotlib, we can use solid_capstyle='round'.StepsSet the figure size and adjust the padding between and around the subplots.Create random x and y data points using numpy.Create a figure and a set of subplots.Plot x and y data points using plot() method, with solid_capstyle in the method argument.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.randn(5) y = np.random.randn(5) fig, ax = plt. subplots() ln, = ax.plot(x, y, lw=10, solid_capstyle='round', color='red') plt.show()OutputRead More

Advertisements