# Remove errors from code of sparse matrix using linked list

G

#### Garvit

##### Guest
Garvit Asks: Remove errors from code of sparse matrix using linked list
Not getting any error on running the code. On debugging Segmentation fault on if(j == temp->col) when j = 4

Create function "seems" to have created the function well but I'm unsure why the segmentation fault.

The matrix(5x6) I input was 0 0 0 0 0 1\n 1 0 0 0 0 1\n 1 1 0 0 0 1\n 1 1 1 1 0 0\n 0 0 0 0 1 1\n

The output I received was 0 0 0 0 0 1\n 1 0 0 0 0 1\n 1 1 0 0 0 1\n 1 1 1 1

Code:
#include <stdio.h>
#include <stdlib.h>

struct node{
int col;
int data;
struct node *next;
}*first;

void create(struct node *A[], int m, int n){
struct node *temp, *last;
int noe, flag = 0;
for(int i = 0; i < m; i++){
flag = 0;
A[i] = (struct node *) malloc(sizeof(struct node));
last = A[i];

printf("Enter no. of items in Row %d :", i);
scanf("%d", &noe);

for(int j = 0; j < noe; j++){
temp = (struct node *) malloc(sizeof(struct node));

printf("Enter column and elmeent :");
scanf("%d%d", &temp->col, &temp->data);

temp->next = NULL;
if(last == A[i] && flag == 0){
A[i] = temp;
flag = 1;
}
else
last->next = temp;

last = temp;

}
last = NULL;
}
}

void display(struct node *A[], int m, int n){
struct node *temp;
for(int i = 0; i < m; i++){
temp = A[i];
for(int j = 0; j < n; j++){
if(j == temp->col){
printf("%d ", temp->data);
temp = temp->next;
}
else
printf("0 ");
}
printf("\n");
}
}

int main(){

int m = 5, n = 6;
struct node *A[m];

create(A, m, n);
display(A, m, n);

return 0;
}

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### How to perform feature engineering on columns with multiple categories?

Prateek Coder Asks: How to perform feature engineering on columns with multiple categories?
I want to perform feature engineering on a data that mostly contains textual data and lot of columns with multiple categories like Supervisor, location code, employee class, business unit, job title, etc. What should be the best approach to do this? I have binary encoded the column with 2-3 categories or performed one hot encoding, but these columns contains different categories from 8 to 150. Different location will play major role in prediction, so will the employee class or business unit etc and I believe they will be very important for my model.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### [Solved] Create Buffer but keep original Attribute table

J.Beer Asks: Create Buffer but keep original Attribute table
I want to create a buffer around a number of features. It is important for me to keep the attributes of the features in the new buffer.shp layer. When I try to write a new VectorLayer with a QgsVectorFileWriter, I do get the buffered polygons and also the fields of the original layer get copied over, however the attribute table stays empty.

How can I copy over the attributes of the original layer to the buffer layer?

As you can see I already tried to load the attributes using the . attributes() method on the QgsFeature object and setting the attributes. However I feel I am missing something here.

Code:
for f in feats:
attributes = f.attributes()
f.setAttributes(attributes)

See full code below:

Code:
path = '/Volumes/VAW_ETH-Z/M.Thesis/data/geospatial/'

sgi_filtered = QgsVectorLayer(path + 'sgi_filtered.shp')

## Create buffer around filtered sgi
outFn = path + 'gl_buffer3.shp'
bufferDist = 50 # in map units

fields = sgi_filtered.fields()
feats = sgi_filtered.getFeatures()

writer = QgsVectorFileWriter(
outFn,
'utf-8',
fields,
QgsWkbTypes.Polygon,
sgi_filtered.sourceCrs(), # loads the reference system of the source feature
'ESRI Shapefile')

for f in feats:
attributes = f.attributes()
f.setAttributes(attributes)
geom = f.geometry()
buff = geom.buffer(bufferDist, 5)
f.setGeometry(buff)

