Skip to content

Instantly share code, notes, and snippets.

View photizzo's full-sized avatar

Ememobong Akpanekpo photizzo

View GitHub Profile
import numpy as np
a = (np.random.rand(1,10)) #create a random (1,10) array
result = np.zeros(10) #create an array of zeros to hold the result
result = (b.reshape(1,10))# reshape b to make sure its a (1,10) array and not (10,)
print ("a: \n" + str(a))
for i in range(10):
if a[0,i]>0.5:
result[0,i] = 1
else:
result[0,i] = 0
import numpy as np
a = (np.random.rand(1,10)) #create a random (1,10) array
print ("a: \n" + str(a))
result = (np.where(a>0.5,1,0))
print ("result: \n" +str(result))
a:
[[ 0.76456104 0.75182292 0.11825977 0.97635566 0.3220488 0.44064402
0.08142387 0.65055208 0.88407891 0.40323535]]
result:
[[1 1 0 1 0 0 0 1 1 0]]
import numpy as np
array = [[True, False], [True, True]] # (2,2) array of boolean values
array_cond_true = [[1, 2], [3, 4]] # (2,2) array of where to pick values if array at position is true
array_cond_false = [[9, 8], [7, 6]] # (2,2) array of where to pick values if array at position is false
print ("result: \n" + str(np.where(array,
array_cond_true,
array_cond_false)))
result:
[[1 8]
[3 4]]
import numpy as np
import time
a = (np.random.rand(1,1000000)) #create a random (1,10) array
result1 = np.zeros((1,1000000),dtype=np.int) #create an array of zeros to hold the result
#print ("a: \n" + str(a))
tic = time.time()
for i in range(1000000):
if a[0,i]>0.5:
result1[0,i] = 1
else:
time passed for result1: 1.2310867309570312ms
time passed for result2: 0.014905214309692383ms
package com.rideon.user.activities;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
abstract class CompletableUseCase<in Params> constructor(
private val postExecutionThread: PostExecutionThread) {
private val disposables = CompositeDisposable()
protected abstract fun buildUseCaseCompletable(params: Params? = null): Completable
open fun execute(observer: DisposableCompletableObserver, params: Params? = null) {
val completable = this.buildUseCaseCompletable(params)
.subscribeOn(Schedulers.io())