How to scale a raphaeljs paper - raphael

I am using .svg files for thumbnails. The original .svg's came from CorelDraw, and they are about 400x400 each. But I wish to use them inside 75x75 thumbnail divs.
I have tried:
one_thumb__paper.setViewBox( 0 , 0 , 75 , 75 , true ) ;
one_thumb__set.transform( "s.5" )
also, the ScaleRaphaël class

I was doing two things wrong:
1 -
// the wrong way:
var my_set = my_paper.importSVG( my_svg_string); 5
// the correct way:
var my_set = my_paper.set();
my_paper.importSVG( my_svg_string , my_set );
2 -
// the wrong way:
my_set.transform( "s.5" )
// the correct way:
my_set.transform( "s.5,.5,0,0" )
see working fiddle
see raphaeljs svg importer

Related

out put a model.wv with an if condition in a list

import gensim
from gensim.models import word2vec
mainmodel = gensim.models.Word2Vec.load('C:/Users/user/2330.model')
data = open('C:/Users/user/vec_2330_segement.txt','r',encoding = 'utf-8')
data=data.read()
Above is loading work2vec model and list of data
Data is a huge of chinese vocabulary list ( have been cut in jieba , about 100 MegaByte ) but have two comma ',' between each whole document(news) , like :
["我" "是" "個" "帥" "哥" ,, "你" "也" "是" ,, "..."]
Have total 40,000 documents.
so , I hope what I see in result "doc_all".
FOR example(each vector in documents are 20 Dimensions)
0.12345 , 1.23456 , -2.34567 , ... , -3.45678
...
...
0.12345 , -1.23456 , 2.34567 , ... , 3.45678
(for 40000 rows)
data=data.read()
doc_all = []
doc_sent = []
for index in data:
doc_sent.append(mainmodel.wv[index]),
try:
(doc_all if data[index] == ',').append(np.sum(doc_sent,axis=0)),
except KeyError:
continue
len(doc_all)
which I can't believe is :
Why there comes an error from syntax ,
I have search lot of relate documents in flow but have no same situation ,
instead my code grammar is same ,
have anything that I suppose to notice but I didn't ?
======Edit======
here is the tracebook (sorry for late)
I guess it's need an else to break
or... not ?
File "<ipython-input-3-c55175ca5d96>", line 9
(doc_all if data[index] == ',').append(np.sum(doc_sent,axis=0)),
^
SyntaxError: invalid syntax

Split Pandas Column by values that are in a list

I have three lists that look like this:
age = ['51+', '21-30', '41-50', '31-40', '<21']
cluster = ['notarget', 'cluster3', 'allclusters', 'cluster1', 'cluster2']
device = ['htc_one_2gb','iphone_6/6+_at&t','iphone_6/6+_vzn','iphone_6/6+_all_other_devices','htc_one_2gb_limited_time_offer','nokia_lumia_v3','iphone5s','htc_one_1gb','nokia_lumia_v3_more_everything']
I also have column in a df that looks like this:
campaign_name
0 notarget_<21_nokia_lumia_v3
1 htc_one_1gb_21-30_notarget
2 41-50_htc_one_2gb_cluster3
3 <21_htc_one_2gb_limited_time_offer_notarget
4 51+_cluster3_iphone_6/6+_all_other_devices
I want to split the column into three separate columns based on the values in the above lists. Like so:
age cluster device
0 <21 notarget nokia_lumia_v3
1 21-30 notarget htc_one_1gb
2 41-50 cluster3 htc_one_2gb
3 <21 notarget htc_one_2gb_limited_time_offer
4 51+ cluster3 iphone_6/6+_all_other_devices
First thought was to do a simple test like this:
ages_list = []
for i in ages:
if i in df['campaign_name'][0]:
ages_list.append(i)
print ages_list
>>> ['<21']
I was then going to convert ages_list to a series and combine it with the remaining two to get the end result above but i assume there is a more pythonic way of doing it?
the idea behind this is that you'll create a regular expression based on the values you already have , for example if you want to build a regular expressions that capture any value from your age list you may do something like this '|'.join(age) and so on for all the values you already have cluster & device.
a special case for device list becuase it contains + sign that will conflict with the regex ( because + means one or more when it comes to regex ) so we can fix this issue by replacing any value of + with \+ , so this mean I want to capture literally +
df = pd.DataFrame({'campaign_name' : ['notarget_<21_nokia_lumia_v3' , 'htc_one_1gb_21-30_notarget' , '41-50_htc_one_2gb_cluster3' , '<21_htc_one_2gb_limited_time_offer_notarget' , '51+_cluster3_iphone_6/6+_all_other_devices'] })
def split_df(df):
campaign_name = df['campaign_name']
df['age'] = re.findall('|'.join(age) , campaign_name)[0]
df['cluster'] = re.findall('|'.join(cluster) , campaign_name)[0]
df['device'] = re.findall('|'.join([x.replace('+' , '\+') for x in device ]) , campaign_name)[0]
return df
df.apply(split_df, axis = 1 )
if you want to drop the original column you can do this
df.apply(split_df, axis = 1 ).drop( 'campaign_name', axis = 1)
Here I'm assuming that a value must be matched by regex but if this is not the case you can do your checks , you got the idea