writer.addFeature(f)

Screenshot of the Attribute Table below (it shows the fields but no attributes):

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

#### [Solved] Saving a Project Folder as a template (QGIS 3.28)

• Ben Sear
• Geography
• Replies: 0
Ben Sear Asks: Saving a Project Folder as a template (QGIS 3.28)
I am looking to create a template for easy layout integration for new QGIS project files, but when saving the project file to a template using save to > template, the file does not appear in the project templates as a template file, but just a new project file. I read that you need to restart GIS once you saved a project file as a template but restarting does not change the project file to being a template. Has anyone experienced saving template before and have any suggestions? Thank you.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

#### Method of cooling a gas without liquid evaporation for Sci-fi novel

• user2765977
• Chemistry
• Replies: 0
user2765977 Asks: Method of cooling a gas without liquid evaporation for Sci-fi novel
sorry for the amateur question here.

I know little about science, but regardless am writing a fictional amateur novel that deals with a lot of chemistry stuff, especially gasses.

My protagonist needs a clever method of cooling a gas. He has access to several gasses (CO2, O2, H2, nitrogen) in varying temperatures (70c and up). Unfortunately no water (at least not more than a few bottles). The atmosphere he is working under (planet atmosphere) is in the range of 150c and at a pressure of roughly 150kpa in the novel.

He also has access to sci-fi style manufacturing machines that can simply 'make' parts, like pipes, valves, pumps, that sort of thing.

I am looking for a clever way or really any way at all, that he can use to cool down some O2 to at least under 40c in such a situation.

My amateur reading online suggests the main way, is via liquid evaporation, but I doubt that would work in the above scenario easily.

Does anybody have any ideas? Is this even possible?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### Is there a "fundamental problem of thermodynamics"?

• agaminon
• Physics
• Replies: 0
agaminon Asks: Is there a "fundamental problem of thermodynamics"?
The "fundamental problem of mechanics" can be boiled down to finding and solving the equation of motion of a system. Similar statements can be said for quantum mechanics for the Schrödinger equation and for electrodynamics and Maxwell's equations, etc. But is there such a thing for thermodynamics? Is there a formulation that allows for this kind of perspective?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### What does this vertical line notation mean?

• Lambda
• Physics
• Replies: 0
Lambda Asks: What does this vertical line notation mean?
Here is the definition of the Noether momentum in my script.

$$I = \left.\frac{\partial L}{\partial \dot{x}} \frac{d x}{d \alpha} \right|_{\alpha=0} = \frac{\partial L}{\partial \dot{x}} = m \dot{x} = p_x.$$ But I don't understand exactly what this vertical line with $\alpha=0$ means, I would have interpreted it as $\frac{dx}{d0}$ now.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### Does diffusion of a spring depend on the spring’s equilibrium length?

• Robert S. Pierre
• Physics
• Replies: 0
Robert S. Pierre Asks: Does diffusion of a spring depend on the spring’s equilibrium length?
Say we perform a random walk on $\mathbb{Z}$ with two equal particles that are connected by a spring with spring constant $K$ and equilibrium length $a$, where at each time step each particle has probability $\frac{1}{2}$ of making a step $\pm1$. However, at each step a random number $q\in[0,1]$ is sampled in order to refuse the move if $$q\geq\exp\left(\Delta E\right),$$ where $\Delta E$ is the difference in elastic energy between the two time steps.

Does the diffusion coefficient depend on the equilibrium length $a$?

I know that the diffusion is independent of the spring constant $K$, so we find the same diffusion coefficient for all $K$, namely that of two independent particles. I assume the same holds for the equilibrium length, but is this true and how can I see this?
And furthermore, what role does the initial extension of the spring play? Say the initial length of the spring $x_0$ is not equal to $a$, then the whole system will need a while to equilibrize, as opposed to when we start with $x_0=a$.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.