Exemplo n.º 1
0
       return s.runner().fetch(output.op().name()).run().get(0).expect(Float.class);
     }
   }
 }
 private static float[] executeInceptionGraph(byte[] graphDef, Tensor<Float> image) {
   try (Graph g = new Graph()) {
     g.importGraphDef(graphDef);
     try (Session s = new Session(g);
         Tensor<Float> result =
             s.runner().feed("input", image).fetch("InceptionV4/Logits/Predictions").run().get(0).expect(Float.class)) {
       final long[] rshape = result.shape();
       if (result.numDimensions() != 2 || rshape[0] != 1) {
         throw new RuntimeException(
             String.format(
                 "Expected model to produce a [1 N] shaped tensor where N is the number of labels, instead it produced one with shape %s",
                 Arrays.toString(rshape)));
       }
       int nlabels = (int) rshape[1];
       return result.copyTo(new float[1][nlabels])[0];
     }
   }
 }
 private static int maxIndex(float[] probabilities) {
   int best = 0;
   for (int i = 1; i < probabilities.length; ++i) {
     if (probabilities[i] > probabilities[best]) {
       best = i;
     }
   }
   return best;
 }
package penjumlahanarray;
import java.util.Arrays;
public class PenjumlahanArray {
   public static void main(String[] args) {
       int[] a = {1, 2, 4, 8};
       int[] b = {16, 32, 64, 128};
       int totalA = 0;
       int totalB = 0;
       int total;
       
       for(int num : a){
           totalA = totalA+num;
       }
       for(int num : b){
           totalB = totalB+num;
       }
       total = totalA + totalB;
       
       System.out.println("Jumlah Nilai dari Kedua Array : "+total);
       
       int[] ab = new int[a.length+b.length];
       System.arraycopy(a, 0, ab, 0, b.length);
       System.arraycopy(b, 0, ab, a.length, b.length);
       
       System.out.print("Gabungan Data dari Kedua Array : ");
       System.out.println(Arrays.toString(ab));    
  }  
}
Exemplo n.º 3
0
import java.util.Arrays;
import java.util.Scanner;

public class ReversingAnArray{
	public static void main(String[] args) {
		int temp = 0;
		Scanner input=new Scanner(System.in);
		System.out.println("give size of the array: ");
		int arraySize = input.nextInt();
		int[] array = new int[arraySize];
		for (int i=0;i<arraySize; i++) {
			array[i]=input.nextInt();
		}
		System.out.println("The array is "+Arrays.toString(array));
		for(int i=0;i<(arraySize/2);i++){
			temp=array[arraySize-i-1];
			array[arraySize-1-i] = array[i];
			array[i]=temp;
		}
		System.out.println("The reversed array is "+Arrays.toString(array));
		
		// searching an element in unsorted array 'array'
		System.out.println("give the Number to be searched in array");
		int num=input.nextInt();
		for(int i=0;i<arraySize;i++){
			if(num==array[i]){
				System.out.println(num+" is in array at "+i+" index");
				break;
			}
		}
	}