128 + 16 = 144 which isn't on the ASCII chart yet it equals H (decimal).
Can somebody help me with the conversion process because I'm quite new to binary so don't understand it that well but ASCII chart only goes up to 128 and H equals 72.
Summary: Why does 01001000 equal H in decimal.
Your binary to decimal conversion is incorrect:
01001000 = 1 * 2^6 + 1 * 2^3 = 72
Recall that the right-most binary digit corresponds to 2^0, not 2^1.
the value 01001000 is translated to decimal like this
0 1 0 0 1 0 0 0
128s 64s 32s 16s 8s 4s 2s 1s
0 64 0 0 8 0 0 0 = 72
Related
I need a Julia BitArray-like object that can encode more than 64 bits, say 128 bits. Does a simple replacement of UInt64 with UInt128 in bitarray.jl work?
Based on the information in your comment, the existing BitArray would itself serve your needs. Note that BitArray uses UInt64s internally, but that's not a limitation on the size of the array - it actually stores the bits as a Vector of UInt64s, so there's no special size limitation. You can create a 5x5x5 BitArray with no problem.
julia> b = BitArray(undef, 5, 5, 5);
julia> b .= 0;
julia> b[3, 5, 5] = 1
1
julia> b[3, :, :]
5×5 BitMatrix:
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 1
Maybe this part of the documentation threw you off:
BitArrays pack up to 64 values into every 8 bytes, resulting in an 8x space efficiency over Array{Bool, N} and allowing some
operations to work on 64 values at once.
but that's talking about internal implementation details. BitArrays are not limited to 8 bytes, so they're not limited to having just 64 values in them either.
Creating a new type of bit array using UInt128s would likely not be optimized, and is unnecessary anyway.
It is possible to take one column of numeric values like in dup$Number and subset columns in DG that match dup$number and return this as a new data frame?
dup
Number Letter
59 Q
91 Q
19 Q
17 Q
DG
chr pos id ref alt refc altc qual cov line_21 line_26 line_28 line_31 line_32 line_38 line_40 line_41 line_42 line_45 line_48 line_49 line_57 line_59 line_69 line_73 line_75 line_83
1 2R 7006506 2R_7006506_SNP C A 169 26 999 29 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 2 -
Try
indx <- grep('line', names(DG))
DG[indx[as.numeric(sub('.*_', '', names(DG)[indx])) %in% dup$Number]]
# line_59
#1 0
I have a data frame vec that I need to prepare for an image.plot() plot. The structure of vec is as follows:
> str(vec)
'data.frame': 31212 obs. of 5 variables:
$ x : int 8 24 40 56 72 88 104 120 136 152 ...
$ y : int 8 8 8 8 8 8 8 8 8 8 ...
$ dx: num 0 0 0 0 0 0 0 0 0 0 ...
$ dy: num 0 0 0 0 0 0 0 0 0 0 ...
$ d : num 0 0 0 0 0 0 0 0 0 0 ...
Note: the values in $dx, $dy and $d are not zero but only too small to be shown in this overview.
Background: the data is the output of a pixel tracking software. $x and $y are pixel coordinates while in $d are the displacement vector lengths (in pixels) of that pixel.
image.plot() expects as first and second argument the dimension of the matrix as ordered vectors, so I think sort(unique(vec$x)) and sort(unique(vec$y)) respectively should be good. So, I would like to end up with image.plot(sort(unique(vec$x)),sort(unique(vec$y)), data)
The third argument is the actual data. To build this I tried:
# spanning an empty matrix
data = matrix(NA,length(unique(vec$x)),length(unique(vec$y)))
# filling the matrix
data[match(vec$x, sort(unique(vec$x))), match(vec$y, sort(unique(vec$y)))] = vec$d
But, unfortunately, this isn't working. It reports no errors but data contains no values! This works:
for(i in c(1:length(vec$x))) data[match(vec$x[i], sort(unique(vec$x))), match(vec$y[i], sort(unique(vec$y)))] = vec$d[i]
But is very slow.
a) is there a better way to build data?
b) is there a better way to deal with my problem, anyways?
R allows indexing of a matrix by a two-column matrix, where the first column of the index is interpreted as the row index, and the second column as the column index. So create the indexes into data as a two-column matrix
idx = cbind(match(vec$x, sort(unique(vec$x))),
match(vec$y, sort(unique(vec$y))))
and use that
data[idx] = vec$d
I have a matrix which contains the genes and the mrna.
ID_REF GSM362168 GSM362169 GSM362170 GSM362171 GSM362172 GSM362173 GSM362174
244901_at 5.171072 5.207896 5.191145 5.067809 5.010239 5.556884 4.879528
244902_at 5.296012 5.460796 5.419633 5.440318 5.234789 7.567894 6.908795
I wanted to find the differentially expressed genes from the matrix using t test and i carried out the following.
stat=mt.teststat(control,classlabel,test="t",na=.mt.naNUM,nonpara="n")
and I get the following error
Error in is.factor(classlabel) : object 'classlabel' not found.
I am not sure how I have to assign the classlabels.Is it the right way to find the differentially expressed genes.
The classlabel should be a vector of integers corresponding to observation (column) class labels. I do not understand what that is.
If you open the documentation for mt.teststat:
?mt.teststat
and scroll down to the end, you'll see an example using the "Golub data":
data(golub)
teststat <- mt.teststat(golub, golub.cl)
If you look at golub.cl,it will become clear what the classlabel vector should look like:
golub.cl
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1
In this case, 0 or 1 are labels for two classes of sample. There should be as many values in the vector as you have samples, in the same order that the samples appear in the data matrix. You can also look at:
?golub
golub.cl: numeric vector indicating the tumor class, 27 acute
lymphoblastic leukemia (ALL) cases (code 0) and 11 acute
myeloid leukemia (AML) cases (code 1).
So you need to create a similar vector, with labels (0, 1, ...) for however many classes you have for your own data.
I have a box defined by 8 points. From those points, I calculate axes and create rotation matrix as follows:
axis[0], axis[1], axis[2]
mat =
{
axis[0].x axis[1].x axis[2].x 0
axis[0].y axis[1].y axis[2].y 0
axis[0].z axis[1].z axis[2].z 0
0 0 0 1
}
I have particular rotation matrix:
{
-1 0 0 0
0 0 1 0
0 -1 0 0
0 0 0 1
}
As best of my knowledge, this is a valid rotation matrix. Its inversion is equal to its transposition.
Now I would like to store this matrix as a quaternion. But later, I need rotation matrix to be recreated from this quaternion. I believe that convertsion from matrix to quaternion and back to matrix should be an identity transform and I should get the same matrix that I had in the beginning (maybe with very small numerical errors).
But this seems not to be the case. Both SlimDX (C#) and my propertiary math library (C++) return invalid matrix.
First, quaternion that I receive:
C#: 0, 0, 0.70710676908493, 0
C++: 0, -0.707107, 0, 0
And matrix created from this quaternion:
C#:
0 0 0 0
0 0 0 0
0 0 1 0
0 0 0 1
C++:
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Why is this wrong?
I've also tried this: http://cache-www.intel.com/cd/00/00/29/37/293748_293748.pdf but it gave me bad results as well.
The matrix you gave isn't a rotation matrix, it's a reflection matrix because its determinant is -1. See the definition on Wikipedia. You can tell something isn't right because you should get a unit quaternion, and yet the one you're getting back only has length 1/sqrt(2).
Try using a 4x4 matrix. I'm not matrix math expert, but I've never used 3x3 matrices when dealing with 3D graphics. I believe the extra dimension is for normalization, or something like that.