Adding Matrix with Variables in Jupyter Notebook

In summary, the conversation discusses creating an SFrame with 2 columns and 11 rows from a list of selected words. The suggested method is to use a dictionary to store the counts and then convert it into an SFrame using the gl.SFrame() function.
  • #1
WWGD
Science Advisor
Gold Member
7,339
11,276
i All,
I have a Jupyter Python Notebook with data like below:
\
upload_2016-12-5_17-9-31.png


I want to create an SFrame with 2 columns and 11 rows.Each row has two entries:
One containing the name of each word and the other entry containing the total count of the word. The words are part of a list called 'Selected Words' . I am kind of clueless,
I know how to create new columns for an existing SFrame, but no clue for how to create a new SFrame, or some other Python Data Structure. The best I have is :

for word in selected_words:
count[word]=products[word].sum()
print [word, count[word]]

Any Ideas?
Thanks.
 
Technology news on Phys.org
  • #2
You can use a dictionary to store the counts and then convert it into an SFrame. Here's an example:# Create empty dictionarycount = {}# Loop through selected_wordsfor word in selected_words: # Count the number of times the word appears in the data count[word] = products[word].sum()# Convert dictionary into an SFramesframe = gl.SFrame(count)# Print out resulting SFrameprint(sframe)
 

FAQ: Adding Matrix with Variables in Jupyter Notebook

1. How can I add two matrices with variables in Jupyter Notebook?

To add two matrices with variables in Jupyter Notebook, you can use the NumPy library. First, import the library by typing import numpy as np. Then, create two matrices and assign them to variables. Finally, use the addition operator (+) to add the matrices together and assign the result to a new variable.

2. Can I add matrices with different dimensions in Jupyter Notebook?

No, you cannot add matrices with different dimensions in Jupyter Notebook. Matrix addition requires both matrices to have the same number of rows and columns.

3. How do I add a constant to a matrix in Jupyter Notebook?

To add a constant to a matrix in Jupyter Notebook, you can use the NumPy library. First, import the library by typing import numpy as np. Then, create a matrix and assign it to a variable. Finally, use the addition operator (+) to add the constant to each element in the matrix.

4. Can I add more than two matrices in Jupyter Notebook?

Yes, you can add more than two matrices in Jupyter Notebook. Simply use the addition operator (+) to add each matrix together, ensuring that they all have the same dimensions.

5. Is there a limit to the number of variables I can use in a matrix addition in Jupyter Notebook?

No, there is no limit to the number of variables you can use in a matrix addition in Jupyter Notebook. However, it is important to ensure that all matrices being added have the same dimensions for the addition to be valid.

Similar threads

Replies
17
Views
2K
Replies
8
Views
2K
Replies
12
Views
7K
Replies
5
Views
4K
Replies
3
Views
663
Replies
7
Views
2K
Replies
10
Views
2K
Replies
1
Views
1K
Replies
5
Views
1K
Replies
25
Views
2K
Back
Top