Skip to content

Instantly share code, notes, and snippets.

@sploving
Created July 25, 2011 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sploving/1103717 to your computer and use it in GitHub Desktop.
Save sploving/1103717 to your computer and use it in GitHub Desktop.
Python:
from shogun.Features import RealFeatures
from numpy import array, float64, all
# create dense matrices A,B,C
matrix=array([[1,2,3],[4,0,0],[0,0,0],[0,5,0],[0,0,6],[9,9,9]], dtype=float64)
parameter_list = [[matrix]]
# ... of type LongInt
def features_simple_real_modular(A=matrix):
# ... of type Real, LongInt and Byte
a=RealFeatures(A)
# print some statistics about a
#print a.get_num_vectors()
#print a.get_num_features()
# get first feature vector and set it
#print a.get_feature_vector(0)
a.set_feature_vector(array([1,4,0,0,0,9], dtype=float64), 0)
# get matrix
a_out = a.get_feature_matrix()
print a_out
assert(all(a_out==A))
return a_out
if __name__=='__main__':
print 'simple_real'
features_simple_real_modular(*parameter_list[0])
result:
[[ 1. 2. 3.]
[ 4. 0. 0.]
[ 0. 0. 0.]
[ 0. 5. 0.]
[ 0. 0. 6.]
[ 9. 9. 9.]]
lua:
require 'shogun'
matrix = {{1,2,3},{4,0,0},{0,0,0},{0,5,0},{0,0,6},{9,9,9}}
parameter_list = {{matrix}}
function features_simple_real_modular(A)
a=RealFeatures(A)
a:set_feature_vector({1,4,0,0,0,9}, 0)
a_out = a:get_feature_matrix()
for _,row in ipairs(a_out) do for _,cell in ipairs(row) do io.write(cell..' ') end io.write('\n') end
return a_out
end
if debug.getinfo(3) == nill then
print 'simple_real'
features_simple_real_modular(unpack(parameter_list[1]))
end
1 4 0
0 0 9
0 0 0
0 5 0
0 0 6
9 9 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment