ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 28 May 2018 18:42:16 +0200array numpy mixed division problemhttps://ask.sagemath.org/question/42456/array-numpy-mixed-division-problem/ Hi
why this line is ok:
DiceValueFrequencyT.append([nonZeroValueT[value],(valueT[nonZeroValueT[value]]*(1/int(len(DiceT[die]))))])
Except the fact that I do not understand why it is written 0.8333333 instead of 5/6 as usual
but this one is ko ?:
DiceValueFrequencyT.append([nonZeroValueT[value],(valueT[nonZeroValueT[value]] / int(len(DiceT[die])))])
in notebook Sagemath 8.2
forget()
import numpy as np
DiceT=[[3,3,3,3,3,6],[1,4,4,4,4,4] ,[2,2,2,5,5,5]]
DiceColorT=['Red','Green','White']
DiceValueFrequencyT=[]
#Rf=[[3,5/6],[6,1/6]];Gf=[[1,1/6],[4,5/6]];Wf=[[2,1/2],[5,1/2]];
for die in range(0,len(DiceT)) :
freqT = np.array(DiceT[die])
valueT = np.bincount(freqT)
nonZeroValueT=np.nonzero(valueT)[0]
show(valueT)
show(nonZeroValueT)
for value in range(0,len(nonZeroValueT)) :
print int(len(DiceT[die]))
# these Two lines are ok when uncommented
#DiceValueFrequencyT.append([nonZeroValueT[value],(valueT[nonZeroValueT[value]]*(1/6))])
DiceValueFrequencyT.append([nonZeroValueT[value],(valueT[nonZeroValueT[value]]*(1/int(len(DiceT[die]))))])
# but this one give false results when uncommented!
#DiceValueFrequencyT.append([nonZeroValueT[value],(valueT[nonZeroValueT[value]] / int(len(DiceT[die])))])
show (DiceValueFrequencyT)
ortolljMon, 28 May 2018 18:42:16 +0200https://ask.sagemath.org/question/42456/export data and labels in cvs filehttps://ask.sagemath.org/question/23407/export-data-and-labels-in-cvs-file/Hi experts!
I have the Numpy arrays `AAA=[a1,a2,...]` and `BBB=[b1,b2,...]`. I know that I can export these arrays doing:
np.savetxt('array AAA.csv', AAA, delimiter=',')
np.savetxt('array BBB.csv', BBB, delimiter=',')
I wanna export one csv file that include both arrays + labels, in this way:
AAA | BBB
----------
a1 | b1
a2 | b2
. | .
. | .
. | .
How can I do that?
Waiting for your answers.
Thanks a lot.
Best regardsmresimulatorMon, 14 Jul 2014 01:08:16 +0200https://ask.sagemath.org/question/23407/Add Numpy array into other Numpy arrayhttps://ask.sagemath.org/question/10391/add-numpy-array-into-other-numpy-array/Hi experts!!
My code starts with a empty array (POPOPO=np.array([])).
In the next lines, np.array are created (L1, L2, ...). How can it add this new-created-arrays into POPOPO in order to obtain the array POPOPO= [[L1],[L2],...]?
Its important to note that L1, L2,.... have different lenght.
Waiting for your answers.
Thanks in advance!mresimulatorSat, 27 Jul 2013 11:21:42 +0200https://ask.sagemath.org/question/10391/export data in MS Excel filehttps://ask.sagemath.org/question/10335/export-data-in-ms-excel-file/Hi experts!
Im running a code that generate three differents Numpy arrays (L1, L2 and L3) for every for-cycle (there is N cycles), so I get 3N arrays.
I wanna save these NP arrays in a MS excel file (.xls or other).
My questions are:
1) How can i generate this excel file?
2) How can I read the Excel file generated in a script?
Waiting for your answers.
Thanks a lot!
mresimulatorTue, 09 Jul 2013 12:20:37 +0200https://ask.sagemath.org/question/10335/Replace rows an columns by zeros in a numpy arrayhttps://ask.sagemath.org/question/10395/replace-rows-an-columns-by-zeros-in-a-numpy-array/Hi expers.
¿How can I replace rows an columns by zeros (or other values) in a numpy array?
Waiting for your answers.
Thanks a lot.mresimulatorMon, 29 Jul 2013 12:13:08 +0200https://ask.sagemath.org/question/10395/replace values in Numpy arrayhttps://ask.sagemath.org/question/10394/replace-values-in-numpy-array/Hi experts.
I'm trying to replace some values in a Numpy array. I wanna conserve the unchanged array too.
sage: import numpy as np
sage: N = np.array([[1,2,3],[4,5,6],[8,9,7]])
I call K the new array (with some values repaced):
sage: K = N
sage: K
array([[1, 2, 3],
[4, 5, 6],
[8, 9, 7]])
sage: K[1,2] = 9
sage: K
array([[1, 2, 3],
[4, 5, 9],
[8, 9, 7]])
But here is the problem: the original array is changed too!!
sage: N
array([[1, 2, 3],
[4, 5, 9],
[8, 9, 7]])
How can I change only the array K (and conserve without change the original array N)?
Waiting for your answers.
Thanks a lot!
mresimulatorSun, 28 Jul 2013 23:05:30 +0200https://ask.sagemath.org/question/10394/refresh numpy array in a for-cyclehttps://ask.sagemath.org/question/10291/refresh-numpy-array-in-a-for-cycle/Hi experts!
Im writing a code with a numpy array L, the numpy matrix M and the next script:
for x in L:
for l in srange(N):
z= l in L
if z is False and M[x,l] != 0:
L=np.append(L,l)
here, in the end of the cycle, new elements are incorporated to the array 'L'.
I want these new elements be considered as 'x' index in the cycle.
When I execute the script I see that only the 'originals' elements of L are considered as 'x'.
How can i fix it?
Waiting for your answers.
Thanks a lot!
mresimulatorWed, 26 Jun 2013 19:36:41 +0200https://ask.sagemath.org/question/10291/frequency (count) in Numpy Arrayhttps://ask.sagemath.org/question/10279/frequency-count-in-numpy-array/Hi experts!
For a list `L` the command `L.count(z)` shows the number of times that the element `z` is repeated in list `L`.
For example:
[I] L=[1,1,3,1,4,5,8]
[I] L.count(1)
[O] 3
How can i do that with a Numpy array?
Waiting for your answers.
Thanks a lot!
mresimulatorTue, 25 Jun 2013 18:28:27 +0200https://ask.sagemath.org/question/10279/