This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def nonzero(self): | |
| """nonzero indices | |
| Returns a tuple of arrays (row,col) containing the indices | |
| of the non-zero elements of the matrix. | |
| Examples | |
| -------- | |
| >>> from scipy.sparse import csr_matrix | |
| >>> A = csr_matrix([[1,2,0],[0,0,3],[4,0,5]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class coo_1d(_data_matrix, ...): | |
| ... | |
| def row(self): | |
| return np.zeros(self.col.shape[0]) | |
| def nonzero(self): | |
| ... | |
| nz_mask = A.data != 0 | |
| return (None, A.col[nz_mask]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class coo_matrix(_data_matrix, _minmax_mixin): | |
| ... | |
| format = 'coo' | |
| def __init__(self, arg1, shape=None, dtype=None, copy=False): | |
| ... | |
| else: | |
| #dense argument | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| import itertool | |
| from nltk import word_tokenize | |
| from sklearn.feature_extraction.text import TfidfVectorizer | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.naive_bayes import MultinomialNB | |
| df = pd.read_csv('my_data_with_text.csv') | |
| df.columns #id, text, category |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Bird(models.Model): | |
| species_choices = [ | |
| ("Spix's Macaw", "Spix's Macaw"), | |
| ("Cockatiel", "Cockatiel"), | |
| ... | |
| ("Caique", "Caique"), | |
| ("Guam Kingfisher", "Guam Kingfisher") | |
| ] | |
| species = models.CharField(max_length=50, choices=species_choices) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| id | species | image | |
|---|---|---|---|
| 1 | Cockatiel | images/cockatiel-1.jpg | |
| 2 | Spix's Macaw | images/spixmacaw-1.jpg | |
| 3 | Cockatiel | images/cockatiel-2.jpg | |
| 4 | Caique | images/caique-1.jpg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /**begin repeat | |
| * | |
| * #name = BYTE, UBYTE, SHORT, USHORT, INT, UINT, | |
| * LONG, ULONG, LONGLONG, ULONGLONG, | |
| * FLOAT, DOUBLE, LONGDOUBLE, | |
| * DATETIME, TIMEDELTA# | |
| * #type = npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, npy_uint, | |
| * npy_long, npy_ulong, npy_longlong, npy_ulonglong, | |
| * npy_float, npy_double, npy_longdouble, | |
| * npy_datetime, npy_timedelta# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def cython_multiplication(a,b): | |
| product = np.ones(a.shape) | |
| for row_index in np.arange(a.shape[0]): | |
| for col_index in np.arange(a.shape[1]): | |
| product[row_index][col_index] = a[row_index][col_index] * b[row_index][col_index] | |
| return product |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ctypes | |
| import time | |
| from _ctypes import Structure, POINTER, byref | |
| from ctypes import c_int, c_float | |
| import pyximport; pyximport.install() | |
| import multiplication | |
| import numpy as np | |
| a = np.random.rand(2000,2000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def cython_multiplication(double[:,:] a, double[:,:] b, double[:,:] out, int x_dims, int y_dims): | |
| cdef int i, j | |
| for i in range(x_dims): | |
| for j in range(y_dims): | |
| out[i, j] = a[i,j] * b[i,j] | |
| return np.asarray(out) |