Multiplication of NDArray in oct file

I am trying to convert an .m file to an .oct file in Octave and part of the .m file code is:-
for hh = 1 : nt
bi_star = bi_star + A( : , : , hh ) * data( : , : , hh + 1 )' ;
end
where both "A" and "data" are of NDArray type. I have tried to extract the values from the NDArrays by using something like
A.extract( 0 , 0 , num_dims-1 , num_dims-1 , hh ) ;
but get the error message
error: ‘class NDArray’ has no member named ‘extract’
when compiling. The only other way I can think of doing this at the moment is to put nested loops within the hh loop to loop over both "A" and "data" to fill in intermediate calculation matrices and do the matrix multiplications and additions using these intermediate matrices. However, this seems to be a very long winded way of doing things. Is there a more efficient way of accomplishing this?
Thanks to Andy's answer here and its included link to the Octave sources page, I have been able to figure out that I simply need to use:
A.page ( hh )
to accomplish what I what.
Thanks Andy!

filter dplyr's tbl_df using variable names

I am having trouble using dplyr's tbl_df, respectively the regular data.frame. I got a big tbl_df (500x30K) and need to filter it.
So what I would like to do is:
filter(my.tbl_df, row1>0, row10<0)
which would be similar to
df[df$row1>0 & df$row10<0,]
Works great. But I need to build the filter functions dynamically while running, so I need to access the DF/tbl_df columns by one or multiple variables.
I tried something like:
var=c("row1","row10")
op=c(">","<")
val=c(0,0)
filter(my.tbl_df, eval(parse(text=paste(var,op,val,sep="")))
Which gives me an error: not compatible with LGLSXP
This seems to be deeply rooted in the Cpp code.
I would be thankful for any hint. Also pointing out the "string to environment variable" conversion would be helpful, since I am pretty that I am doing it wrong.
With best,
Mario
This is related to this issue. In the meantime, one way could be to construct the whole expression, i.e.:
> my.tbl_df <- data.frame( row1 = -5:5, row10 = 5:-5)
> call <- parse( text = sprintf( "filter(my.tbl_df, %s)", paste(var,op,val, collapse="&") ) )
> call
expression(filter(my.tbl_df, row1 > 0&row10 < 0))
> eval( call )
row1 row10
1 1 -1
2 2 -2
3 3 -3
4 4 -4
5 5 -5

OnRowRender Corona SDK 1076 not show data

Good afternoon,
I have a problem when displaying the contents of my table in a list. The action does not make the impression of the data in each row and do not understand why.
I have the 1076 version of Corona SDK and does not work, but with the previous IF it worked.
I hope your help.
local function onRowRender( event )
print("oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo")
local phase = event.phase
local row = event.row
local rowGroup = event.view
local label = aux.corrigeEspeciales (rowTitles[ row.index ])
local color = 20
print ("label" .. label)
row.itemName = label
row.textObj = display.newRetinaText(rowGroup,label, 0, 0, "Verdana", 12 )
row.textObj:setTextColor( color )
row.textObj:setReferencePoint( display.CenterLeftReferencePoint )
row.textObj.x, row.textObj.y = 20, rowGroup.contentHeight * 0.5
rowGroup:insert( row.textObj )
row.arrow = display.newImage( "images/tiendarowArrow.png", false )
row.arrow.x = rowGroup.contentWidth - row.arrow.contentWidth * 2
row.arrow.y = rowGroup.contentHeight * 0.5
rowGroup:insert( row.arrow )
end
You can show text info in 2013.1076 Corona SDK version using:
local phase = event.phase
local row = event.row
local rowGroup = event.view
local label = aux.corrigeEspeciales (rowTitles[ row.index ])
local color = 20
row.itemName = label
local rowTitle = display.newText(row,label, 0, 0, "Verdana", 12 )
rowTitle.x = row.x - ( row.contentWidth * 0.5 ) + ( rowTitle.contentWidth * 0.5 )
rowTitle.y = row.contentHeight * 0.5
rowTitle:setTextColor( 0, 0, 0 )
Corona 1076 I think uses Widget 2.0 widgets. They require a different syntax for determining the row group. See this article on updating your widgets to the new syntax.
http://docs.coronalabs.com/api/library/widget/migration.html
Also there is a new public build, 1135 that contains considerable bug fixes to the widget library. I would suggest upgrading so that you have these fixes.